Skip to content

Commit 3c39bac

Browse files
ajkleinCommit bot
authored andcommitted
Don't skip hole checks inside patterns in parameter lists
Previously, b6e9f62 fixed self-assignment in parameters to throw. But it failed to deal with the case of destructuring with defaults. This patch extends that previous approach to always treat the end of a parameter as its initializer position, whether it has an initializer or not. This is the minimal change to make it easy to merge; a follow-up will rename the field of Parameter from "initializer_end_position" to "end_position". BUG=v8:5454 Review-Url: https://codereview.chromium.org/2390943002 Cr-Commit-Position: refs/heads/master@{#39962}
1 parent 99cfa5f commit 3c39bac

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/parsing/parser.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2939,9 +2939,6 @@ Block* Parser::BuildParameterInitializationBlock(
29392939
// TODO(adamk): Should this be kNoSourcePosition, since
29402940
// it's just copying from a temp var to the real param var?
29412941
descriptor.initialization_pos = parameter.pattern->position();
2942-
// The initializer position which will end up in,
2943-
// Variable::initializer_position(), used for hole check elimination.
2944-
int initializer_position = parameter.pattern->position();
29452942
Expression* initial_value =
29462943
factory()->NewVariableProxy(parameters.scope->parameter(i));
29472944
if (parameter.initializer != nullptr) {
@@ -2957,7 +2954,6 @@ Block* Parser::BuildParameterInitializationBlock(
29572954
initial_value = factory()->NewConditional(
29582955
condition, parameter.initializer, initial_value, kNoSourcePosition);
29592956
descriptor.initialization_pos = parameter.initializer->position();
2960-
initializer_position = parameter.initializer_end_position;
29612957
}
29622958

29632959
Scope* param_scope = scope();
@@ -2980,7 +2976,7 @@ Block* Parser::BuildParameterInitializationBlock(
29802976

29812977
BlockState block_state(&scope_state_, param_scope);
29822978
DeclarationParsingResult::Declaration decl(
2983-
parameter.pattern, initializer_position, initial_value);
2979+
parameter.pattern, parameter.initializer_end_position, initial_value);
29842980
PatternRewriter::DeclareAndInitializeVariables(
29852981
this, param_block, &descriptor, &decl, nullptr, CHECK_OK);
29862982

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2016 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
assertThrows(function(...[b = !b]) { }, ReferenceError);
6+
assertThrows(() => (function([b = !b]) { })([]), ReferenceError);
7+
assertThrows(() => (function({b = !b}) { })({}), ReferenceError);
8+
9+
assertThrows((...[b = !b]) => { }, ReferenceError);
10+
assertThrows(() => (([b = !b]) => { })([]), ReferenceError);
11+
assertThrows(() => (({b = !b}) => { })({}), ReferenceError);

0 commit comments

Comments
 (0)