Bug 901987 - The RHS of a for-of loop is an assignment expression r=jorendorff
authorAndy Wingo <wingo@igalia.com>
Tue, 11 Mar 2014 09:31:18 +0100
changeset 190129 39f411171c6f3053d6e2f648722ec41e2b9ef546
parent 190128 7450b87d6ff4f51e8632bf5a9951dd1deb982c99
child 190130 56b85741f932189b7e031a53ed090772eefc1f3a
push id3503
push userraliiev@mozilla.com
push dateMon, 28 Apr 2014 18:51:11 +0000
treeherdermozilla-beta@c95ac01e332e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs901987
milestone30.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 901987 - The RHS of a for-of loop is an assignment expression r=jorendorff
js/src/frontend/Parser.cpp
js/src/jit-test/tests/for-of/syntax-4.js
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -4269,17 +4269,17 @@ Parser<FullParseHandler>::forStatement()
             JS_ASSERT(!blockObj);
             pn2 = pn1;
             pn1 = nullptr;
 
             if (!checkAndMarkAsAssignmentLhs(pn2, PlainAssignment))
                 return null();
         }
 
-        pn3 = expr();
+        pn3 = (headKind == PNK_FOROF) ? assignExpr() : expr();
         if (!pn3)
             return null();
 
         if (blockObj) {
             /*
              * Now that the pn3 has been parsed, push the let scope. To hold
              * the blockObj for the emitter, wrap the PNK_LEXICALSCOPE node
              * created by PushLetScope around the for's initializer. This also
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/for-of/syntax-4.js
@@ -0,0 +1,19 @@
+// The right-hand-side of a for-of is an assignment expression.
+
+load(libdir + 'asserts.js');
+
+function assertSyntaxError(str) {
+  assertThrowsInstanceOf(function () { return Function(str); }, SyntaxError);
+}
+
+assertSyntaxError("for (var x     of 1, 2) {}");
+assertSyntaxError("for (var [x]   of 1, 2) {}");
+assertSyntaxError("for (var {x}   of 1, 2) {}");
+
+assertSyntaxError("for (let x     of 1, 2) {}");
+assertSyntaxError("for (let [x]   of 1, 2) {}");
+assertSyntaxError("for (let {x}   of 1, 2) {}");
+
+assertSyntaxError("for (const x   of 1, 2) {}");
+assertSyntaxError("for (const [x] of 1, 2) {}");
+assertSyntaxError("for (const {x} of 1, 2) {}");