mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 648526 - Constant folding in array and object literals. r=bhackett
This commit is contained in:
parent
949d0ed298
commit
6446af5eb2
@ -6759,8 +6759,12 @@ Parser::primaryExpr(TokenKind tt, bool afterDoubleDot)
|
||||
pn->pn_xflags |= PNX_HOLEY | PNX_NONCONST;
|
||||
} else {
|
||||
pn2 = assignExpr();
|
||||
if (pn2 && !pn2->isConstant())
|
||||
pn->pn_xflags |= PNX_NONCONST;
|
||||
if (pn2) {
|
||||
if (foldConstants && !FoldConstants(context, pn2, tc))
|
||||
return NULL;
|
||||
if (!pn2->isConstant())
|
||||
pn->pn_xflags |= PNX_NONCONST;
|
||||
}
|
||||
}
|
||||
if (!pn2)
|
||||
return NULL;
|
||||
@ -6975,6 +6979,9 @@ Parser::primaryExpr(TokenKind tt, bool afterDoubleDot)
|
||||
if (!pnval)
|
||||
return NULL;
|
||||
|
||||
if (foldConstants && !FoldConstants(context, pnval, tc))
|
||||
return NULL;
|
||||
|
||||
/*
|
||||
* Treat initializers which mutate __proto__ as non-constant,
|
||||
* so that we can later assume singleton objects delegate to
|
||||
|
@ -29,3 +29,31 @@ assertEq(q[4294967295], 2);
|
||||
try {
|
||||
[1,2,3,{a:0,b:1}].foo.bar;
|
||||
} catch (e) { assertEq(e.message, "[1, 2, 3, {a:0, b:1}].foo is undefined"); }
|
||||
|
||||
var a = [1 + 1, 3 * 2, 6 - 5, 14 % 6, 15 / 5, 1 << 3,
|
||||
8 >> 2, 5 | 2, 5 ^ 3, ~3, -3,"a" + "b", !true, !false];
|
||||
assertEq(String(a), "2,6,1,2,3,8,2,7,6,-4,-3,ab,false,true");
|
||||
assertEq(a.length, 14);
|
||||
|
||||
var b = {
|
||||
a: 1 + 1,
|
||||
b: 3 * 2,
|
||||
c: 6 - 5,
|
||||
d: 14 % 6,
|
||||
e: 15 / 5,
|
||||
f: 1 << 3,
|
||||
g: 8 >> 2,
|
||||
h: 5 | 2,
|
||||
i: 5 ^ 3,
|
||||
j: ~3,
|
||||
k: -3,
|
||||
l: "a" + "b",
|
||||
m: !true,
|
||||
n: !false,
|
||||
}
|
||||
|
||||
var char = "a".charCodeAt(0);
|
||||
for (var i = 0; i < a.length; i++) {
|
||||
assertEq(b[String.fromCharCode(char)], a[i]);
|
||||
char++;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user