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

Side by Side Diff: src/ast/scopes.cc

Issue 2380993003: Readd default function variables upon scope reset for preparse abort (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « src/ast/scopes.h ('k') | src/parsing/parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/ast/scopes.h" 5 #include "src/ast/scopes.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "src/accessors.h" 9 #include "src/accessors.h"
10 #include "src/ast/ast.h" 10 #include "src/ast/ast.h"
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 // redeclaration. See ES#sec-functiondeclarationinstantiation, step 20. 599 // redeclaration. See ES#sec-functiondeclarationinstantiation, step 20.
600 arguments_ = nullptr; 600 arguments_ = nullptr;
601 } 601 }
602 } 602 }
603 603
604 void DeclarationScope::DeclareDefaultFunctionVariables( 604 void DeclarationScope::DeclareDefaultFunctionVariables(
605 AstValueFactory* ast_value_factory) { 605 AstValueFactory* ast_value_factory) {
606 DCHECK(is_function_scope()); 606 DCHECK(is_function_scope());
607 DCHECK(!is_arrow_scope()); 607 DCHECK(!is_arrow_scope());
608 608
609 DeclareThis(ast_value_factory);
609 new_target_ = Declare(zone(), this, ast_value_factory->new_target_string(), 610 new_target_ = Declare(zone(), this, ast_value_factory->new_target_string(),
610 CONST, NORMAL_VARIABLE, kCreatedInitialized); 611 CONST, NORMAL_VARIABLE, kCreatedInitialized);
611 612
612 if (IsConciseMethod(function_kind_) || IsClassConstructor(function_kind_) || 613 if (IsConciseMethod(function_kind_) || IsClassConstructor(function_kind_) ||
613 IsAccessorFunction(function_kind_)) { 614 IsAccessorFunction(function_kind_)) {
614 this_function_ = 615 this_function_ =
615 Declare(zone(), this, ast_value_factory->this_function_string(), CONST, 616 Declare(zone(), this, ast_value_factory->this_function_string(), CONST,
616 NORMAL_VARIABLE, kCreatedInitialized); 617 NORMAL_VARIABLE, kCreatedInitialized);
617 } 618 }
618 } 619 }
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 Handle<StringSet> DeclarationScope::CollectNonLocals( 1182 Handle<StringSet> DeclarationScope::CollectNonLocals(
1182 ParseInfo* info, Handle<StringSet> non_locals) { 1183 ParseInfo* info, Handle<StringSet> non_locals) {
1183 VariableProxy* free_variables = FetchFreeVariables(this, true, info); 1184 VariableProxy* free_variables = FetchFreeVariables(this, true, info);
1184 for (VariableProxy* proxy = free_variables; proxy != nullptr; 1185 for (VariableProxy* proxy = free_variables; proxy != nullptr;
1185 proxy = proxy->next_unresolved()) { 1186 proxy = proxy->next_unresolved()) {
1186 non_locals = StringSet::Add(non_locals, proxy->name()); 1187 non_locals = StringSet::Add(non_locals, proxy->name());
1187 } 1188 }
1188 return non_locals; 1189 return non_locals;
1189 } 1190 }
1190 1191
1191 void DeclarationScope::ResetAfterPreparsing(bool aborted) { 1192 void DeclarationScope::ResetAfterPreparsing(AstValueFactory* ast_value_factory,
1193 bool aborted) {
1194 DCHECK(is_function_scope());
1195
1192 // Reset all non-trivial members. 1196 // Reset all non-trivial members.
1193 decls_.Clear(); 1197 decls_.Clear();
1194 locals_.Clear(); 1198 locals_.Clear();
1195 sloppy_block_function_map_.Clear(); 1199 sloppy_block_function_map_.Clear();
1196 variables_.Clear(); 1200 variables_.Clear();
1197 // Make sure we won't walk the scope tree from here on. 1201 // Make sure we won't walk the scope tree from here on.
1198 inner_scope_ = nullptr; 1202 inner_scope_ = nullptr;
1199 unresolved_ = nullptr; 1203 unresolved_ = nullptr;
1200 1204
1201 // TODO(verwaest): We should properly preparse the parameters (no declarations 1205 // TODO(verwaest): We should properly preparse the parameters (no declarations
1202 // should be created), and reparse on abort. 1206 // should be created), and reparse on abort.
1203 if (aborted) { 1207 if (aborted) {
1208 if (!IsArrowFunction(function_kind_)) {
1209 DeclareDefaultFunctionVariables(ast_value_factory);
1210 }
1204 // Recreate declarations for parameters. 1211 // Recreate declarations for parameters.
1205 for (int i = 0; i < params_.length(); i++) { 1212 for (int i = 0; i < params_.length(); i++) {
1206 Variable* var = params_[i]; 1213 Variable* var = params_[i];
1207 if (var->mode() == TEMPORARY) { 1214 if (var->mode() == TEMPORARY) {
1208 locals_.Add(var, zone()); 1215 locals_.Add(var, zone());
1209 } else if (variables_.Lookup(var->raw_name()) == nullptr) { 1216 } else if (variables_.Lookup(var->raw_name()) == nullptr) {
1210 variables_.Add(zone(), var); 1217 variables_.Add(zone(), var);
1211 locals_.Add(var, zone()); 1218 locals_.Add(var, zone());
1212 } 1219 }
1213 } 1220 }
(...skipping 25 matching lines...) Expand all
1239 unresolved = copy; 1246 unresolved = copy;
1240 } 1247 }
1241 1248
1242 // Clear arguments_ if unused. This is used as a signal for optimization. 1249 // Clear arguments_ if unused. This is used as a signal for optimization.
1243 if (arguments_ != nullptr && 1250 if (arguments_ != nullptr &&
1244 !(MustAllocate(arguments_) && !has_arguments_parameter_)) { 1251 !(MustAllocate(arguments_) && !has_arguments_parameter_)) {
1245 arguments_ = nullptr; 1252 arguments_ = nullptr;
1246 } 1253 }
1247 } 1254 }
1248 1255
1249 ResetAfterPreparsing(false); 1256 ResetAfterPreparsing(ast_node_factory->ast_value_factory(), false);
1250 1257
1251 unresolved_ = unresolved; 1258 unresolved_ = unresolved;
1252 } 1259 }
1253 1260
1254 #ifdef DEBUG 1261 #ifdef DEBUG
1255 static const char* Header(ScopeType scope_type, FunctionKind function_kind, 1262 static const char* Header(ScopeType scope_type, FunctionKind function_kind,
1256 bool is_declaration_scope) { 1263 bool is_declaration_scope) {
1257 switch (scope_type) { 1264 switch (scope_type) {
1258 case EVAL_SCOPE: return "eval"; 1265 case EVAL_SCOPE: return "eval";
1259 // TODO(adamk): Should we print concise method scopes specially? 1266 // TODO(adamk): Should we print concise method scopes specially?
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
1894 Variable* function = 1901 Variable* function =
1895 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; 1902 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr;
1896 bool is_function_var_in_context = 1903 bool is_function_var_in_context =
1897 function != nullptr && function->IsContextSlot(); 1904 function != nullptr && function->IsContextSlot();
1898 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 1905 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
1899 (is_function_var_in_context ? 1 : 0); 1906 (is_function_var_in_context ? 1 : 0);
1900 } 1907 }
1901 1908
1902 } // namespace internal 1909 } // namespace internal
1903 } // namespace v8 1910 } // namespace v8
OLDNEW
« no previous file with comments | « src/ast/scopes.h ('k') | src/parsing/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698