Bug 901987 - The RHS of a for-of loop is an assignment expression r=jorendorff

--HG--
extra : amend_source : d18317a5d17ad1c4ba243fc4184a13baf69b1415
This commit is contained in:
Andy Wingo 2014-03-11 09:31:18 +01:00
parent 4539a9ee78
commit 6cefd35997
2 changed files with 20 additions and 1 deletions

View File

@ -4274,7 +4274,7 @@ Parser<FullParseHandler>::forStatement()
return null();
}
pn3 = expr();
pn3 = (headKind == PNK_FOROF) ? assignExpr() : expr();
if (!pn3)
return null();

View File

@ -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) {}");