Bug 1501928 - Part 2: Remove MUST_MATCH_TOKEN_FUNC* macros. r=Waldo
authorTooru Fujisawa <arai_a@mac.com>
Fri, 02 Nov 2018 15:51:05 +0900
changeset 445356 6af00f47b82911306268990c6c45a3e5b9dc622d
parent 445355 b07f54650288bf8664ca7a1ef67ca747ff46fdbb
child 445357 c0ff603045c080877553eb2d3a45abd8ef58a1d0
push id109719
push userarai_a@mac.com
push dateFri, 09 Nov 2018 06:25:57 +0000
treeherdermozilla-inbound@a922413f0f74 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs1501928
milestone65.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 1501928 - Part 2: Remove MUST_MATCH_TOKEN_FUNC* macros. r=Waldo
js/src/frontend/Parser.cpp
js/src/frontend/Parser.h
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -86,25 +86,16 @@ using BindingNameVector = Vector<Binding
         if (!tokenStream.getToken(&token, modifier))                                        \
             return failureValue;                                                            \
         if (!(cond)) {                                                                      \
             errorReport;                                                                    \
             return failureValue;                                                            \
         }                                                                                   \
     JS_END_MACRO
 
-#define MUST_MATCH_TOKEN_FUNC_MOD_OR(func, modifier, errorNumber, failureValue) \
-    MUST_MATCH_TOKEN_INTERNAL((func)(token), modifier, error(errorNumber), failureValue)
-
-#define MUST_MATCH_TOKEN_FUNC_OR(func, errorNumber, failureValue) \
-    MUST_MATCH_TOKEN_FUNC_MOD_OR(func, TokenStream::None, errorNumber, failureValue)
-
-#define MUST_MATCH_TOKEN_FUNC(func, errorNumber) \
-    MUST_MATCH_TOKEN_FUNC_OR(func, errorNumber, null())
-
 #define MUST_MATCH_TOKEN_MOD_WITH_REPORT_OR(tt, modifier, errorReport, failureValue) \
     MUST_MATCH_TOKEN_INTERNAL(token == tt, modifier, errorReport, failureValue)
 
 #define MUST_MATCH_TOKEN_MOD_WITH_REPORT(tt, modifier, errorReport) \
     MUST_MATCH_TOKEN_MOD_WITH_REPORT_OR(tt, modifier, errorReport, null())
 
 template <class T, class U>
 static inline void
@@ -148,25 +139,26 @@ GeneralParser<ParseHandler, Unit>::asFin
 {
     static_assert(mozilla::IsBaseOf<GeneralParser<ParseHandler, Unit>, FinalParser>::value,
                   "inheritance relationship required by the static_cast<> below");
 
     return static_cast<const FinalParser*>(this);
 }
 
 template <class ParseHandler, typename Unit>
+template <typename ConditionT>
 bool
-GeneralParser<ParseHandler, Unit>::mustMatchToken(TokenKind expected, Modifier modifier,
-                                                  unsigned errorNumber)
+GeneralParser<ParseHandler, Unit>::mustMatchTokenInternal(ConditionT condition, Modifier modifier,
+                                                          unsigned errorNumber)
 {
     TokenKind actual;
     if (!tokenStream.getToken(&actual, modifier)) {
         return false;
     }
-    if (actual != expected) {
+    if (!condition(actual)) {
         error(errorNumber);
         return false;
     }
     return true;
 }
 
 template <class ParseHandler, typename Unit>
 void
@@ -4892,17 +4884,19 @@ Parser<FullParseHandler, Unit>::namedImp
         }
     } else {
         MOZ_ASSERT(tt == TokenKind::Mul);
 
         if (!mustMatchToken(TokenKind::As, JSMSG_AS_AFTER_IMPORT_STAR)) {
             return false;
         }
 
-        MUST_MATCH_TOKEN_FUNC_OR(TokenKindIsPossibleIdentifierName, JSMSG_NO_BINDING_NAME, false);
+        if (!mustMatchToken(TokenKindIsPossibleIdentifierName, JSMSG_NO_BINDING_NAME)) {
+            return false;
+        }
 
         NameNodeType importName = newName(context->names().star);
         if (!importName) {
             return false;
         }
 
         // Namespace imports are are not indirect bindings but lexical
         // definitions that hold a module namespace object. They are treated
@@ -5514,17 +5508,19 @@ GeneralParser<ParseHandler, Unit>::expor
             return null();
         }
 
         bool foundAs;
         if (!tokenStream.matchToken(&foundAs, TokenKind::As)) {
             return null();
         }
         if (foundAs) {
-            MUST_MATCH_TOKEN_FUNC(TokenKindIsPossibleIdentifierName, JSMSG_NO_EXPORT_NAME);
+            if (!mustMatchToken(TokenKindIsPossibleIdentifierName, JSMSG_NO_EXPORT_NAME)) {
+                return null();
+            }
         }
 
         NameNodeType exportName = newName(anyChars.currentName());
         if (!exportName) {
             return null();
         }
 
         if (!checkExportedNameForClause(exportName)) {
--- a/js/src/frontend/Parser.h
+++ b/js/src/frontend/Parser.h
@@ -871,21 +871,35 @@ FOR_EACH_PARSENODE_SUBCLASS(DECLARE_TYPE
     inline void setAwaitHandling(AwaitHandling awaitHandling);
     inline void setInParametersOfAsyncFunction(bool inParameters);
 
     /*
      * Parse a top-level JS script.
      */
     ListNodeType parse();
 
+  private:
+    template<typename ConditionT>
+    MOZ_MUST_USE bool mustMatchTokenInternal(ConditionT condition, Modifier modifier,
+                                             unsigned errorNumber);
+
+  public:
+    MOZ_MUST_USE bool mustMatchToken(TokenKind expected, Modifier modifier, unsigned errorNumber) {
+        return mustMatchTokenInternal([expected](TokenKind actual) { return actual == expected; },
+                                      modifier, errorNumber);
+    }
+
     MOZ_MUST_USE bool mustMatchToken(TokenKind excpected, unsigned errorNumber) {
         return mustMatchToken(excpected, TokenStream::None, errorNumber);
     }
 
-    MOZ_MUST_USE bool mustMatchToken(TokenKind expected, Modifier modifier, unsigned errorNumber);
+    template<typename ConditionT>
+    MOZ_MUST_USE bool mustMatchToken(ConditionT condition, unsigned errorNumber) {
+        return mustMatchTokenInternal(condition, TokenStream::None, errorNumber);
+    }
 
     /* Report the given error at the current offset. */
     void error(unsigned errorNumber, ...);
     void errorWithNotes(UniquePtr<JSErrorNotes> notes, unsigned errorNumber, ...);
 
     /* Report the given error at the given offset. */
     void errorAt(uint32_t offset, unsigned errorNumber, ...);
     void errorWithNotesAt(UniquePtr<JSErrorNotes> notes, uint32_t offset,