Bug 1296814 - Introduce Parser::warning. r=anba
authorJeff Walden <jwalden@mit.edu>
Mon, 07 Nov 2016 15:23:18 -0800
changeset 322548 a6329e0a6f9696d5e95ac7f50009de5d47d4e538
parent 322547 1404e070a44c8fb5e7723daa12aea5c39502191c
child 322549 ae58d7e8cbf02abdd49b6442fad2fe2b547f4ff5
push id21
push usermaklebus@msu.edu
push dateThu, 01 Dec 2016 06:22:08 +0000
reviewersanba
bugs1296814
milestone52.0a1
Bug 1296814 - Introduce Parser::warning. r=anba
js/src/frontend/Parser.cpp
js/src/frontend/Parser.h
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -596,16 +596,27 @@ Parser<ParseHandler>::qeport(ParseReport
     va_start(args, errorNumber);
     bool result = reportHelper(kind, false, pos().begin, errorNumber, args);
     va_end(args);
     return result;
 }
 
 template <typename ParseHandler>
 bool
+Parser<ParseHandler>::warning(unsigned errorNumber, ...)
+{
+    va_list args;
+    va_start(args, errorNumber);
+    bool result = reportHelper(ParseWarning, false, pos().begin, errorNumber, args);
+    va_end(args);
+    return result;
+}
+
+template <typename ParseHandler>
+bool
 Parser<ParseHandler>::extraWarning(unsigned errorNumber, ...)
 {
     va_list args;
     va_start(args, errorNumber);
     bool result = reportHelper(ParseExtraWarning, false, pos().begin, errorNumber, args);
     va_end(args);
     return result;
 }
@@ -7044,17 +7055,17 @@ Parser<ParseHandler>::statementListItem(
       // ExpressionStatement[?Yield].
       //
       // These should probably be handled by a single ExpressionStatement
       // function in a default, not split up this way.
       case TOK_STRING:
         if (!canHaveDirectives && tokenStream.currentToken().atom() == context->names().useAsm) {
             if (!abortIfSyntaxParser())
                 return null();
-            if (!qeport(ParseWarning, JSMSG_USE_ASM_DIRECTIVE_FAIL))
+            if (!warning(JSMSG_USE_ASM_DIRECTIVE_FAIL))
                 return null();
         }
         return expressionStatement(yieldHandling);
 
       case TOK_YIELD: {
         // Don't use a ternary operator here due to obscure linker issues
         // around using static consts in the arms of a ternary.
         TokenStream::Modifier modifier;
@@ -9588,34 +9599,34 @@ bool
 Parser<ParseHandler>::warnOnceAboutExprClosure()
 {
 #ifndef RELEASE_OR_BETA
     JSContext* cx = context->maybeJSContext();
     if (!cx)
         return true;
 
     if (!cx->compartment()->warnedAboutExprClosure) {
-        if (!qeport(ParseWarning, JSMSG_DEPRECATED_EXPR_CLOSURE))
+        if (!warning(JSMSG_DEPRECATED_EXPR_CLOSURE))
             return false;
         cx->compartment()->warnedAboutExprClosure = true;
     }
 #endif
     return true;
 }
 
 template <typename ParseHandler>
 bool
 Parser<ParseHandler>::warnOnceAboutForEach()
 {
     JSContext* cx = context->maybeJSContext();
     if (!cx)
         return true;
 
     if (!cx->compartment()->warnedAboutForEach) {
-        if (!qeport(ParseWarning, JSMSG_DEPRECATED_FOR_EACH))
+        if (!warning(JSMSG_DEPRECATED_FOR_EACH))
             return false;
         cx->compartment()->warnedAboutForEach = true;
     }
     return true;
 }
 
 template class Parser<FullParseHandler>;
 template class Parser<SyntaxParseHandler>;
--- a/js/src/frontend/Parser.h
+++ b/js/src/frontend/Parser.h
@@ -915,23 +915,25 @@ class Parser final : private JS::AutoGCR
 
     /*
      * Handle a strict mode error at the current offset.  Report an error if in
      * strict mode code, or warn if not, using the given error number and
      * arguments.
      */
     MOZ_MUST_USE bool strictModeError(unsigned errorNumber, ...);
 
+    /* Report the given warning at the current offset. */
+    MOZ_MUST_USE bool warning(unsigned errorNumber, ...);
+
     /*
      * If extra warnings are enabled, report the given warning at the current
      * offset.
      */
     MOZ_MUST_USE bool extraWarning(unsigned errorNumber, ...);
 
-
     Parser(ExclusiveContext* cx, LifoAlloc& alloc, const ReadOnlyCompileOptions& options,
            const char16_t* chars, size_t length, bool foldConstants, UsedNameTracker& usedNames,
            Parser<SyntaxParseHandler>* syntaxParser, LazyScript* lazyOuterFunction);
     ~Parser();
 
     bool checkOptions();
 
     // A Parser::Mark is the extension of the LifoAlloc::Mark to the entire