From 077d70f0fe594151f7b28ea0c81aa0dfa3af8d52 Mon Sep 17 00:00:00 2001 From: nikolaos Date: Mon, 1 Feb 2016 01:18:09 -0800 Subject: [PATCH] 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} --- src/parsing/parser.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc index 1b5b7e6779..009f36d136 100644 --- a/src/parsing/parser.cc +++ b/src/parsing/parser.cc @@ -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); }