Bug 790247 - Reflect.parse should treat x["y"] as a computed MemberExpression. r=jorendorff.

This commit is contained in:
Yusuke Suzuki 2012-09-12 10:27:09 -05:00
parent 11a62b651b
commit f6de4fab9b
2 changed files with 20 additions and 16 deletions

View File

@ -5664,22 +5664,24 @@ Parser::memberExpr(bool allowCallSyntax)
*/
uint32_t index;
PropertyName *name = NULL;
if (propExpr->isKind(PNK_STRING)) {
JSAtom *atom = propExpr->pn_atom;
if (atom->isIndex(&index)) {
propExpr->setKind(PNK_NUMBER);
propExpr->setOp(JSOP_DOUBLE);
propExpr->pn_dval = index;
} else {
name = atom->asPropertyName();
}
} else if (propExpr->isKind(PNK_NUMBER)) {
double number = propExpr->pn_dval;
if (number != ToUint32(number)) {
JSAtom *atom = ToAtom(context, DoubleValue(number));
if (!atom)
return NULL;
name = atom->asPropertyName();
if (foldConstants) {
if (propExpr->isKind(PNK_STRING)) {
JSAtom *atom = propExpr->pn_atom;
if (atom->isIndex(&index)) {
propExpr->setKind(PNK_NUMBER);
propExpr->setOp(JSOP_DOUBLE);
propExpr->pn_dval = index;
} else {
name = atom->asPropertyName();
}
} else if (propExpr->isKind(PNK_NUMBER)) {
double number = propExpr->pn_dval;
if (number != ToUint32(number)) {
JSAtom *atom = ToAtom(context, DoubleValue(number));
if (!atom)
return NULL;
name = atom->asPropertyName();
}
}
}

View File

@ -261,6 +261,8 @@ assertExpr("this", thisExpr);
assertExpr("foo", ident("foo"));
assertExpr("foo.bar", dotExpr(ident("foo"), ident("bar")));
assertExpr("foo[bar]", memExpr(ident("foo"), ident("bar")));
assertExpr("foo['bar']", memExpr(ident("foo"), lit("bar")));
assertExpr("foo[42]", memExpr(ident("foo"), lit(42)));
assertExpr("(function(){})", funExpr(null, [], blockStmt([])));
assertExpr("(function f() {})", funExpr(ident("f"), [], blockStmt([])));
assertExpr("(function f(x,y,z) {})", funExpr(ident("f"), [ident("x"),ident("y"),ident("z")], blockStmt([])));