Bug 748550 - Remove support for |for (... = ... in/of ...)| now that ES6 has removed it. r=jorendorff

--HG--
extra : rebase_source : a277c231092abedfd037b7ee0b5693c848706b8a
This commit is contained in:
Jeff Walden 2015-04-02 21:08:11 -04:00
parent 6b5cb3d245
commit 811dd58432
21 changed files with 43 additions and 117 deletions

View File

@ -4807,39 +4807,11 @@ Parser<FullParseHandler>::forStatement()
if (isForDecl) {
pn2 = pn1->pn_head;
if ((pn2->isKind(PNK_NAME) && pn2->maybeExpr()) || pn2->isKind(PNK_ASSIGN)) {
/*
* Declaration with initializer.
*
* Rewrite 'for (<decl> x = i in o)' where <decl> is 'var' or
* 'const' to hoist the initializer or the entire decl out of
* the loop head.
*/
if (headKind == PNK_FOROF) {
report(ParseError, false, pn2, JSMSG_INVALID_FOR_OF_INIT);
return null();
}
if (blockObj) {
report(ParseError, false, pn2, JSMSG_INVALID_FOR_IN_INIT);
return null();
}
hoistedVar = pn1;
/*
* All of 'var x = i' is hoisted above 'for (x in o)'.
*
* Request JSOP_POP here since the var is for a simple
* name (it is not a destructuring binding's left-hand
* side) and it has an initializer.
*/
pn1->pn_xflags |= PNX_POPVAR;
pn1 = nullptr;
if (pn2->isKind(PNK_ASSIGN)) {
pn2 = pn2->pn_left;
MOZ_ASSERT(pn2->isKind(PNK_ARRAY) || pn2->isKind(PNK_OBJECT) ||
pn2->isKind(PNK_NAME));
}
// We have a bizarre |for (var/const/let x = ... in/of ...)|
// loop erroneously permitted by ES1-5 but removed in ES6.
report(ParseError, false, pn2, JSMSG_INVALID_FOR_INOF_DECL_WITH_INIT,
headKind == PNK_FOROF ? "of" : "in");
return null();
}
} else {
/* Not a declaration. */

View File

@ -1,4 +1,4 @@
// Binary: cache/js-dbg-32-f561f17e6c27-linux
// Flags:
//
Reflect.parse("for (var x = 3 in []) { }")
Reflect.parse("for (var x in []) { }")

View File

@ -3,4 +3,10 @@
//
load(libdir + 'asserts.js');
// value is not iterable
assertThrowsInstanceOf(function(){for(var[x]=x>>x in[[]<[]]){[]}}, TypeError);
(function() {
for (var [x] in [[] < []])
{
// Just a useless expression.
[];
}
})();

View File

@ -1,17 +0,0 @@
// |jit-test| error: TypeError
(eval("\
(function () {\
for (var[x] = function(){} in \
(function m(a) {\
if (a < 1) {\
x;\
return\
}\
return m(a - 1) + m(a - 2)\
})(7)\
(eval(\"\"))\
)\
([])\
})\
"))()

View File

@ -1,3 +0,0 @@
(function() {
for (var [e] = [] in (eval("for (b = 0; b < 6; ++b) gc()"))) {}
})()

View File

@ -3,7 +3,7 @@ function test() {
function f()
k.apply(this, arguments);
if (undefined >> undefined !== 0) {}
for (var [ v , c ] = 0 in this.tracemonkey) { }
for (var [ v , c ] in this.tracemonkey) { }
}
try { test(); } catch(exc1) {}
try { test(); } catch(exc1) {}

View File

@ -1,8 +0,0 @@
// |jit-test| error: TypeError
(function () {
var b = e
for (var [e] = b in w) c
})()
/* Don't assert. */

View File

@ -1,10 +0,0 @@
function test() {
try {
for (var i = 0 in this) throw p;
} catch (e) {
if (i !== 94)
return "what";
}
}
test();

View File

@ -253,8 +253,7 @@ MSG_DEF(JSMSG_GARBAGE_AFTER_INPUT, 2, JSEXN_SYNTAXERR, "unexpected garbage a
MSG_DEF(JSMSG_IDSTART_AFTER_NUMBER, 0, JSEXN_SYNTAXERR, "identifier starts immediately after numeric literal")
MSG_DEF(JSMSG_ILLEGAL_CHARACTER, 0, JSEXN_SYNTAXERR, "illegal character")
MSG_DEF(JSMSG_IMPORT_DECL_AT_TOP_LEVEL, 0, JSEXN_SYNTAXERR, "import declarations may only appear at top level")
MSG_DEF(JSMSG_INVALID_FOR_IN_INIT, 0, JSEXN_SYNTAXERR, "for-in loop let declaration may not have an initializer")
MSG_DEF(JSMSG_INVALID_FOR_OF_INIT, 0, JSEXN_SYNTAXERR, "for-of loop variable declaration may not have an initializer")
MSG_DEF(JSMSG_INVALID_FOR_INOF_DECL_WITH_INIT,1,JSEXN_SYNTAXERR,"for-{0} loop head declarations may not have initializers")
MSG_DEF(JSMSG_IN_AFTER_FOR_NAME, 0, JSEXN_SYNTAXERR, "missing 'in' or 'of' after for")
MSG_DEF(JSMSG_LABEL_NOT_FOUND, 0, JSEXN_SYNTAXERR, "label not found")
MSG_DEF(JSMSG_LET_CLASS_BINDING, 0, JSEXN_SYNTAXERR, "'let' is not a valid name for a class")

View File

@ -19,8 +19,8 @@ var dodis;
function f1(o){for(var x in o)printStatus(o[x]); return x}
function f2(o){with(this)for(var x in o)printStatus(o[x]); return x}
function f2novar(o){with(this)for(x in o)printStatus(o[x]); return x}
function f3(i,o){for(var x=i in o)printStatus(o[x]); return x}
function f4(i,o){with(this)for(var x=i in o)printStatus(o[x]); return x}
function f3(i,o){for(var x in o)printStatus(o[x]); return x}
function f4(i,o){with(this)for(var x in o)printStatus(o[x]); return x}
var t=0;
function assert(c)
@ -38,28 +38,31 @@ function assert(c)
reportCompare(expect, actual, summary);
}
assert(f1([]) == undefined);
assertEq(f1([]), undefined);
assert(f1(['first']) == 0);
assertEq(f1(['first']), "0");
assert(f2([]) == undefined);
assertEq(f2([]), undefined);
assert(f2(['first']) == 0);
assertEq(f2(['first']), "0");
assert(f3(42, []) == 42);
assertEq(f3(42, []), undefined);
assert(f3(42, ['first']) == 0);
assertEq(f3(42, ['first']), "0");
assert(f4(42, []) == 42);
assertEq(f4(42, []), undefined);
assert(f4(42, ['first']) == 0);
assertEq(f4(42, ['first']), "0");
this.x = 41;
assert(f2([]) == undefined);
assertEq(f2([]), undefined);
assert(f2novar([]) == 41);
assertEq(f2novar([]), 41);
assert(f2(['first']) == undefined);
assertEq(f2(['first']), undefined);
assert(f2novar(['first']) == 0);
assertEq(f2novar(['first']), "0");
if (typeof reportCompare === "function")
reportCompare(true, true);

View File

@ -15,7 +15,7 @@ printStatus (summary);
function SetLangHead(l){
with(p){
for(var i=0 in x)
for(var i in x)
if(getElementById("TxtH"+i)!=undefined)
printStatus('huh');
}

View File

@ -22,7 +22,7 @@ function test()
try
{
for (var {a: []} = 2 in []) { }
for (var {a: []} in []) { }
}
catch(ex)
{

View File

@ -22,7 +22,7 @@ function test()
try
{
for (var [,{y}] = 1 in []) {}
for (var [,{y}] in []) {}
}
catch(ex)
{

View File

@ -27,7 +27,7 @@ function test()
// Crash in NoteLValue, called from BindDestructuringVar.
// NoteLValue assumes pn->pn_lexdef is non-null, but here
// pn is itself the definition of x.
for (var [x]=[] in null) ;
for (var [x] in null) ;
// This one only crashes when executed from a file.
// Assertion failure: pn != dn->dn_uses, at ../jsparse.cpp:1131

View File

@ -52,7 +52,7 @@ function test()
//
try
{
for (var [x] = x in y) var x;
for (var [x] in y) var x;
}
catch(ex)
{

View File

@ -75,7 +75,7 @@ function test()
// Assertion failure: pnu->pn_lexdef == dn, at ../jsemit.cpp:1817
// =====
uneval(function(){for(var [arguments] = ({ get y(){} }) in y ) (x);});
uneval(function(){arguments = ({ get y(){} }); for(var [arguments] in y ) (x);});
// Assertion failure: n != 0, at ../jsfun.cpp:2689
// =====

View File

@ -35,7 +35,7 @@ function test()
// Assertion failure: !(pn->pn_dflags & flag), at ../jsparse.h:651
// =====
(function(){for(var x = arguments in []){} function x(){}})();
(function(){for(var x in [arguments]){} function x(){}})();
// Assertion failure: dn->pn_defn, at ../jsemit.cpp:1873
// =====

View File

@ -36,22 +36,6 @@ 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);
// destructuring in for-in and for-each-in loop heads with initializers
assertStmt("for (var {a:x,b:y,c:z} = 22 in foo);", forInStmt(varDecl([{ id: axbycz, init: lit(22) }]), ident("foo"), emptyStmt));
assertStmt("for (var [x,y,z] = 22 in foo);", forInStmt(varDecl([{ id: xyz, init: lit(22) }]), ident("foo"), emptyStmt));
assertStmt("for each (var {a:x,b:y,c:z} = 22 in foo);", forEachInStmt(varDecl([{ id: axbycz, init: lit(22) }]), ident("foo"), emptyStmt));
assertStmt("for each (var [x,y,z] = 22 in foo);", forEachInStmt(varDecl([{ id: xyz, init: lit(22) }]), ident("foo"), emptyStmt));
assertError("for (x = 22 in foo);", SyntaxError);
assertError("for ({a:x,b:y,c:z} = 22 in foo);", SyntaxError);
assertError("for ([x,y,z] = 22 in foo);", SyntaxError);
assertError("for (const x = 22 in foo);", SyntaxError);
assertError("for (const {a:x,b:y,c:z} = 22 in foo);", SyntaxError);
assertError("for (const [x,y,z] = 22 in foo);", SyntaxError);
assertError("for each (const x = 22 in foo);", SyntaxError);
assertError("for each (const {a:x,b:y,c:z} = 22 in foo);", SyntaxError);
assertError("for each (const [x,y,z] = 22 in foo);", SyntaxError);
}
runtest(test);

View File

@ -6,7 +6,7 @@
if (typeof evalcx == 'function') {
var src = 'try {\n' +
' for (var [e] = /x/ in d) {\n' +
' for (var [e] in d) {\n' +
' (function () {});\n' +
' }\n' +
'} catch (e) {}\n' +

View File

@ -2,7 +2,7 @@
// http://creativecommons.org/licenses/publicdomain/
with (0)
for (var b = 0 in 0) // don't assert in parser
for (var b in 0) // don't assert in parser
;
reportCompare(0, 0, 'ok');

View File

@ -29,11 +29,11 @@ namespace js {
*
* https://developer.mozilla.org/en-US/docs/SpiderMonkey/Internals/Bytecode
*/
static const uint32_t XDR_BYTECODE_VERSION_SUBTRAHEND = 276;
static const uint32_t XDR_BYTECODE_VERSION_SUBTRAHEND = 277;
static const uint32_t XDR_BYTECODE_VERSION =
uint32_t(0xb973c0de - XDR_BYTECODE_VERSION_SUBTRAHEND);
static_assert(JSErr_Limit == 395,
static_assert(JSErr_Limit == 394,
"GREETINGS, POTENTIAL SUBTRAHEND INCREMENTER! If you added or "
"removed MSG_DEFs from js.msg, you should increment "
"XDR_BYTECODE_VERSION_SUBTRAHEND and update this assertion's "