PreParser scope analysis: simplify DeclareAndInitializeVariables.
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}
This commit is contained in:
parent
ed43c63e26
commit
8f1353256f
@ -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);
|
||||
}
|
||||
|
@ -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},
|
||||
@ -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},
|
||||
|
Loading…
Reference in New Issue
Block a user