| Index: src/parser.cc
|
| diff --git a/src/parser.cc b/src/parser.cc
|
| index 354f1c33187a33196be7b7db2813f089baa507b3..75d1cf93a23488d4a0f2b10507c303d15cd9ed25 100644
|
| --- a/src/parser.cc
|
| +++ b/src/parser.cc
|
| @@ -6,6 +6,7 @@
|
|
|
| #include "src/api.h"
|
| #include "src/ast.h"
|
| +#include "src/ast-expression-visitor.h"
|
| #include "src/ast-literal-reindexer.h"
|
| #include "src/bailout-reason.h"
|
| #include "src/base/platform/platform.h"
|
| @@ -920,6 +921,8 @@ Parser::Parser(ParseInfo* info)
|
| set_allow_harmony_rest_parameters(FLAG_harmony_rest_parameters);
|
| set_allow_harmony_default_parameters(FLAG_harmony_default_parameters);
|
| set_allow_harmony_destructuring_bind(FLAG_harmony_destructuring_bind);
|
| + set_allow_harmony_destructuring_assignment(
|
| + FLAG_harmony_destructuring_assignment);
|
| set_allow_strong_mode(FLAG_strong_mode);
|
| set_allow_legacy_const(FLAG_legacy_const);
|
| set_allow_harmony_do_expressions(FLAG_harmony_do_expressions);
|
| @@ -1090,6 +1093,7 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
|
| }
|
|
|
| if (ok) {
|
| + ParserTraits::RewriteDestructuringAssignments();
|
| result = factory()->NewFunctionLiteral(
|
| ast_value_factory()->empty_string(), ast_value_factory(), scope_,
|
| body, function_state.materialized_literal_count(),
|
| @@ -4404,6 +4408,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
|
| allow_harmony_destructuring_bind()) {
|
| CheckConflictingVarDeclarations(scope, CHECK_OK);
|
| }
|
| +
|
| + ParserTraits::RewriteDestructuringAssignments();
|
| }
|
|
|
| bool has_duplicate_parameters =
|
| @@ -4532,6 +4538,40 @@ Statement* Parser::BuildAssertIsCoercible(Variable* var) {
|
| }
|
|
|
|
|
| +class InitializerRewriter : public AstExpressionVisitor {
|
| + public:
|
| + InitializerRewriter(uintptr_t stack_limit, Expression* root, Parser* parser,
|
| + Scope* scope)
|
| + : AstExpressionVisitor(stack_limit, root),
|
| + parser_(parser),
|
| + scope_(scope) {}
|
| +
|
| + private:
|
| + void VisitExpression(Expression* expr) {
|
| + if (expr->IsAssignment()) {
|
| + Assignment* node = expr->AsAssignment();
|
| + if (node->op() == Token::ASSIGN && node->is_destructuring_assignment() &&
|
| + !node->destructuring_assignment()) {
|
| + bool ok = true;
|
| + Parser::PatternRewriter::RewriteDestructuringAssignment(parser_, node,
|
| + scope_, &ok);
|
| + DCHECK(ok);
|
| + }
|
| + }
|
| + }
|
| +
|
| + private:
|
| + Parser* parser_;
|
| + Scope* scope_;
|
| +};
|
| +
|
| +
|
| +void Parser::RewriteParameterInitializer(Expression* expr, Scope* scope) {
|
| + InitializerRewriter rewriter(stack_limit_, expr, this, scope);
|
| + rewriter.Run();
|
| +}
|
| +
|
| +
|
| Block* Parser::BuildParameterInitializationBlock(
|
| const ParserFormalParameters& parameters, bool* ok) {
|
| DCHECK(!parameters.is_simple);
|
| @@ -4556,6 +4596,10 @@ Block* Parser::BuildParameterInitializationBlock(
|
| if (parameter.initializer != nullptr) {
|
| // IS_UNDEFINED($param) ? initializer : $param
|
| DCHECK(!parameter.is_rest);
|
| +
|
| + // Ensure initializer is rewritten
|
| + RewriteParameterInitializer(parameter.initializer, scope_);
|
| +
|
| auto condition = factory()->NewCompareOperation(
|
| Token::EQ_STRICT,
|
| factory()->NewVariableProxy(parameters.scope->parameter(i)),
|
|
|