Bug 1451826 - Part 3: No longer call TokenStream::computeErrorMetadata from BCE. (r=Waldo)
authorEric Faust <efaustbmo@gmail.com>
Fri, 27 Apr 2018 15:02:31 -0700
changeset 472242 1afcb999264298659ff610d3409f067565e7c031
parent 472241 b945db303abc6ae585aaf8d518af225225aba2ba
child 472243 6d712c91d06dfb9b968404fcd217dc43670ad2e3
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs1451826
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1451826 - Part 3: No longer call TokenStream::computeErrorMetadata from BCE. (r=Waldo)
js/src/frontend/BytecodeEmitter.cpp
js/src/frontend/EitherParser.h
js/src/frontend/TokenStream.cpp
js/src/frontend/TokenStream.h
--- a/js/src/frontend/BytecodeEmitter.cpp
+++ b/js/src/frontend/BytecodeEmitter.cpp
@@ -3590,19 +3590,17 @@ void
 BytecodeEmitter::reportError(ParseNode* pn, unsigned errorNumber, ...)
 {
     MOZ_ASSERT_IF(!pn, this->scriptStartOffsetSet);
     uint32_t offset = pn ? pn->pn_pos.begin : this->scriptStartOffset;
 
     va_list args;
     va_start(args, errorNumber);
 
-    ErrorMetadata metadata;
-    if (parser.computeErrorMetadata(&metadata, offset))
-        ReportCompileError(cx, Move(metadata), nullptr, JSREPORT_ERROR, errorNumber, args);
+    parser.errorAtVA(offset, errorNumber, &args);
 
     va_end(args);
 }
 
 bool
 BytecodeEmitter::reportExtraWarning(ParseNode* pn, unsigned errorNumber, ...)
 {
     MOZ_ASSERT_IF(!pn, this->scriptStartOffsetSet);
--- a/js/src/frontend/EitherParser.h
+++ b/js/src/frontend/EitherParser.h
@@ -88,24 +88,16 @@ struct GetTokenStream
 template<class Parser>
 struct ParserOptions
 {
     static constexpr auto get() -> decltype(&Parser::options) {
         return &Parser::options;
     }
 };
 
-template<class TokenStream>
-struct TokenStreamComputeErrorMetadata
-{
-    static constexpr auto get() -> decltype(&TokenStream::computeErrorMetadata) {
-        return &TokenStream::computeErrorMetadata;
-    }
-};
-
 template<class Parser>
 struct ParserNewObjectBox
 {
     static constexpr auto get() -> decltype(&Parser::newObjectBox) {
         return &Parser::newObjectBox;
     }
 };
 
@@ -129,16 +121,24 @@ template<class Handler>
 struct HandlerIsSuperBase
 {
     static constexpr auto get() -> decltype(&Handler::isSuperBase) {
         return &Handler::isSuperBase;
     }
 };
 
 template<class TokenStream>
+struct TokenStreamErrorAtVA
+{
+    static constexpr auto get() -> decltype(&TokenStream::errorAtVA) {
+        return &TokenStream::errorAtVA;
+    }
+};
+
+template<class TokenStream>
 struct TokenStreamReportExtraWarning
 {
     static constexpr auto get() -> decltype(&TokenStream::reportExtraWarningErrorNumberVA) {
         return &TokenStream::reportExtraWarningErrorNumberVA;
     }
 };
 
 // Generic matchers.
@@ -200,23 +200,16 @@ class EitherParser
         return parser.match(detail::ScriptSourceMatcher());
     }
 
     const JS::ReadOnlyCompileOptions& options() {
         InvokeMemberFunction<detail::GetParser, detail::ParserOptions> optionsMatcher;
         return parser.match(mozilla::Move(optionsMatcher));
     }
 
-    MOZ_MUST_USE bool computeErrorMetadata(ErrorMetadata* metadata, uint32_t offset) {
-        InvokeMemberFunction<detail::GetTokenStream, detail::TokenStreamComputeErrorMetadata,
-                             ErrorMetadata*, uint32_t>
-            matcher { metadata, offset };
-        return parser.match(mozilla::Move(matcher));
-    }
-
     ObjectBox* newObjectBox(JSObject* obj) {
         InvokeMemberFunction<detail::GetParser, detail::ParserNewObjectBox,
                              JSObject*>
             matcher { obj };
         return parser.match(mozilla::Move(matcher));
     }
 
     Node singleBindingFromDeclaration(Node decl) {
@@ -241,19 +234,27 @@ class EitherParser
     }
 
     template<typename... Args>
     MOZ_MUST_USE bool warningNoOffset(Args&&... args) {
         return parser.match(detail::ParserBaseMatcher()).warningNoOffset(mozilla::Forward<Args>(args)...);
     }
 
     template<typename... Args>
+    void errorAtVA(Args&&... args) {
+        InvokeMemberFunction<detail::GetTokenStream, detail::TokenStreamErrorAtVA, Args...>
+            matcher { mozilla::Forward<Args>(args)... };
+        return parser.match(mozilla::Move(matcher));
+    }
+
+    template<typename... Args>
     MOZ_MUST_USE bool reportExtraWarningErrorNumberVA(Args&&... args) {
         InvokeMemberFunction<detail::GetTokenStream, detail::TokenStreamReportExtraWarning, Args...>
             matcher { mozilla::Forward<Args>(args)... };
         return parser.match(mozilla::Move(matcher));
     }
+
 };
 
 } /* namespace frontend */
 } /* namespace js */
 
 #endif /* frontend_EitherParser_h */
--- a/js/src/frontend/TokenStream.cpp
+++ b/js/src/frontend/TokenStream.cpp
@@ -961,27 +961,35 @@ TokenStreamSpecific<CharT, AnyCharsAcces
                            args);
     }
 
     va_end(args);
 }
 
 template<typename CharT, class AnyCharsAccess>
 void
+TokenStreamSpecific<CharT, AnyCharsAccess>::errorAtVA(uint32_t offset, unsigned errorNumber, va_list *args)
+{
+    ErrorMetadata metadata;
+    if (computeErrorMetadata(&metadata, offset)) {
+        TokenStreamAnyChars& anyChars = anyCharsAccess();
+        ReportCompileError(anyChars.cx, Move(metadata), nullptr, JSREPORT_ERROR, errorNumber,
+                           *args);
+    }
+}
+
+
+template<typename CharT, class AnyCharsAccess>
+void
 TokenStreamSpecific<CharT, AnyCharsAccess>::errorAt(uint32_t offset, unsigned errorNumber, ...)
 {
     va_list args;
     va_start(args, errorNumber);
 
-    ErrorMetadata metadata;
-    if (computeErrorMetadata(&metadata, offset)) {
-        TokenStreamAnyChars& anyChars = anyCharsAccess();
-        ReportCompileError(anyChars.cx, Move(metadata), nullptr, JSREPORT_ERROR, errorNumber,
-                           args);
-    }
+    errorAtVA(offset, errorNumber, &args);
 
     va_end(args);
 }
 
 // We have encountered a '\': check for a Unicode escape sequence after it.
 // Return the length of the escape sequence and the character code point (by
 // value) if we found a Unicode escape sequence.  Otherwise, return 0.  In both
 // cases, do not advance along the buffer.
--- a/js/src/frontend/TokenStream.h
+++ b/js/src/frontend/TokenStream.h
@@ -1201,16 +1201,17 @@ class MOZ_STACK_CLASS TokenStreamSpecifi
     // TokenStream-specific error reporters.
     void reportError(unsigned errorNumber, ...);
 
     // Report the given error at the current offset.
     void error(unsigned errorNumber, ...);
 
     // Report the given error at the given offset.
     void errorAt(uint32_t offset, unsigned errorNumber, ...);
+    void errorAtVA(uint32_t offset, unsigned errorNumber, va_list* args);
 
     // Warn at the current offset.
     MOZ_MUST_USE bool warning(unsigned errorNumber, ...);
 
   private:
     // Compute a line of context for an otherwise-filled-in |err| at the given
     // offset in this token stream.  (This function basically exists to make
     // |computeErrorMetadata| more readable and shouldn't be called elsewhere.)