Bug 875002 - add shorthand flag to ObjectPattern in Reflect.parse;r=jorendorff

--HG--
extra : rebase_source : 5cba8a50b7937c4979dcbadf273634b63ddb2185
extra : amend_source : 8f793b4309941c49de697cb71105ae6369a27986
This commit is contained in:
Arpad Borsos 2014-06-30 14:12:28 +02:00
parent 9dda5f5b76
commit 4b03564d79
2 changed files with 11 additions and 4 deletions

View File

@ -665,7 +665,8 @@ class NodeBuilder
bool objectPattern(NodeVector &elts, TokenPos *pos, MutableHandleValue dst);
bool propertyPattern(HandleValue key, HandleValue patt, TokenPos *pos, MutableHandleValue dst);
bool propertyPattern(HandleValue key, HandleValue patt, bool isShorthand, TokenPos *pos,
MutableHandleValue dst);
};
} /* anonymous namespace */
@ -1227,13 +1228,15 @@ NodeBuilder::spreadExpression(HandleValue expr, TokenPos *pos, MutableHandleValu
}
bool
NodeBuilder::propertyPattern(HandleValue key, HandleValue patt, TokenPos *pos,
NodeBuilder::propertyPattern(HandleValue key, HandleValue patt, bool isShorthand, TokenPos *pos,
MutableHandleValue dst)
{
RootedValue kindName(cx);
if (!atomValue("init", &kindName))
return false;
RootedValue isShorthandVal(cx, BooleanValue(isShorthand));
RootedValue cb(cx, callbacks[AST_PROP_PATT]);
if (!cb.isNull())
return callback(cb, key, patt, pos, dst);
@ -1242,6 +1245,7 @@ NodeBuilder::propertyPattern(HandleValue key, HandleValue patt, TokenPos *pos,
"key", key,
"value", patt,
"kind", kindName,
"shorthand", isShorthandVal,
dst);
}
@ -3015,7 +3019,8 @@ ASTSerializer::objectPattern(ParseNode *pn, VarDeclKind *pkind, MutableHandleVal
RootedValue key(cx), patt(cx), prop(cx);
if (!propertyName(next->pn_left, &key) ||
!pattern(next->pn_right, pkind, &patt) ||
!builder.propertyPattern(key, patt, &next->pn_pos, &prop)) {
!builder.propertyPattern(key, patt, next->isKind(PNK_SHORTHAND), &next->pn_pos,
&prop)) {
return false;
}

View File

@ -488,8 +488,10 @@ assertStmt("function f() { var x = 42; var x = 43; }",
varDecl([{ id: ident("x"), init: lit(43) }])])));
assertDecl("var {x:y} = foo;", varDecl([{ id: objPatt([{ key: ident("x"), value: ident("y") }]),
assertDecl("var {x:y} = foo;", varDecl([{ id: objPatt([{ key: ident("x"), value: ident("y"), shorthand: false }]),
init: ident("foo") }]));
assertDecl("var {x} = foo;", varDecl([{ id: objPatt([{ key: ident("x"), value: ident("x"), shorthand: true }]),
init: ident("foo") }]));
// Bug 632030: redeclarations between var and funargs, var and function
assertStmt("function g(x) { var x }",