Bug 883226, part 6 - Clean up string literal parsing. r=Waldo.
authorJason Orendorff <jorendorff@mozilla.com>
Wed, 19 Jun 2013 14:43:39 -0500
changeset 147172 df5cc60bb55d4685863cbff5688c62e09407b0b7
parent 147171 e7c5639bebe8f4a56c5d7a96966067fb09f608f9
child 147173 8c2dec82bf298d8a35cd647bea0ceb1a662e0b1f
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs883226
milestone24.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 883226, part 6 - Clean up string literal parsing. r=Waldo.
js/src/frontend/FullParseHandler.h
js/src/frontend/Parser.cpp
js/src/frontend/Parser.h
js/src/frontend/SyntaxParseHandler.h
--- a/js/src/frontend/FullParseHandler.h
+++ b/js/src/frontend/FullParseHandler.h
@@ -98,38 +98,41 @@ class FullParseHandler
         if (!dn)
             return NULL;
 
         dn->setOp(JSOP_NOP);
         dn->setDefn(true);
         dn->pn_dflags |= PND_PLACEHOLDER;
         return dn;
     }
-    ParseNode *newAtom(ParseNodeKind kind, JSAtom *atom, JSOp op = JSOP_NOP) {
-        ParseNode *pn = new_<NullaryNode>(kind, pos());
-        if (!pn)
-            return NULL;
-        pn->setOp(op);
-        pn->pn_atom = atom;
-        return pn;
+
+    ParseNode *newAtom(ParseNodeKind kind, JSAtom *atom, const TokenPos &pos) {
+        return new_<NullaryNode>(kind, JSOP_NOP, pos, atom);
     }
+
     ParseNode *newNumber(double value, DecimalPoint decimalPoint, const TokenPos &pos) {
         ParseNode *pn = new_<NullaryNode>(PNK_NUMBER, pos);
         if (!pn)
             return NULL;
         pn->initNumber(value, decimalPoint);
         return pn;
     }
 
     ParseNode *newBooleanLiteral(bool cond, const TokenPos &pos) {
         return new_<BooleanLiteral>(cond, pos);
     }
+
+    ParseNode *newStringLiteral(JSAtom *atom, const TokenPos &pos) {
+        return new_<NullaryNode>(PNK_STRING, JSOP_STRING, pos, atom);
+    }
+
     ParseNode *newThisLiteral(const TokenPos &pos) {
         return new_<ThisLiteral>(pos);
     }
+
     ParseNode *newNullLiteral(const TokenPos &pos) {
         return new_<NullLiteral>(pos);
     }
 
     // The Boxer object here is any object that can allocate ObjectBoxes.
     // Specifically, a Boxer has a .newObjectBox(T) method that accepts a
     // Rooted<RegExpObject*> argument and returns an ObjectBox*.
     template <class Boxer>
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -6370,31 +6370,28 @@ Parser<ParseHandler>::identifierName()
     if (!pc->inDeclDestructuring && !noteNameUse(name, pn))
         return null();
 
     return pn;
 }
 
 template <typename ParseHandler>
 typename ParseHandler::Node
-Parser<ParseHandler>::atomNode(ParseNodeKind kind, JSOp op)
+Parser<ParseHandler>::stringLiteral()
 {
     JSAtom *atom = tokenStream.currentToken().atom();
-    Node pn = handler.newAtom(kind, atom, op);
-    if (!pn)
-        return null();
 
     // Large strings are fast to parse but slow to compress. Stop compression on
     // them, so we don't wait for a long time for compression to finish at the
     // end of compilation.
     const size_t HUGE_STRING = 50000;
-    if (sct && sct->active() && kind == PNK_STRING && atom->length() >= HUGE_STRING)
+    if (sct && sct->active() && atom->length() >= HUGE_STRING)
         sct->abort();
 
-    return pn;
+    return handler.newStringLiteral(atom, pos());
 }
 
 template <typename ParseHandler>
 typename ParseHandler::Node
 Parser<ParseHandler>::newRegExp()
 {
     // Create the regexp even when doing a syntax parse, to check the regexp's syntax.
     size_t length = tokenStream.getTokenbuf().length();
@@ -6584,17 +6581,17 @@ Parser<ParseHandler>::primaryExpr(TokenK
               case TOK_NAME:
                 {
                     atom = tokenStream.currentToken().name();
                     if (atom == context->names().get) {
                         op = JSOP_INITPROP_GETTER;
                     } else if (atom == context->names().set) {
                         op = JSOP_INITPROP_SETTER;
                     } else {
-                        pn3 = handler.newAtom(PNK_NAME, atom);
+                        pn3 = handler.newAtom(PNK_NAME, atom, pos());
                         if (!pn3)
                             return null();
                         break;
                     }
 
                     tt = tokenStream.getToken(TSF_KEYWORD_IS_NAME);
                     if (tt == TOK_NAME) {
                         atom = tokenStream.currentToken().name();
@@ -6609,32 +6606,32 @@ Parser<ParseHandler>::primaryExpr(TokenK
                             pn3 = handler.newNumber(index, NoDecimal, pos());
                             if (!pn3)
                                 return null();
                             tmp = DoubleValue(index);
                             atom = ToAtom<CanGC>(context, HandleValue::fromMarkedLocation(&tmp));
                             if (!atom)
                                 return null();
                         } else {
-                            pn3 = handler.newName(atom->asPropertyName(), pc, PNK_STRING);
+                            pn3 = stringLiteral();
                             if (!pn3)
                                 return null();
                         }
                     } else if (tt == TOK_NUMBER) {
                         double number = tokenStream.currentToken().number();
                         tmp = DoubleValue(number);
                         atom = ToAtom<CanGC>(context, HandleValue::fromMarkedLocation(&tmp));
                         if (!atom)
                             return null();
                         pn3 = newNumber(tokenStream.currentToken());
                         if (!pn3)
                             return null();
                     } else {
                         tokenStream.ungetToken();
-                        pn3 = handler.newAtom(PNK_NAME, atom);
+                        pn3 = handler.newAtom(PNK_NAME, atom, pos());
                         if (!pn3)
                             return null();
                         break;
                     }
 
                     JS_ASSERT(op == JSOP_INITPROP_GETTER || op == JSOP_INITPROP_SETTER);
 
                     handler.setListFlag(pn, PNX_NONCONST);
@@ -6654,17 +6651,17 @@ Parser<ParseHandler>::primaryExpr(TokenK
               case TOK_STRING: {
                 atom = tokenStream.currentToken().atom();
                 uint32_t index;
                 if (atom->isIndex(&index)) {
                     pn3 = handler.newNumber(index, NoDecimal, pos());
                     if (!pn3)
                         return null();
                 } else {
-                    pn3 = handler.newAtom(PNK_STRING, atom);
+                    pn3 = stringLiteral();
                     if (!pn3)
                         return null();
                 }
                 break;
               }
               case TOK_RC:
                 goto end_obj_init;
               default:
@@ -6793,17 +6790,17 @@ Parser<ParseHandler>::primaryExpr(TokenK
         pn = handler.setInParens(pn);
 
         if (!genexp)
             MUST_MATCH_TOKEN(TOK_RP, JSMSG_PAREN_IN_PAREN);
         return pn;
       }
 
       case TOK_STRING:
-        return atomNode(PNK_STRING, JSOP_STRING);
+        return stringLiteral();
 
       case TOK_NAME:
         return identifierName();
 
       case TOK_REGEXP:
         return newRegExp();
 
       case TOK_NUMBER:
--- a/js/src/frontend/Parser.h
+++ b/js/src/frontend/Parser.h
@@ -356,21 +356,17 @@ struct Parser : private AutoGCRooter, pu
     }
     void clearAbortedSyntaxParse() {
         abortedSyntaxParse = false;
     }
 
   private:
     Parser *thisForCtor() { return this; }
 
-    /*
-     * Create a parse node with the given kind and op using the current token's
-     * atom. 
-    */
-    Node atomNode(ParseNodeKind kind, JSOp op);
+    Node stringLiteral();
 
     inline bool abortIfSyntaxParser();
 
   public:
 
     /* Public entry points for parsing. */
     Node statement(bool canHaveDirectives = false);
     bool maybeParseDirective(Node pn, bool *cont);
--- a/js/src/frontend/SyntaxParseHandler.h
+++ b/js/src/frontend/SyntaxParseHandler.h
@@ -52,25 +52,26 @@ class SyntaxParseHandler
     Node newName(PropertyName *name, ParseContext<SyntaxParseHandler> *pc,
                  ParseNodeKind kind = PNK_NAME) {
         lastAtom = name;
         return NodeName;
     }
     DefinitionNode newPlaceholder(JSAtom *atom, ParseContext<SyntaxParseHandler> *pc) {
         return Definition::PLACEHOLDER;
     }
-    Node newAtom(ParseNodeKind kind, JSAtom *atom, JSOp op = JSOP_NOP) {
-        if (kind == PNK_STRING) {
-            lastAtom = atom;
-            lastStringPos = tokenStream.currentToken().pos;
-        }
+    Node newAtom(ParseNodeKind kind, JSAtom *atom, const TokenPos &pos) { return NodeString; }
+    Node newNumber(double value, DecimalPoint decimalPoint, const TokenPos &pos) { return NodeGeneric; }
+    Node newBooleanLiteral(bool cond, const TokenPos &pos) { return NodeGeneric; }
+
+    Node newStringLiteral(JSAtom *atom, const TokenPos &pos) {
+        lastAtom = atom;
+        lastStringPos = pos;
         return NodeString;
     }
-    Node newNumber(double value, DecimalPoint decimalPoint, const TokenPos &pos) { return NodeGeneric; }
-    Node newBooleanLiteral(bool cond, const TokenPos &pos) { return NodeGeneric; }
+
     Node newThisLiteral(const TokenPos &pos) { return NodeGeneric; }
     Node newNullLiteral(const TokenPos &pos) { return NodeGeneric; }
 
     template <class Boxer>
     Node newRegExp(JSObject *reobj, const TokenPos &pos, Boxer &boxer) { return NodeGeneric; }
 
     Node newConditional(Node cond, Node thenExpr, Node elseExpr) { return NodeGeneric; }