#541: hack for(const x in y) with test changes

This commit is contained in:
Cameron Kaiser 2019-06-16 15:57:45 -07:00
parent 78e9f2e0e5
commit f47c9dba75
5 changed files with 22 additions and 5 deletions

View File

@ -5502,7 +5502,7 @@ BytecodeEmitter::emitIterator()
bool
BytecodeEmitter::emitForInOrOfVariables(ParseNode* pn)
{
MOZ_ASSERT(pn->isKind(PNK_VAR) || pn->isKind(PNK_LET));
MOZ_ASSERT(pn->isKind(PNK_VAR) || pn->isKind(PNK_LET) || pn->isKind(PNK_CONST));
// ES6 specifies that loop variables get a fresh binding in each iteration.
// This is currently implemented for C-style for(;;) loops, but not
@ -5524,7 +5524,7 @@ BytecodeEmitter::emitForInOrOfVariables(ParseNode* pn)
if (!emitVariables(pn, DefineVars))
return false;
} else {
MOZ_ASSERT(pn->isKind(PNK_LET));
MOZ_ASSERT(pn->isKind(PNK_LET) || pn->isKind(PNK_CONST));
if (!emitVariables(pn, InitializeVars))
return false;
}

View File

@ -4581,12 +4581,15 @@ Parser<ParseHandler>::declarationPattern(Node decl, TokenKind tt, BindData<Parse
*forHeadKind = PNK_FORHEAD;
if (*forHeadKind != PNK_FORHEAD) {
// TenFourFox issue 541
#if(0)
// |for (const ... in ...);| and |for (const ... of ...);| are
// syntax errors for now. We'll fix this in bug 449811.
if (handler.declarationIsConst(decl)) {
report(ParseError, false, pattern, JSMSG_BAD_CONST_DECL);
return null();
}
#endif
if (!checkDestructuringPattern(data, pattern))
return null();
@ -4786,9 +4789,14 @@ Parser<ParseHandler>::declarationName(Node decl, TokenKind tt, BindData<ParseHan
return null();
if (isForIn || isForOf) {
// TenFourFox issue 541
#if(0)
// XXX Uncomment this when fixing bug 449811. Until then,
// |for (const ... in/of ...)| remains an error.
//constRequiringInitializer = false;
#else
constRequiringInitializer = false;
#endif
*forHeadKind = isForIn ? PNK_FORIN : PNK_FOROF;
} else {

View File

@ -18,16 +18,16 @@ eval(`let {x:x} = {x:42}; assertEq(x, 42);`);
eval(`let [x] = [42]; assertEq(x, 42);`);
eval(`for (let x in [1]) { assertEq(x, "0"); }`);
expectError(`for (const x in [1]) { assertEq(x, "0"); }`); // XXX bug 449811
// expectError(`for (const x in [1]) { assertEq(x, "0"); }`); // XXX bug 449811
eval(`for (let x of [1]) { assertEq(x, 1); }`);
expectError(`for (const x of [1]) { assertEq(x, 1); }`); // XXX bug 449811
// expectError(`for (const x of [1]) { assertEq(x, 1); }`); // XXX bug 449811
eval(`for (let i = 0; i < 1; i++) { assertEq(i, 0); }`);
eval(`var done = false; for (const i = 0; !done; done = true) { assertEq(i, 0); }`);
eval(`for (let of of [1]) { assertEq(of, 1); }`);
expectError(`for (const of of [1]) { assertEq(of, 1); }`); // XXX bug 449811
// expectError(`for (const of of [1]) { assertEq(of, 1); }`); // XXX bug 449811
eval(`try { throw 17; } catch (let) { assertEq(let, 17); }`);
eval(`try { throw [17]; } catch ([let]) { assertEq(let, 17); }`);

View File

@ -44,6 +44,8 @@ Function(`if (true)
continue;
}`)();
/* Enabled by TenFourFox issue 541
// We don't support for (const ... in ...) or for (const ... of ...) yet. When
// we do, these all should start passing without throwing a syntax error, and
// we can remove the try/catch here, and the ultimate throw-canary forcing this
@ -51,6 +53,8 @@ Function(`if (true)
try
{
*/
executeGlobalScript(`for (const a5 of [])
continue;`);
@ -87,6 +91,7 @@ Function(`if (true)
continue;
}`)();
/*
throw new Error("Congratulations on making for (const … in/of …) work! " +
"Please remove the try/catch and this throw.");
}
@ -95,6 +100,7 @@ catch (e)
assertEq(e instanceof SyntaxError, true,
"unexpected error: expected SyntaxError, got " + e);
}
*/
/******************************************************************************/

View File

@ -26,6 +26,8 @@ assertStmt("for each ({a:x,b:y,c:z} in foo);", forEachInStmt(axbycz, ident("foo"
assertStmt("for each (var [x,y,z] in foo);", forEachInStmt(varDecl([{ id: xyz, init: null }]), ident("foo"), emptyStmt));
assertStmt("for each (let [x,y,z] in foo);", forEachInStmt(letDecl([{ id: xyz, init: null }]), ident("foo"), emptyStmt));
assertStmt("for each ([x,y,z] in foo);", forEachInStmt(xyz, ident("foo"), emptyStmt));
/*
// Enabled by TenFourFox issue 541
assertError("for (const x in foo);", SyntaxError);
assertError("for (const {a:x,b:y,c:z} in foo);", SyntaxError);
assertError("for (const [x,y,z] in foo);", SyntaxError);
@ -35,6 +37,7 @@ assertError("for (const [x,y,z] of foo);", SyntaxError);
assertError("for each (const x in foo);", SyntaxError);
assertError("for each (const {a:x,b:y,c:z} in foo);", SyntaxError);
assertError("for each (const [x,y,z] in foo);", SyntaxError);
*/
assertError("for (x = 22 in foo);", SyntaxError);-
assertError("for ({a:x,b:y,c:z} = 22 in foo);", SyntaxError);