mirror of
https://github.com/classilla/tenfourfox.git
synced 2024-10-25 06:28:30 +00:00
#541: hack for(const x in y) with test changes
This commit is contained in:
parent
78e9f2e0e5
commit
f47c9dba75
@ -5502,7 +5502,7 @@ BytecodeEmitter::emitIterator()
|
|||||||
bool
|
bool
|
||||||
BytecodeEmitter::emitForInOrOfVariables(ParseNode* pn)
|
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.
|
// ES6 specifies that loop variables get a fresh binding in each iteration.
|
||||||
// This is currently implemented for C-style for(;;) loops, but not
|
// This is currently implemented for C-style for(;;) loops, but not
|
||||||
@ -5524,7 +5524,7 @@ BytecodeEmitter::emitForInOrOfVariables(ParseNode* pn)
|
|||||||
if (!emitVariables(pn, DefineVars))
|
if (!emitVariables(pn, DefineVars))
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
MOZ_ASSERT(pn->isKind(PNK_LET));
|
MOZ_ASSERT(pn->isKind(PNK_LET) || pn->isKind(PNK_CONST));
|
||||||
if (!emitVariables(pn, InitializeVars))
|
if (!emitVariables(pn, InitializeVars))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -4581,12 +4581,15 @@ Parser<ParseHandler>::declarationPattern(Node decl, TokenKind tt, BindData<Parse
|
|||||||
*forHeadKind = PNK_FORHEAD;
|
*forHeadKind = PNK_FORHEAD;
|
||||||
|
|
||||||
if (*forHeadKind != PNK_FORHEAD) {
|
if (*forHeadKind != PNK_FORHEAD) {
|
||||||
|
// TenFourFox issue 541
|
||||||
|
#if(0)
|
||||||
// |for (const ... in ...);| and |for (const ... of ...);| are
|
// |for (const ... in ...);| and |for (const ... of ...);| are
|
||||||
// syntax errors for now. We'll fix this in bug 449811.
|
// syntax errors for now. We'll fix this in bug 449811.
|
||||||
if (handler.declarationIsConst(decl)) {
|
if (handler.declarationIsConst(decl)) {
|
||||||
report(ParseError, false, pattern, JSMSG_BAD_CONST_DECL);
|
report(ParseError, false, pattern, JSMSG_BAD_CONST_DECL);
|
||||||
return null();
|
return null();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!checkDestructuringPattern(data, pattern))
|
if (!checkDestructuringPattern(data, pattern))
|
||||||
return null();
|
return null();
|
||||||
@ -4786,9 +4789,14 @@ Parser<ParseHandler>::declarationName(Node decl, TokenKind tt, BindData<ParseHan
|
|||||||
return null();
|
return null();
|
||||||
|
|
||||||
if (isForIn || isForOf) {
|
if (isForIn || isForOf) {
|
||||||
|
// TenFourFox issue 541
|
||||||
|
#if(0)
|
||||||
// XXX Uncomment this when fixing bug 449811. Until then,
|
// XXX Uncomment this when fixing bug 449811. Until then,
|
||||||
// |for (const ... in/of ...)| remains an error.
|
// |for (const ... in/of ...)| remains an error.
|
||||||
//constRequiringInitializer = false;
|
//constRequiringInitializer = false;
|
||||||
|
#else
|
||||||
|
constRequiringInitializer = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
*forHeadKind = isForIn ? PNK_FORIN : PNK_FOROF;
|
*forHeadKind = isForIn ? PNK_FORIN : PNK_FOROF;
|
||||||
} else {
|
} else {
|
||||||
|
@ -18,16 +18,16 @@ eval(`let {x:x} = {x:42}; assertEq(x, 42);`);
|
|||||||
eval(`let [x] = [42]; assertEq(x, 42);`);
|
eval(`let [x] = [42]; assertEq(x, 42);`);
|
||||||
|
|
||||||
eval(`for (let x in [1]) { assertEq(x, "0"); }`);
|
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); }`);
|
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(`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(`var done = false; for (const i = 0; !done; done = true) { assertEq(i, 0); }`);
|
||||||
|
|
||||||
eval(`for (let of of [1]) { assertEq(of, 1); }`);
|
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); }`);
|
||||||
eval(`try { throw [17]; } catch ([let]) { assertEq(let, 17); }`);
|
eval(`try { throw [17]; } catch ([let]) { assertEq(let, 17); }`);
|
||||||
|
@ -44,6 +44,8 @@ Function(`if (true)
|
|||||||
continue;
|
continue;
|
||||||
}`)();
|
}`)();
|
||||||
|
|
||||||
|
/* Enabled by TenFourFox issue 541
|
||||||
|
|
||||||
// We don't support for (const ... in ...) or for (const ... of ...) yet. When
|
// 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 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
|
// we can remove the try/catch here, and the ultimate throw-canary forcing this
|
||||||
@ -51,6 +53,8 @@ Function(`if (true)
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
executeGlobalScript(`for (const a5 of [])
|
executeGlobalScript(`for (const a5 of [])
|
||||||
continue;`);
|
continue;`);
|
||||||
|
|
||||||
@ -87,6 +91,7 @@ Function(`if (true)
|
|||||||
continue;
|
continue;
|
||||||
}`)();
|
}`)();
|
||||||
|
|
||||||
|
/*
|
||||||
throw new Error("Congratulations on making for (const … in/of …) work! " +
|
throw new Error("Congratulations on making for (const … in/of …) work! " +
|
||||||
"Please remove the try/catch and this throw.");
|
"Please remove the try/catch and this throw.");
|
||||||
}
|
}
|
||||||
@ -95,6 +100,7 @@ catch (e)
|
|||||||
assertEq(e instanceof SyntaxError, true,
|
assertEq(e instanceof SyntaxError, true,
|
||||||
"unexpected error: expected SyntaxError, got " + e);
|
"unexpected error: expected SyntaxError, got " + e);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
@ -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 (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 (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));
|
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 x in foo);", SyntaxError);
|
||||||
assertError("for (const {a:x,b:y,c:z} in foo);", SyntaxError);
|
assertError("for (const {a:x,b:y,c:z} in foo);", SyntaxError);
|
||||||
assertError("for (const [x,y,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 x in foo);", SyntaxError);
|
||||||
assertError("for each (const {a:x,b:y,c:z} 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 each (const [x,y,z] in foo);", SyntaxError);
|
||||||
|
*/
|
||||||
|
|
||||||
assertError("for (x = 22 in foo);", SyntaxError);-
|
assertError("for (x = 22 in foo);", SyntaxError);-
|
||||||
assertError("for ({a:x,b:y,c:z} = 22 in foo);", SyntaxError);
|
assertError("for ({a:x,b:y,c:z} = 22 in foo);", SyntaxError);
|
||||||
|
Loading…
Reference in New Issue
Block a user