Bug 1504947 - Make ReflectParse code store a Parser<FullParseHandler, char16_t>* rather than a TokenStreamAnyChars*, because the former (or at least a Unit-specific token stream) will be necessary for proper column numbers when column numbers respect multi-unit UTF-8/16 code points. r=tcampbell
authorJeff Walden <jwalden@mit.edu>
Sat, 10 Nov 2018 21:18:12 -0800
changeset 502962 fc1fbf30d7039277b8603eaafa034848edc5a55e
parent 502961 e6653e8332fadda4a3effa82180f3fdfa110163e
child 502963 5b0d24759be622dd24c051e10e07941366626dd8
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstcampbell
bugs1504947
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 1504947 - Make ReflectParse code store a Parser<FullParseHandler, char16_t>* rather than a TokenStreamAnyChars*, because the former (or at least a Unit-specific token stream) will be necessary for proper column numbers when column numbers respect multi-unit UTF-8/16 code points. r=tcampbell
js/src/builtin/ReflectParse.cpp
--- a/js/src/builtin/ReflectParse.cpp
+++ b/js/src/builtin/ReflectParse.cpp
@@ -14,17 +14,16 @@
 
 #include "jspubtd.h"
 
 #include "builtin/Array.h"
 #include "builtin/Reflect.h"
 #include "frontend/ModuleSharedContext.h"
 #include "frontend/ParseNode.h"
 #include "frontend/Parser.h"
-#include "frontend/TokenStream.h"
 #include "js/CharacterEncoding.h"
 #include "js/StableStringChars.h"
 #include "vm/JSAtom.h"
 #include "vm/JSObject.h"
 #include "vm/RegExpObject.h"
 
 #include "vm/JSObject-inl.h"
 
@@ -234,27 +233,32 @@ enum class GeneratorStyle
  *
  * Bug 569487: generalize builder interface
  */
 class NodeBuilder
 {
     typedef AutoValueArray<AST_LIMIT> CallbackArray;
 
     JSContext*  cx;
-    TokenStreamAnyChars* tokenStream;
+    frontend::Parser<frontend::FullParseHandler, char16_t>* parser;
     bool        saveLoc;               /* save source location information?     */
     char const* src;                  /* source filename or null               */
     RootedValue srcval;                /* source filename JS value or null      */
     CallbackArray callbacks;           /* user-specified callbacks              */
     RootedValue userv;                 /* user-specified builder object or null */
 
   public:
     NodeBuilder(JSContext* c, bool l, char const* s)
-      : cx(c), tokenStream(nullptr), saveLoc(l), src(s), srcval(c), callbacks(cx),
-          userv(c)
+      : cx(c),
+        parser(nullptr),
+        saveLoc(l),
+        src(s),
+        srcval(c),
+        callbacks(cx),
+        userv(c)
     {}
 
     MOZ_MUST_USE bool init(HandleObject userobj = nullptr) {
         if (src) {
             if (!atomValue(src, &srcval)) {
                 return false;
             }
         } else {
@@ -295,18 +299,18 @@ class NodeBuilder
             }
 
             callbacks[i].set(funv);
         }
 
         return true;
     }
 
-    void setTokenStream(TokenStreamAnyChars* ts) {
-        tokenStream = ts;
+    void setParser(frontend::Parser<frontend::FullParseHandler, char16_t>* p) {
+        parser = p;
     }
 
   private:
     MOZ_MUST_USE bool callbackHelper(HandleValue fun, const InvokeArgs& args, size_t i,
                                      TokenPos* pos, MutableHandleValue dst)
     {
         // The end of the implementation of callback(). All arguments except
         // loc have already been stored in range [0, i).
@@ -702,18 +706,18 @@ NodeBuilder::newNodeLoc(TokenPos* pos, M
     if (!newObject(&loc)) {
         return false;
     }
 
     dst.setObject(*loc);
 
     uint32_t startLineNum, startColumnIndex;
     uint32_t endLineNum, endColumnIndex;
-    tokenStream->srcCoords.lineNumAndColumnIndex(pos->begin, &startLineNum, &startColumnIndex);
-    tokenStream->srcCoords.lineNumAndColumnIndex(pos->end, &endLineNum, &endColumnIndex);
+    parser->anyChars.srcCoords.lineNumAndColumnIndex(pos->begin, &startLineNum, &startColumnIndex);
+    parser->anyChars.srcCoords.lineNumAndColumnIndex(pos->end, &endLineNum, &endColumnIndex);
 
     if (!newObject(&to)) {
         return false;
     }
     val.setObject(*to);
     if (!defineProperty(loc, "start", val)) {
         return false;
     }
@@ -1829,19 +1833,19 @@ class ASTSerializer
         , lineno(ln)
 #endif
     {}
 
     bool init(HandleObject userobj) {
         return builder.init(userobj);
     }
 
-    void setParser(Parser<FullParseHandler, char16_t>* p) {
+    void setParser(frontend::Parser<frontend::FullParseHandler, char16_t>* p) {
         parser = p;
-        builder.setTokenStream(&p->anyChars);
+        builder.setParser(p);
     }
 
     bool program(ListNode* node, MutableHandleValue dst);
 };
 
 } /* anonymous namespace */
 
 AssignmentOperator
@@ -2013,17 +2017,22 @@ ASTSerializer::blockStatement(ListNode* 
     NodeVector stmts(cx);
     return statements(node, stmts) &&
            builder.blockStatement(stmts, &node->pn_pos, dst);
 }
 
 bool
 ASTSerializer::program(ListNode* node, MutableHandleValue dst)
 {
-    MOZ_ASSERT(parser->anyChars.srcCoords.lineNum(node->pn_pos.begin) == lineno);
+#ifdef DEBUG
+    {
+        const auto& srcCoords = parser->anyChars.srcCoords;
+        MOZ_ASSERT(srcCoords.lineNum(node->pn_pos.begin) == lineno);
+    }
+#endif
 
     NodeVector stmts(cx);
     return statements(node, stmts) &&
            builder.program(stmts, &node->pn_pos, dst);
 }
 
 bool
 ASTSerializer::sourceElement(ParseNode* pn, MutableHandleValue dst)