Bug 1296814 - Introduce Parser::extraWarning. r=anba
authorJeff Walden <jwalden@mit.edu>
Mon, 07 Nov 2016 15:23:17 -0800
changeset 322547 1404e070a44c8fb5e7723daa12aea5c39502191c
parent 322546 6b8ade7340f10009de27b114534b610b604eac97
child 322548 a6329e0a6f9696d5e95ac7f50009de5d47d4e538
push id21
push usermaklebus@msu.edu
push dateThu, 01 Dec 2016 06:22:08 +0000
reviewersanba
bugs1296814
milestone52.0a1
Bug 1296814 - Introduce Parser::extraWarning. 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>::extraWarning(unsigned errorNumber, ...)
+{
+    va_list args;
+    va_start(args, errorNumber);
+    bool result = reportHelper(ParseExtraWarning, false, pos().begin, errorNumber, args);
+    va_end(args);
+    return result;
+}
+
+template <typename ParseHandler>
+bool
 Parser<ParseHandler>::strictModeError(unsigned errorNumber, ...)
 {
     va_list args;
     va_start(args, errorNumber);
     bool res = reportHelper(ParseStrictError, pc->sc()->strict(), pos().begin, errorNumber, args);
     va_end(args);
     return res;
 }
@@ -3862,17 +3873,17 @@ Parser<ParseHandler>::condition(InHandli
     MUST_MATCH_TOKEN(TOK_LP, JSMSG_PAREN_BEFORE_COND);
     Node pn = exprInParens(inHandling, yieldHandling, TripledotProhibited);
     if (!pn)
         return null();
     MUST_MATCH_TOKEN(TOK_RP, JSMSG_PAREN_AFTER_COND);
 
     /* Check for (a = b) and warn about possible (a == b) mistype. */
     if (handler.isUnparenthesizedAssignment(pn)) {
-        if (!qeport(ParseExtraWarning, JSMSG_EQUAL_AS_ASSIGN))
+        if (!extraWarning(JSMSG_EQUAL_AS_ASSIGN))
             return null();
     }
     return pn;
 }
 
 template <typename ParseHandler>
 bool
 Parser<ParseHandler>::matchLabel(YieldHandling yieldHandling, MutableHandle<PropertyName*> label)
@@ -5242,17 +5253,17 @@ Parser<ParseHandler>::ifStatement(YieldH
         Node cond = condition(InAllowed, yieldHandling);
         if (!cond)
             return null();
 
         TokenKind tt;
         if (!tokenStream.peekToken(&tt, TokenStream::Operand))
             return null();
         if (tt == TOK_SEMI) {
-            if (!qeport(ParseExtraWarning, JSMSG_EMPTY_CONSEQUENT))
+            if (!extraWarning(JSMSG_EMPTY_CONSEQUENT))
                 return null();
         }
 
         Node thenBranch = consequentOrAlternative(yieldHandling);
         if (!thenBranch)
             return null();
 
         if (!condList.append(cond) || !thenList.append(thenBranch) || !posList.append(begin))
@@ -8196,17 +8207,17 @@ Parser<ParseHandler>::comprehensionIf(Ge
     MUST_MATCH_TOKEN(TOK_LP, JSMSG_PAREN_BEFORE_COND);
     Node cond = assignExpr(InAllowed, YieldIsKeyword, TripledotProhibited);
     if (!cond)
         return null();
     MUST_MATCH_TOKEN(TOK_RP, JSMSG_PAREN_AFTER_COND);
 
     /* Check for (a = b) and warn about possible (a == b) mistype. */
     if (handler.isUnparenthesizedAssignment(cond)) {
-        if (!qeport(ParseExtraWarning, JSMSG_EQUAL_AS_ASSIGN))
+        if (!extraWarning(JSMSG_EQUAL_AS_ASSIGN))
             return null();
     }
 
     Node then = comprehensionTail(comprehensionKind);
     if (!then)
         return null();
 
     return handler.newIfStatement(begin, cond, then, null());
--- a/js/src/frontend/Parser.h
+++ b/js/src/frontend/Parser.h
@@ -915,16 +915,23 @@ 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, ...);
 
+    /*
+     * 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