Bug 1424394 - Split Parser::reportNoOffset into Parser::{error,warning}NoOffset. r=arai
authorJeff Walden <jwalden@mit.edu>
Mon, 17 Apr 2017 15:05:39 -0700
changeset 396259 5d3190b2b1bd77bdf476fa9c075be1829d8447d9
parent 396258 7496d9ff6fa0ae03545ce206caba5490a26c9226
child 396260 0559a4899c440b7c9a6666715cd3a1836fc4128f
push id33087
push userdluca@mozilla.com
push dateThu, 14 Dec 2017 09:54:55 +0000
treeherdermozilla-central@8062887ff0d9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersarai
bugs1424394
milestone59.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 1424394 - Split Parser::reportNoOffset into Parser::{error,warning}NoOffset. r=arai
js/src/frontend/BytecodeEmitter.cpp
js/src/frontend/EitherParser.h
js/src/frontend/Parser.cpp
js/src/frontend/Parser.h
js/src/wasm/AsmJS.cpp
--- a/js/src/frontend/BytecodeEmitter.cpp
+++ b/js/src/frontend/BytecodeEmitter.cpp
@@ -3519,18 +3519,18 @@ BytecodeEmitter::maybeSetSourceMap()
 
     /*
      * Source map URLs passed as a compile option (usually via a HTTP source map
      * header) override any source map urls passed as comment pragmas.
      */
     if (parser.options().sourceMapURL()) {
         // Warn about the replacement, but use the new one.
         if (parser.ss()->hasSourceMapURL()) {
-            if (!parser.reportNoOffset(ParseWarning, false, JSMSG_ALREADY_HAS_PRAGMA,
-                                       parser.ss()->filename(), "//# sourceMappingURL"))
+            if (!parser.warningNoOffset(JSMSG_ALREADY_HAS_PRAGMA,
+                                        parser.ss()->filename(), "//# sourceMappingURL"))
             {
                 return false;
             }
         }
 
         if (!parser.ss()->setSourceMapURL(cx, parser.options().sourceMapURL()))
             return false;
     }
--- a/js/src/frontend/EitherParser.h
+++ b/js/src/frontend/EitherParser.h
@@ -250,18 +250,18 @@ class EitherParser
     template<typename... Args>
     void reportError(Args&&... args) {
         InvokeMemberFunction<detail::GetTokenStream, detail::TokenStreamReportError, Args...>
             matcher { mozilla::Forward<Args>(args)... };
         return parser.match(mozilla::Move(matcher));
     }
 
     template<typename... Args>
-    MOZ_MUST_USE bool reportNoOffset(Args&&... args) {
-        return parser.match(detail::ParserBaseMatcher()).reportNoOffset(mozilla::Forward<Args>(args)...);
+    MOZ_MUST_USE bool warningNoOffset(Args&&... args) {
+        return parser.match(detail::ParserBaseMatcher()).warningNoOffset(mozilla::Forward<Args>(args)...);
     }
 
     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));
     }
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -739,54 +739,46 @@ Parser<ParseHandler, CharT>::strictModeE
         tokenStream.reportStrictModeErrorNumberVA(nullptr, offset, pc->sc()->strict(),
                                                   errorNumber, &args);
 
     va_end(args);
     return res;
 }
 
 bool
-ParserBase::reportNoOffset(ParseReportKind kind, bool strict, unsigned errorNumber, ...)
+ParserBase::warningNoOffset(unsigned errorNumber, ...)
 {
     va_list args;
     va_start(args, errorNumber);
 
-    bool result = false;
-    switch (kind) {
-      case ParseError:
-      case ParseWarning: {
-        ErrorMetadata metadata;
-        tokenStream.computeErrorMetadataNoOffset(&metadata);
-
-        if (kind == ParseError) {
-            ReportCompileError(context, Move(metadata), nullptr, JSREPORT_ERROR, errorNumber,
-                               args);
-            MOZ_ASSERT(!result);
-        } else {
-            result =
-                tokenStream.compileWarning(Move(metadata), nullptr, JSREPORT_WARNING, errorNumber,
-                                           args);
-        }
-
-        break;
-      }
-      case ParseExtraWarning:
-        result = tokenStream.reportExtraWarningErrorNumberVA(nullptr, TokenStream::NoOffset,
-                                                             errorNumber, &args);
-        break;
-      case ParseStrictError:
-        result = tokenStream.reportStrictModeErrorNumberVA(nullptr, TokenStream::NoOffset, strict,
-                                                           errorNumber, &args);
-        break;
-    }
+    ErrorMetadata metadata;
+    tokenStream.computeErrorMetadataNoOffset(&metadata);
+
+    bool result =
+        tokenStream.compileWarning(Move(metadata), nullptr, JSREPORT_WARNING, errorNumber,
+                                   args);
 
     va_end(args);
     return result;
 }
 
+void
+ParserBase::errorNoOffset(unsigned errorNumber, ...)
+{
+    va_list args;
+    va_start(args, errorNumber);
+
+    ErrorMetadata metadata;
+    tokenStream.computeErrorMetadataNoOffset(&metadata);
+
+    ReportCompileError(context, Move(metadata), nullptr, JSREPORT_ERROR, errorNumber, args);
+
+    va_end(args);
+}
+
 #define ABORTED_SYNTAX_PARSE_SENTINEL (SyntaxParser*)(0x1)
 
 template <>
 bool
 Parser<FullParseHandler, char16_t>::hadAbortedSyntaxParse()
 {
     return false;
 }
--- a/js/src/frontend/Parser.h
+++ b/js/src/frontend/Parser.h
@@ -182,17 +182,18 @@ class ParserBase : public StrictModeGett
     }
 
     const ReadOnlyCompileOptions& options() const {
         return tokenStream.options();
     }
 
     bool isUnexpectedEOF() const { return isUnexpectedEOF_; }
 
-    bool reportNoOffset(ParseReportKind kind, bool strict, unsigned errorNumber, ...);
+    MOZ_MUST_USE bool warningNoOffset(unsigned errorNumber, ...);
+    void errorNoOffset(unsigned errorNumber, ...);
 
     bool isValidStrictBinding(PropertyName* name);
 
     void addTelemetry(DeprecatedLanguageExtension e);
 
     bool hasValidSimpleStrictParameterNames();
 
 
--- a/js/src/wasm/AsmJS.cpp
+++ b/js/src/wasm/AsmJS.cpp
@@ -8662,53 +8662,63 @@ LookupAsmJSModuleInCache(JSContext* cx, 
 
 static bool
 NoExceptionPending(JSContext* cx)
 {
     return cx->helperThread() || !cx->isExceptionPending();
 }
 
 static bool
-Warn(AsmJSParser& parser, int errorNumber, const char* str)
-{
-    ParseReportKind reportKind = parser.options().throwOnAsmJSValidationFailureOption &&
-                                 errorNumber == JSMSG_USE_ASM_TYPE_FAIL
-                                 ? ParseError
-                                 : ParseWarning;
-    parser.reportNoOffset(reportKind, /* strict = */ false, errorNumber, str ? str : "");
+SuccessfulValidation(AsmJSParser& parser, UniqueChars str)
+{
+    return parser.warningNoOffset(JSMSG_USE_ASM_TYPE_OK, str.get());
+}
+
+static bool
+TypeFailureWarning(AsmJSParser& parser, const char* str)
+{
+    if (parser.options().throwOnAsmJSValidationFailureOption) {
+        parser.errorNoOffset(JSMSG_USE_ASM_TYPE_FAIL, str ? str : "");
+        return false;
+    }
+
+    // Per the asm.js standard convention, whether failure sets a pending
+    // exception determines whether to attempt non-asm.js reparsing, so ignore
+    // the return value below.
+    Unused << parser.warningNoOffset(JSMSG_USE_ASM_TYPE_FAIL, str ? str : "");
     return false;
 }
 
 static bool
 EstablishPreconditions(JSContext* cx, AsmJSParser& parser)
 {
     if (!HasCompilerSupport(cx))
-        return Warn(parser, JSMSG_USE_ASM_TYPE_FAIL, "Disabled by lack of compiler support");
+        return TypeFailureWarning(parser, "Disabled by lack of compiler support");
 
     switch (parser.options().asmJSOption) {
       case AsmJSOption::Disabled:
-        return Warn(parser, JSMSG_USE_ASM_TYPE_FAIL, "Disabled by 'asmjs' runtime option");
+        return TypeFailureWarning(parser, "Disabled by 'asmjs' runtime option");
       case AsmJSOption::DisabledByDebugger:
-        return Warn(parser, JSMSG_USE_ASM_TYPE_FAIL, "Disabled by debugger");
+        return TypeFailureWarning(parser, "Disabled by debugger");
       case AsmJSOption::Enabled:
         break;
     }
 
     if (parser.pc->isGenerator())
-        return Warn(parser, JSMSG_USE_ASM_TYPE_FAIL, "Disabled by generator context");
+        return TypeFailureWarning(parser, "Disabled by generator context");
 
     if (parser.pc->isAsync())
-        return Warn(parser, JSMSG_USE_ASM_TYPE_FAIL, "Disabled by async context");
+        return TypeFailureWarning(parser, "Disabled by async context");
 
     if (parser.pc->isArrowFunction())
-        return Warn(parser, JSMSG_USE_ASM_TYPE_FAIL, "Disabled by arrow function context");
+        return TypeFailureWarning(parser, "Disabled by arrow function context");
 
     // Class constructors are also methods
     if (parser.pc->isMethod() || parser.pc->isGetterOrSetter())
-        return Warn(parser, JSMSG_USE_ASM_TYPE_FAIL, "Disabled by class constructor or method context");
+        return TypeFailureWarning(parser, "Disabled by class constructor or method context");
 
     return true;
 }
 
 static UniqueChars
 BuildConsoleMessage(JSContext* cx, unsigned time, JS::AsmJSCacheResult cacheResult)
 {
 #ifndef JS_MORE_DETERMINISTIC
@@ -8812,17 +8822,17 @@ js::CompileAsmJS(JSContext* cx, AsmJSPar
     // asm.js module function. Special cases in the bytecode emitter avoid
     // generating bytecode for asm.js functions, allowing this asm.js module
     // function to be the finished result.
     MOZ_ASSERT(funbox->function()->isInterpreted());
     funbox->object = moduleFun;
 
     // Success! Write to the console with a "warning" message.
     *validated = true;
-    Warn(parser, JSMSG_USE_ASM_TYPE_OK, message.get());
+    SuccessfulValidation(parser, Move(message));
     return NoExceptionPending(cx);
 }
 
 /*****************************************************************************/
 // asm.js testing functions
 
 bool
 js::IsAsmJSModuleNative(Native native)