Skip to content

Commit

Permalink
PreParser scope analysis: simplify DeclareAndInitializeVariables.
Browse files Browse the repository at this point in the history
Now we have declarations too, so it doesn't matter whether preparser
produces the same unresolved variables as the parser.

BUG=v8:5501, v8:5516
R=verwaest@chromium.org

Review-Url: https://codereview.chromium.org/2623583004
Cr-Commit-Position: refs/heads/master@{#42174}
  • Loading branch information
marjakh authored and Commit bot committed Jan 10, 2017
1 parent ed43c63 commit 8f13532
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
16 changes: 1 addition & 15 deletions src/parsing/preparser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -297,26 +297,12 @@ void PreParser::DeclareAndInitializeVariables(
ZoneList<const AstRawString*>* names, bool* ok) {
if (declaration->pattern.variables_ != nullptr) {
DCHECK(FLAG_lazy_inner_functions);
/* Mimic what Parser does when declaring variables (see
Parser::PatternRewriter::VisitVariableProxy).
var + no initializer -> RemoveUnresolved
let / const + no initializer -> RemoveUnresolved
var + initializer -> RemoveUnresolved followed by NewUnresolved
let / const + initializer -> RemoveUnresolved
*/
Scope* scope = declaration_descriptor->hoist_scope;
if (scope == nullptr) {
scope = this->scope();
}
if (declaration->initializer.IsEmpty() ||
(declaration_descriptor->mode == VariableMode::LET ||
declaration_descriptor->mode == VariableMode::CONST)) {
for (auto variable : *(declaration->pattern.variables_)) {
declaration_descriptor->scope->RemoveUnresolved(variable);
}
}
for (auto variable : *(declaration->pattern.variables_)) {
declaration_descriptor->scope->RemoveUnresolved(variable);
scope->DeclareVariableName(variable->raw_name(),
declaration_descriptor->mode);
}
Expand Down
8 changes: 8 additions & 0 deletions test/cctest/test-parsing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8692,12 +8692,17 @@ TEST(NoPessimisticContextAllocation) {
{"function inner() { for (let {y, x: my_var} of []) { } my_var; }", true},
{"function inner() { for (let {a, my_var} in {}) { } my_var; }", true},
{"function inner() { for (let {a, my_var} of []) { } my_var; }", true},
{"function inner() { for (let my_var = 0; my_var < 1; ++my_var) { } "
"my_var }",
true},
// No pessimistic context allocation:
{"function inner() { var my_var; my_var; }", false},
{"function inner() { var my_var; }", false},
{"function inner() { var my_var = 0; }", false},
{"function inner() { if (true) { var my_var; } my_var; }", false},
{"function inner() { let my_var; my_var; }", false},
{"function inner() { let my_var; }", false},
{"function inner() { let my_var = 0; }", false},
{"function inner() { const my_var = 0; my_var; }", false},
{"function inner() { const my_var = 0; }", false},
{"function inner() { var [a, my_var] = [1, 2]; my_var; }", false},
Expand Down Expand Up @@ -8871,6 +8876,9 @@ TEST(NoPessimisticContextAllocation) {
{"function inner() { for (var my_var = 0; my_var < 1; ++my_var) { my_var "
"} }",
false},
{"function inner() { for (var my_var = 0; my_var < 1; ++my_var) { } "
"my_var }",
false},
{"function inner() { for (let a = 0, my_var = 0; my_var < 1; ++my_var) { "
"my_var } }",
false},
Expand Down

0 comments on commit 8f13532

Please sign in to comment.