Reland 104b182daf70
authorBrian Hackett <bhackett1024@gmail.com>
Fri, 08 Jul 2011 18:28:03 -0700
changeset 75193 fd60ba97753ba9904c0f9344a8e212cf2384ab89
parent 75192 4873f63c9d51c9f33d7ecea33c92c4f8704aaece
child 75194 7abfbaac06931b3c242934eafb0742646216382a
push id2
push userbsmedberg@mozilla.com
push dateFri, 19 Aug 2011 14:38:13 +0000
milestone8.0a1
Reland 104b182daf70
js/src/jsparse.cpp
js/src/tests/js1_8_5/extensions/jstests.list
js/src/tests/js1_8_5/extensions/regress-668438.js
--- a/js/src/jsparse.cpp
+++ b/js/src/jsparse.cpp
@@ -1549,31 +1549,24 @@ Parser::functionBody()
             pn = NULL;
         }
     }
 
     tc->flags = oldflags | (tc->flags & TCF_FUN_FLAGS);
     return pn;
 }
 
-/*
- * Creates a placeholder JSDefinition node for |atom| and adds it to the
- * current lexdeps.
- */
+/* Create a placeholder JSDefinition node for |atom|. */
 static JSDefinition *
-MakePlaceholder(AtomDefnAddPtr &p, JSParseNode *pn, JSTreeContext *tc)
-{
-    JSAtom *atom = pn->pn_atom;
-    JSDefinition *dn = (JSDefinition *) NameNode::create(atom, tc);
+MakePlaceholder(JSParseNode *pn, JSTreeContext *tc)
+{
+    JSDefinition *dn = (JSDefinition *) NameNode::create(pn->pn_atom, tc);
     if (!dn)
         return NULL;
 
-    if (!tc->lexdeps->add(p, atom, dn))
-        return NULL;
-
     dn->pn_type = TOK_NAME;
     dn->pn_op = JSOP_NOP;
     dn->pn_defn = true;
     dn->pn_dflags |= PND_PLACEHOLDER;
     return dn;
 }
 
 static bool
@@ -2782,18 +2775,18 @@ LeaveFunction(JSParseNode *fn, JSTreeCon
                      *   function f() { x; { function g() { x; } let x; } }
                      *
                      * Here, the 'let' must not capture all the uses of f's
                      * lexdep entry for x, but it must capture the x node
                      * referred to from g's TOK_UPVARS node.  Always turning
                      * inherited lexdeps into uses of a new outer definition
                      * allows us to handle both these cases in a natural way.
                      */
-                    outer_dn = MakePlaceholder(p, dn, tc);
-                    if (!outer_dn)
+                    outer_dn = MakePlaceholder(dn, tc);
+                    if (!outer_dn || !tc->lexdeps->add(p, atom, outer_dn))
                         return false;
                 }
             }
 
             /*
              * Insert dn's uses list at the front of outer_dn's list.
              *
              * Without loss of generality or correctness, we allow a dn to
@@ -6914,18 +6907,17 @@ CompExprTransplanter::transplant(JSParse
                     /*
                      * The variable originally appeared to be a use of a
                      * definition or placeholder outside the generator, but now
                      * we know it is scoped within the comprehension tail's
                      * clauses. Make it (along with any other uses within the
                      * generator) a use of a new placeholder in the generator's
                      * lexdeps.
                      */
-                    AtomDefnAddPtr p = tc->lexdeps->lookupForAdd(atom);
-                    JSDefinition *dn2 = MakePlaceholder(p, pn, tc);
+                    JSDefinition *dn2 = MakePlaceholder(pn, tc);
                     if (!dn2)
                         return false;
                     dn2->pn_pos = root->pn_pos;
 
                     /* 
                      * Change all uses of |dn| that lie within the generator's
                      * |yield| expression into uses of dn2.
                      */
@@ -6934,16 +6926,18 @@ CompExprTransplanter::transplant(JSParse
                     while ((pnu = *pnup) != NULL && pnu->pn_pos >= root->pn_pos) {
                         pnu->pn_lexdef = dn2;
                         dn2->pn_dflags |= pnu->pn_dflags & PND_USE2DEF_FLAGS;
                         pnup = &pnu->pn_link;
                     }
                     dn2->dn_uses = dn->dn_uses;
                     dn->dn_uses = *pnup;
                     *pnup = NULL;
+                    if (!tc->lexdeps->put(atom, dn2))
+                        return false;
                 } else if (dn->isPlaceholder()) {
                     /*
                      * The variable first occurs free in the 'yield' expression;
                      * move the existing placeholder node (and all its uses)
                      * from the parent's lexdeps into the generator's lexdeps.
                      */
                     tc->parent->lexdeps->remove(atom);
                     if (!tc->lexdeps->put(atom, dn))
@@ -8758,18 +8752,18 @@ Parser::primaryExpr(TokenKind tt, JSBool
                     /*
                      * No definition before this use in any lexical scope.
                      * Create a placeholder definition node to either:
                      * - Be adopted when we parse the real defining
                      *   declaration, or
                      * - Be left as a free variable definition if we never
                      *   see the real definition.
                      */
-                    dn = MakePlaceholder(p, pn, tc);
-                    if (!dn)
+                    dn = MakePlaceholder(pn, tc);
+                    if (!dn || !tc->lexdeps->add(p, dn->pn_atom, dn))
                         return NULL;
 
                     /*
                      * In case this is a forward reference to a function,
                      * we pessimistically set PND_FUNARG if the next token
                      * is not a left parenthesis.
                      *
                      * If the definition eventually parsed into dn is not a
--- a/js/src/tests/js1_8_5/extensions/jstests.list
+++ b/js/src/tests/js1_8_5/extensions/jstests.list
@@ -39,10 +39,11 @@ script regress-627984-5.js
 script regress-627984-6.js
 script regress-627984-7.js
 script regress-630377.js
 script regress-631723.js
 skip-if(!xulRuntime.shell) script regress-636818.js
 script regress-636697.js
 script is-generator.js
 script weakmap.js
+script regress-645160.js
 script regress-650753.js
-script regress-645160.js
+script regress-668438.js
new file mode 100644
--- /dev/null
+++ b/js/src/tests/js1_8_5/extensions/regress-668438.js
@@ -0,0 +1,12 @@
+// -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+// Any copyright is dedicated to the Public Domain.
+// http://creativecommons.org/licenses/publicdomain/
+
+// Don't assert trying to parse this.
+let(x = (x(( function() { 
+                 return { e: function() { e in x } };
+             }))
+         for (x in [])))
+true;
+
+reportCompare(true, true);