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

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

Issue 2302013002: Store the scope info in catch contexts (Closed)
Patch Set: updates Created 4 years, 3 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/compiler/access-builder.h » ('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/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 DeclarationScope::DeclarationScope(Zone* zone, ScopeType scope_type, 216 DeclarationScope::DeclarationScope(Zone* zone, ScopeType scope_type,
217 Handle<ScopeInfo> scope_info) 217 Handle<ScopeInfo> scope_info)
218 : Scope(zone, scope_type, scope_info), 218 : Scope(zone, scope_type, scope_info),
219 function_kind_(scope_info->function_kind()), 219 function_kind_(scope_info->function_kind()),
220 params_(0, zone), 220 params_(0, zone),
221 sloppy_block_function_map_(zone) { 221 sloppy_block_function_map_(zone) {
222 DCHECK_NE(scope_type, SCRIPT_SCOPE); 222 DCHECK_NE(scope_type, SCRIPT_SCOPE);
223 SetDefaults(); 223 SetDefaults();
224 } 224 }
225 225
226 Scope::Scope(Zone* zone, const AstRawString* catch_variable_name) 226 Scope::Scope(Zone* zone, const AstRawString* catch_variable_name,
227 Handle<ScopeInfo> scope_info)
227 : zone_(zone), 228 : zone_(zone),
228 outer_scope_(nullptr), 229 outer_scope_(nullptr),
229 variables_(zone), 230 variables_(zone),
230 locals_(0, zone), 231 locals_(0, zone),
231 decls_(0, zone), 232 decls_(0, zone),
233 scope_info_(scope_info),
232 scope_type_(CATCH_SCOPE) { 234 scope_type_(CATCH_SCOPE) {
233 SetDefaults(); 235 SetDefaults();
234 #ifdef DEBUG 236 #ifdef DEBUG
235 already_resolved_ = true; 237 already_resolved_ = true;
236 #endif 238 #endif
239 // Cache the catch variable, even though it's also available via the
240 // scope_info, as the parser expects that a catch scope always has the catch
241 // variable as first and only variable.
237 Variable* variable = Declare(zone, this, catch_variable_name, VAR, 242 Variable* variable = Declare(zone, this, catch_variable_name, VAR,
238 Variable::NORMAL, kCreatedInitialized); 243 Variable::NORMAL, kCreatedInitialized);
239 AllocateHeapSlot(variable); 244 AllocateHeapSlot(variable);
240 } 245 }
241 246
242 void DeclarationScope::SetDefaults() { 247 void DeclarationScope::SetDefaults() {
243 is_declaration_scope_ = true; 248 is_declaration_scope_ = true;
244 has_simple_parameters_ = true; 249 has_simple_parameters_ = true;
245 asm_module_ = false; 250 asm_module_ = false;
246 asm_function_ = false; 251 asm_function_ = false;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 } 365 }
361 } else if (context->IsModuleContext()) { 366 } else if (context->IsModuleContext()) {
362 ScopeInfo* scope_info = context->closure()->shared()->scope_info(); 367 ScopeInfo* scope_info = context->closure()->shared()->scope_info();
363 DCHECK_EQ(scope_info->scope_type(), MODULE_SCOPE); 368 DCHECK_EQ(scope_info->scope_type(), MODULE_SCOPE);
364 outer_scope = new (zone) ModuleScope( 369 outer_scope = new (zone) ModuleScope(
365 isolate, Handle<ScopeInfo>(scope_info), ast_value_factory); 370 isolate, Handle<ScopeInfo>(scope_info), ast_value_factory);
366 } else { 371 } else {
367 DCHECK(context->IsCatchContext()); 372 DCHECK(context->IsCatchContext());
368 String* name = context->catch_name(); 373 String* name = context->catch_name();
369 outer_scope = new (zone) 374 outer_scope = new (zone)
370 Scope(zone, ast_value_factory->GetString(handle(name, isolate))); 375 Scope(zone, ast_value_factory->GetString(handle(name, isolate)),
376 Handle<ScopeInfo>(context->scope_info()));
371 } 377 }
372 if (current_scope != nullptr) { 378 if (current_scope != nullptr) {
373 outer_scope->AddInnerScope(current_scope); 379 outer_scope->AddInnerScope(current_scope);
374 } 380 }
375 current_scope = outer_scope; 381 current_scope = outer_scope;
376 if (deserialization_mode == DeserializationMode::kDeserializeOffHeap) { 382 if (deserialization_mode == DeserializationMode::kDeserializeOffHeap) {
377 current_scope->DeserializeScopeInfo(isolate, ast_value_factory); 383 current_scope->DeserializeScopeInfo(isolate, ast_value_factory);
378 } 384 }
379 if (innermost_scope == nullptr) innermost_scope = current_scope; 385 if (innermost_scope == nullptr) innermost_scope = current_scope;
380 context = context->previous(); 386 context = context->previous();
(...skipping 1306 matching lines...) Expand 10 before | Expand all | Expand 10 after
1687 Variable* function = 1693 Variable* function =
1688 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; 1694 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr;
1689 bool is_function_var_in_context = 1695 bool is_function_var_in_context =
1690 function != nullptr && function->IsContextSlot(); 1696 function != nullptr && function->IsContextSlot();
1691 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 1697 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
1692 (is_function_var_in_context ? 1 : 0); 1698 (is_function_var_in_context ? 1 : 0);
1693 } 1699 }
1694 1700
1695 } // namespace internal 1701 } // namespace internal
1696 } // namespace v8 1702 } // namespace v8
OLDNEW
« no previous file with comments | « src/ast/scopes.h ('k') | src/compiler/access-builder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698