Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(829)

Unified Diff: src/parser.cc

Issue 1468143004: [es6] Self-assignment in a default parameter initializer should throw (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Change less behavior, add TODO Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index 354f1c33187a33196be7b7db2813f089baa507b3..6497833d14869269ac8e0930496fec2fc5b0ae03 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -4088,7 +4088,11 @@ void ParserTraits::ParseArrowFunctionFormalParameters(
parser_->scope_, parameters->scope);
}
- AddFormalParameter(parameters, expr, initializer, is_rest);
+ // TODO(adamk): params_loc.end_pos is not the correct initializer position,
+ // but it should be conservative enough to trigger hole checks for variables
+ // referenced in the initializer (if any).
+ AddFormalParameter(parameters, expr, initializer, params_loc.end_pos,
+ is_rest);
}
@@ -4550,7 +4554,15 @@ Block* Parser::BuildParameterInitializationBlock(
descriptor.is_const = false;
descriptor.needs_init = true;
descriptor.declaration_pos = parameter.pattern->position();
+ // The position that will be used by the AssignmentExpression
+ // which copies from the temp parameter to the pattern.
+ //
+ // TODO(adamk): Should this be RelocInfo::kNoPosition, since
+ // it's just copying from a temp var to the real param var?
descriptor.initialization_pos = parameter.pattern->position();
+ // The initializer position which will end up in,
+ // Variable::initializer_position(), used for hole check elimination.
+ int initializer_position = parameter.pattern->position();
Expression* initial_value =
factory()->NewVariableProxy(parameters.scope->parameter(i));
if (parameter.initializer != nullptr) {
@@ -4565,6 +4577,7 @@ Block* Parser::BuildParameterInitializationBlock(
condition, parameter.initializer, initial_value,
RelocInfo::kNoPosition);
descriptor.initialization_pos = parameter.initializer->position();
+ initializer_position = parameter.initializer_end_position;
} else if (parameter.is_rest) {
// $rest = [];
// for (var $argument_index = $rest_index;
@@ -4576,7 +4589,6 @@ Block* Parser::BuildParameterInitializationBlock(
DCHECK(parameter.pattern->IsVariableProxy());
DCHECK_EQ(i, parameters.params.length() - 1);
- int pos = parameter.pattern->position();
Variable* temp_var = parameters.scope->parameter(i);
auto empty_values = new (zone()) ZoneList<Expression*>(0, zone());
auto empty_array = factory()->NewArrayLiteral(
@@ -4640,8 +4652,6 @@ Block* Parser::BuildParameterInitializationBlock(
zone());
init_block->statements()->Add(loop, zone());
-
- descriptor.initialization_pos = pos;
}
Scope* param_scope = scope_;
@@ -4660,7 +4670,7 @@ Block* Parser::BuildParameterInitializationBlock(
{
BlockState block_state(&scope_, param_scope);
DeclarationParsingResult::Declaration decl(
- parameter.pattern, parameter.pattern->position(), initial_value);
+ parameter.pattern, initializer_position, initial_value);
PatternRewriter::DeclareAndInitializeVariables(param_block, &descriptor,
&decl, nullptr, CHECK_OK);
}
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698