Avoid multiple rewriting of object key expressions

NonPatternRewrite was called more than once for the same AST
in the case of (computed) key expressions present in object
literals.  As an example, in:

   var x = { [[...42]]: 17 };

the array containing the spread would be desugared first and
then the resulting do-expression would again be desugared.

This could be problematic if a computed key expression contains
large nested array/object literals.

R=rossberg@chromium.org
BUG=

Review URL: https://codereview.chromium.org/1645023002

Cr-Commit-Position: refs/heads/master@{#33632}
This commit is contained in:
nikolaos 2016-02-01 01:18:09 -08:00 committed by Commit bot
parent a17bd3f3bc
commit 077d70f0fe

View File

@ -5561,6 +5561,12 @@ class NonPatternRewriter : public AstExpressionRewriter {
return false;
}
void VisitObjectLiteralProperty(ObjectLiteralProperty* property) override {
if (property == nullptr) return;
// Do not rewrite (computed) key expressions
AST_REWRITE_PROPERTY(Expression, property, value);
}
Parser* parser_;
};
@ -5581,8 +5587,7 @@ ObjectLiteralProperty* Parser::RewriteNonPatternObjectLiteralProperty(
ObjectLiteralProperty* property, const ExpressionClassifier* classifier,
bool* ok) {
if (property != nullptr) {
Expression* key = RewriteNonPattern(property->key(), classifier, ok);
property->set_key(key);
// Do not rewrite (computed) key expressions
Expression* value = RewriteNonPattern(property->value(), classifier, ok);
property->set_value(value);
}