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

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

Issue 2224793003: Only conditionally add inner scope when deserializing (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 4 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') | no next file » | 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 already_resolved_(true) { 133 already_resolved_(true) {
134 SetDefaults(); 134 SetDefaults();
135 if (!scope_info.is_null()) { 135 if (!scope_info.is_null()) {
136 scope_calls_eval_ = scope_info->CallsEval(); 136 scope_calls_eval_ = scope_info->CallsEval();
137 language_mode_ = scope_info->language_mode(); 137 language_mode_ = scope_info->language_mode();
138 num_heap_slots_ = scope_info_->ContextLength(); 138 num_heap_slots_ = scope_info_->ContextLength();
139 } 139 }
140 // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context. 140 // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context.
141 num_heap_slots_ = Max(num_heap_slots_, 141 num_heap_slots_ = Max(num_heap_slots_,
142 static_cast<int>(Context::MIN_CONTEXT_SLOTS)); 142 static_cast<int>(Context::MIN_CONTEXT_SLOTS));
143 AddInnerScope(inner_scope); 143 if (inner_scope != nullptr) AddInnerScope(inner_scope);
144 } 144 }
145 145
146 DeclarationScope::DeclarationScope(Zone* zone, Scope* inner_scope, 146 DeclarationScope::DeclarationScope(Zone* zone, Scope* inner_scope,
147 ScopeType scope_type, 147 ScopeType scope_type,
148 Handle<ScopeInfo> scope_info) 148 Handle<ScopeInfo> scope_info)
149 : Scope(zone, inner_scope, scope_type, scope_info), 149 : Scope(zone, inner_scope, scope_type, scope_info),
150 function_kind_(scope_info.is_null() ? kNormalFunction 150 function_kind_(scope_info.is_null() ? kNormalFunction
151 : scope_info->function_kind()), 151 : scope_info->function_kind()),
152 temps_(4, zone), 152 temps_(4, zone),
153 params_(4, zone), 153 params_(4, zone),
154 sloppy_block_function_map_(zone), 154 sloppy_block_function_map_(zone),
155 module_descriptor_(nullptr) { 155 module_descriptor_(nullptr) {
156 SetDefaults(); 156 SetDefaults();
157 } 157 }
158 158
159 Scope::Scope(Zone* zone, Scope* inner_scope, 159 Scope::Scope(Zone* zone, Scope* inner_scope,
160 const AstRawString* catch_variable_name) 160 const AstRawString* catch_variable_name)
161 : zone_(zone), 161 : zone_(zone),
162 outer_scope_(nullptr), 162 outer_scope_(nullptr),
163 variables_(zone), 163 variables_(zone),
164 decls_(0, zone), 164 decls_(0, zone),
165 scope_type_(CATCH_SCOPE), 165 scope_type_(CATCH_SCOPE),
166 already_resolved_(true) { 166 already_resolved_(true) {
167 SetDefaults(); 167 SetDefaults();
168 AddInnerScope(inner_scope); 168 if (inner_scope != nullptr) AddInnerScope(inner_scope);
169 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; 169 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS;
170 Variable* variable = 170 Variable* variable =
171 variables_.Declare(zone, this, catch_variable_name, VAR, Variable::NORMAL, 171 variables_.Declare(zone, this, catch_variable_name, VAR, Variable::NORMAL,
172 kCreatedInitialized); 172 kCreatedInitialized);
173 AllocateHeapSlot(variable); 173 AllocateHeapSlot(variable);
174 } 174 }
175 175
176 void DeclarationScope::SetDefaults() { 176 void DeclarationScope::SetDefaults() {
177 is_declaration_scope_ = true; 177 is_declaration_scope_ = true;
178 has_simple_parameters_ = true; 178 has_simple_parameters_ = true;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 DeclarationScope* scope = GetClosureScope(); 225 DeclarationScope* scope = GetClosureScope();
226 return !scope->is_function_scope() || scope->has_simple_parameters(); 226 return !scope->is_function_scope() || scope->has_simple_parameters();
227 } 227 }
228 228
229 Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone, 229 Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone,
230 Context* context, 230 Context* context,
231 DeclarationScope* script_scope, 231 DeclarationScope* script_scope,
232 AstValueFactory* ast_value_factory, 232 AstValueFactory* ast_value_factory,
233 DeserializationMode deserialization_mode) { 233 DeserializationMode deserialization_mode) {
234 // Reconstruct the outer scope chain from a closure's context chain. 234 // Reconstruct the outer scope chain from a closure's context chain.
235 Scope* current_scope = NULL; 235 Scope* current_scope = nullptr;
236 Scope* innermost_scope = NULL; 236 Scope* innermost_scope = nullptr;
237 while (!context->IsNativeContext()) { 237 while (!context->IsNativeContext()) {
238 if (context->IsWithContext() || context->IsDebugEvaluateContext()) { 238 if (context->IsWithContext() || context->IsDebugEvaluateContext()) {
239 // For scope analysis, debug-evaluate is equivalent to a with scope. 239 // For scope analysis, debug-evaluate is equivalent to a with scope.
240 Scope* with_scope = new (zone) 240 Scope* with_scope = new (zone)
241 Scope(zone, current_scope, WITH_SCOPE, Handle<ScopeInfo>::null()); 241 Scope(zone, current_scope, WITH_SCOPE, Handle<ScopeInfo>::null());
242 current_scope = with_scope; 242 current_scope = with_scope;
243 // All the inner scopes are inside a with. 243 // All the inner scopes are inside a with.
244 for (Scope* s = innermost_scope; s != NULL; s = s->outer_scope()) { 244 for (Scope* s = innermost_scope; s != nullptr; s = s->outer_scope()) {
245 s->scope_inside_with_ = true; 245 s->scope_inside_with_ = true;
246 } 246 }
247 } else if (context->IsScriptContext()) { 247 } else if (context->IsScriptContext()) {
248 ScopeInfo* scope_info = context->scope_info(); 248 ScopeInfo* scope_info = context->scope_info();
249 current_scope = new (zone) DeclarationScope( 249 current_scope = new (zone) DeclarationScope(
250 zone, current_scope, SCRIPT_SCOPE, Handle<ScopeInfo>(scope_info)); 250 zone, current_scope, SCRIPT_SCOPE, Handle<ScopeInfo>(scope_info));
251 } else if (context->IsFunctionContext()) { 251 } else if (context->IsFunctionContext()) {
252 ScopeInfo* scope_info = context->closure()->shared()->scope_info(); 252 ScopeInfo* scope_info = context->closure()->shared()->scope_info();
253 current_scope = new (zone) DeclarationScope( 253 current_scope = new (zone) DeclarationScope(
254 zone, current_scope, FUNCTION_SCOPE, Handle<ScopeInfo>(scope_info)); 254 zone, current_scope, FUNCTION_SCOPE, Handle<ScopeInfo>(scope_info));
(...skipping 11 matching lines...) Expand all
266 } else { 266 } else {
267 DCHECK(context->IsCatchContext()); 267 DCHECK(context->IsCatchContext());
268 String* name = context->catch_name(); 268 String* name = context->catch_name();
269 current_scope = 269 current_scope =
270 new (zone) Scope(zone, current_scope, 270 new (zone) Scope(zone, current_scope,
271 ast_value_factory->GetString(handle(name, isolate))); 271 ast_value_factory->GetString(handle(name, isolate)));
272 } 272 }
273 if (deserialization_mode == DeserializationMode::kDeserializeOffHeap) { 273 if (deserialization_mode == DeserializationMode::kDeserializeOffHeap) {
274 current_scope->DeserializeScopeInfo(isolate, ast_value_factory); 274 current_scope->DeserializeScopeInfo(isolate, ast_value_factory);
275 } 275 }
276 if (innermost_scope == NULL) innermost_scope = current_scope; 276 if (innermost_scope == nullptr) innermost_scope = current_scope;
277 context = context->previous(); 277 context = context->previous();
278 } 278 }
279 279
280 script_scope->AddInnerScope(current_scope); 280 script_scope->AddInnerScope(current_scope);
281 script_scope->PropagateScopeInfo(false); 281 script_scope->PropagateScopeInfo(false);
282 return (innermost_scope == NULL) ? script_scope : innermost_scope; 282 return (innermost_scope == NULL) ? script_scope : innermost_scope;
283 } 283 }
284 284
285 void Scope::DeserializeScopeInfo(Isolate* isolate, 285 void Scope::DeserializeScopeInfo(Isolate* isolate,
286 AstValueFactory* ast_value_factory) { 286 AstValueFactory* ast_value_factory) {
(...skipping 1472 matching lines...) Expand 10 before | Expand all | Expand 10 after
1759 function != NULL && function->proxy()->var()->IsContextSlot(); 1759 function != NULL && function->proxy()->var()->IsContextSlot();
1760 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - 1760 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() -
1761 (is_function_var_in_context ? 1 : 0); 1761 (is_function_var_in_context ? 1 : 0);
1762 } 1762 }
1763 1763
1764 1764
1765 int Scope::ContextGlobalCount() const { return num_global_slots(); } 1765 int Scope::ContextGlobalCount() const { return num_global_slots(); }
1766 1766
1767 } // namespace internal 1767 } // namespace internal
1768 } // namespace v8 1768 } // namespace v8
OLDNEW
« no previous file with comments | « src/ast/scopes.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698