Bug 1303703 - Part 4: Check assignment destructuring syntax before constant-folding. r=shu
authorAndré Bargull <andre.bargull@gmail.com>
Sat, 22 Apr 2017 03:32:09 -0700
changeset 402712 332fa2188d891a1aa15c9c98fd2e1f7007a46239
parent 402711 8f2c0ac318b10cac245519338ed8556bcfce09e6
child 402713 827141143dc93f77a9d2862b23def5726c47201e
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersshu
bugs1303703
milestone55.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 1303703 - Part 4: Check assignment destructuring syntax before constant-folding. r=shu
js/src/frontend/Parser.cpp
js/src/tests/ecma_6/Destructuring/constant-folding.js
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -9799,16 +9799,19 @@ Parser<ParseHandler, CharT>::objectLiter
 
             Node propExpr = assignExpr(InAllowed, yieldHandling, TripledotProhibited,
                                        possibleError);
             if (!propExpr)
                 return null();
 
             handler.checkAndSetIsDirectRHSAnonFunction(propExpr);
 
+            if (possibleError)
+                checkDestructuringAssignmentElement(propExpr, exprPos, possibleError);
+
             if (foldConstants && !FoldConstants(context, &propExpr, this))
                 return null();
 
             if (propAtom == context->names().proto) {
                 if (seenPrototypeMutation) {
                     // Directly report the error when we're not in a
                     // destructuring context.
                     if (!possibleError) {
@@ -9831,19 +9834,16 @@ Parser<ParseHandler, CharT>::objectLiter
                     return null();
             } else {
                 if (!handler.isConstant(propExpr))
                     handler.setListFlag(literal, PNX_NONCONST);
 
                 if (!handler.addPropertyDefinition(literal, propName, propExpr))
                     return null();
             }
-
-            if (possibleError)
-                checkDestructuringAssignmentElement(propExpr, exprPos, possibleError);
         } else if (propType == PropertyType::Shorthand) {
             /*
              * Support, e.g., |({x, y} = o)| as destructuring shorthand
              * for |({x: x, y: y} = o)|, and |var o = {x, y}| as initializer
              * shorthand for |var o = {x: x, y: y}|.
              */
             Rooted<PropertyName*> name(context, identifierReference(yieldHandling));
             if (!name)
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_6/Destructuring/constant-folding.js
@@ -0,0 +1,16 @@
+function assertSyntaxError(code) {
+    assertThrowsInstanceOf(function () { Function(code); }, SyntaxError, "Function:" + code);
+    assertThrowsInstanceOf(function () { eval(code); }, SyntaxError, "eval:" + code);
+    var ieval = eval;
+    assertThrowsInstanceOf(function () { ieval(code); }, SyntaxError, "indirect eval:" + code);
+}
+
+// |true && a| is constant-folded to |a|, ensure the destructuring assignment
+// validation takes place before constant-folding.
+for (let prefix of ["null,", "var", "let", "const"]) {
+    assertSyntaxError(`${prefix} [true && a] = [];`);
+    assertSyntaxError(`${prefix} {p: true && a} = {};`);
+}
+
+if (typeof reportCompare === "function")
+    reportCompare(true, true);