Reflect.parse("[,,,]") should make an ArrayExpression with .elements.length 3. Bug 630232, r=dherman.

This commit is contained in:
Jason Orendorff 2012-03-01 09:01:45 -06:00
parent d52fe19668
commit 2642e75e1e
3 changed files with 17 additions and 9 deletions

View File

@ -639,11 +639,15 @@ NodeBuilder::newNode(ASTType type, TokenPos *pos, JSObject **dst)
bool
NodeBuilder::newArray(NodeVector &elts, Value *dst)
{
JSObject *array = NewDenseEmptyArray(cx);
const size_t len = elts.length();
if (len > UINT32_MAX) {
js_ReportAllocationOverflow(cx);
return false;
}
JSObject *array = NewDenseAllocatedArray(cx, uint32_t(len));
if (!array)
return false;
const size_t len = elts.length();
for (size_t i = 0; i < len; i++) {
Value val = elts[i];

View File

@ -312,10 +312,10 @@ assertExpr("[1,,,2,,,3]", arrExpr([lit(1),,,lit(2),,,lit(3)]));
assertExpr("[,1,2,3]", arrExpr([,lit(1),lit(2),lit(3)]));
assertExpr("[,,1,2,3]", arrExpr([,,lit(1),lit(2),lit(3)]));
assertExpr("[,,,1,2,3]", arrExpr([,,,lit(1),lit(2),lit(3)]));
assertExpr("[,,,1,2,3,]", arrExpr([,,,lit(1),lit(2),lit(3)]));
assertExpr("[,,,1,2,3,,]", arrExpr([,,,lit(1),lit(2),lit(3),]));
assertExpr("[,,,1,2,3,,,]", arrExpr([,,,lit(1),lit(2),lit(3),,]));
assertExpr("[,,,,,]", arrExpr([,,,,]));
assertExpr("[,,,1,2,3,]", arrExpr([,,,lit(1),lit(2),lit(3),]));
assertExpr("[,,,1,2,3,,]", arrExpr([,,,lit(1),lit(2),lit(3),,]));
assertExpr("[,,,1,2,3,,,]", arrExpr([,,,lit(1),lit(2),lit(3),,,]));
assertExpr("[,,,,,]", arrExpr([,,,,,]));
assertExpr("({})", objExpr([]));
assertExpr("({x:1})", objExpr([{ key: ident("x"), value: lit(1) }]));
assertExpr("({x:1, y:2})", objExpr([{ key: ident("x"), value: lit(1) },
@ -436,9 +436,10 @@ assertStmt("function f() { function g() { } function g() { } }",
funDecl(ident("f"), [], blockStmt([funDecl(ident("g"), [], blockStmt([])),
funDecl(ident("g"), [], blockStmt([]))])));
assertStmt("function f() { function g() { } function g() { return 42 } }",
funDecl(ident("f"), [], blockStmt([funDecl(ident("g"), [], blockStmt([])),
funDecl(ident("g"), [], blockStmt([returnStmt(lit(42))]))])));
// Fails due to parser quirks (bug 638577)
//assertStmt("function f() { function g() { } function g() { return 42 } }",
// funDecl(ident("f"), [], blockStmt([funDecl(ident("g"), [], blockStmt([])),
// funDecl(ident("g"), [], blockStmt([returnStmt(lit(42))]))])));
assertStmt("function f() { var x = 42; var x = 43; }",
funDecl(ident("f"), [], blockStmt([varDecl([{ id: ident("x"), init: lit(42) }]),

View File

@ -139,6 +139,9 @@ var Match =
throw new MatchError("expected array-like object, got " + quote(act));
var length = exp.length;
if (act.length !== exp.length)
throw new MatchError("expected array-like object of length " + length + ", got " + quote(act));
for (var i = 0; i < length; i++) {
if (i in exp) {
if (!(i in act))