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

Side by Side Diff: src/parsing/parser.cc

Issue 2112163002: Block-scoped functions in evals are now only conditionally hoisted out. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 5 months 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/parsing/parser.h" 5 #include "src/parsing/parser.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/ast/ast-expression-rewriter.h" 9 #include "src/ast/ast-expression-rewriter.h"
10 #include "src/ast/ast-expression-visitor.h" 10 #include "src/ast/ast-expression-visitor.h"
(...skipping 5116 matching lines...) Expand 10 before | Expand all | Expand 10 after
5127 continue; 5127 continue;
5128 } 5128 }
5129 } 5129 }
5130 5130
5131 bool var_created = false; 5131 bool var_created = false;
5132 5132
5133 // Write in assignments to var for each block-scoped function declaration 5133 // Write in assignments to var for each block-scoped function declaration
5134 auto delegates = static_cast<SloppyBlockFunctionMap::Vector*>(p->value); 5134 auto delegates = static_cast<SloppyBlockFunctionMap::Vector*>(p->value);
5135 for (SloppyBlockFunctionStatement* delegate : *delegates) { 5135 for (SloppyBlockFunctionStatement* delegate : *delegates) {
5136 // Check if there's a conflict with a lexical declaration 5136 // Check if there's a conflict with a lexical declaration
5137 Scope* outer_scope = scope->outer_scope(); 5137 Scope* decl_scope = scope;
5138 while (decl_scope->is_eval_scope()) {
5139 decl_scope = decl_scope->outer_scope()->DeclarationScope();
5140 }
5141 Scope* outer_scope = decl_scope->outer_scope();
5138 Scope* query_scope = delegate->scope()->outer_scope(); 5142 Scope* query_scope = delegate->scope()->outer_scope();
5139 Variable* var = nullptr; 5143 Variable* var = nullptr;
5140 bool should_hoist = true; 5144 bool should_hoist = true;
5141 5145
5142 // Note that we perform this loop for each delegate named 'name', 5146 // Note that we perform this loop for each delegate named 'name',
5143 // which may duplicate work if those delegates share scopes. 5147 // which may duplicate work if those delegates share scopes.
5144 // It is not sufficient to just do a Lookup on query_scope: for 5148 // It is not sufficient to just do a Lookup on query_scope: for
5145 // example, that does not prevent hoisting of the function in 5149 // example, that does not prevent hoisting of the function in
5146 // `{ let e; try {} catch (e) { function e(){} } }` 5150 // `{ let e; try {} catch (e) { function e(){} } }`
5147 do { 5151 do {
(...skipping 1870 matching lines...) Expand 10 before | Expand all | Expand 10 after
7018 try_block, target); 7022 try_block, target);
7019 final_loop = target; 7023 final_loop = target;
7020 } 7024 }
7021 7025
7022 return final_loop; 7026 return final_loop;
7023 } 7027 }
7024 7028
7025 7029
7026 } // namespace internal 7030 } // namespace internal
7027 } // namespace v8 7031 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/es6/block-eval-var-over-let.js » ('j') | test/mjsunit/es6/block-sloppy-function.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698