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

Side by Side Diff: src/scopeinfo.cc

Issue 1292753007: [es6] Parameter scopes for sloppy eval (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 <stdlib.h> 5 #include <stdlib.h>
6 6
7 #include "src/v8.h" 7 #include "src/v8.h"
8 8
9 #include "src/bootstrapper.h" 9 #include "src/bootstrapper.h"
10 #include "src/scopeinfo.h" 10 #include "src/scopeinfo.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 Factory* factory = isolate->factory(); 82 Factory* factory = isolate->factory();
83 Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length); 83 Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length);
84 84
85 bool has_simple_parameters = 85 bool has_simple_parameters =
86 scope->is_function_scope() && scope->has_simple_parameters(); 86 scope->is_function_scope() && scope->has_simple_parameters();
87 87
88 // Encode the flags. 88 // Encode the flags.
89 int flags = ScopeTypeField::encode(scope->scope_type()) | 89 int flags = ScopeTypeField::encode(scope->scope_type()) |
90 CallsEvalField::encode(scope->calls_eval()) | 90 CallsEvalField::encode(scope->calls_eval()) |
91 LanguageModeField::encode(scope->language_mode()) | 91 LanguageModeField::encode(scope->language_mode()) |
92 DeclarationScopeField::encode(scope->is_declaration_scope()) |
92 ReceiverVariableField::encode(receiver_info) | 93 ReceiverVariableField::encode(receiver_info) |
93 FunctionVariableField::encode(function_name_info) | 94 FunctionVariableField::encode(function_name_info) |
94 FunctionVariableMode::encode(function_variable_mode) | 95 FunctionVariableMode::encode(function_variable_mode) |
95 AsmModuleField::encode(scope->asm_module()) | 96 AsmModuleField::encode(scope->asm_module()) |
96 AsmFunctionField::encode(scope->asm_function()) | 97 AsmFunctionField::encode(scope->asm_function()) |
97 HasSimpleParametersField::encode(has_simple_parameters) | 98 HasSimpleParametersField::encode(has_simple_parameters) |
98 FunctionKindField::encode(scope->function_kind()); 99 FunctionKindField::encode(scope->function_kind());
99 scope_info->SetFlags(flags); 100 scope_info->SetFlags(flags);
100 scope_info->SetParameterCount(parameter_count); 101 scope_info->SetParameterCount(parameter_count);
101 scope_info->SetStackLocalCount(stack_local_count); 102 scope_info->SetStackLocalCount(stack_local_count);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 3 * strong_mode_free_variable_count + 238 3 * strong_mode_free_variable_count +
238 (has_receiver ? 1 : 0) + (has_function_name ? 2 : 0); 239 (has_receiver ? 1 : 0) + (has_function_name ? 2 : 0);
239 240
240 Factory* factory = isolate->factory(); 241 Factory* factory = isolate->factory();
241 Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length); 242 Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length);
242 243
243 // Encode the flags. 244 // Encode the flags.
244 int flags = ScopeTypeField::encode(SCRIPT_SCOPE) | 245 int flags = ScopeTypeField::encode(SCRIPT_SCOPE) |
245 CallsEvalField::encode(false) | 246 CallsEvalField::encode(false) |
246 LanguageModeField::encode(SLOPPY) | 247 LanguageModeField::encode(SLOPPY) |
248 DeclarationScopeField::encode(true) |
247 ReceiverVariableField::encode(receiver_info) | 249 ReceiverVariableField::encode(receiver_info) |
248 FunctionVariableField::encode(function_name_info) | 250 FunctionVariableField::encode(function_name_info) |
249 FunctionVariableMode::encode(function_variable_mode) | 251 FunctionVariableMode::encode(function_variable_mode) |
250 AsmModuleField::encode(false) | AsmFunctionField::encode(false) | 252 AsmModuleField::encode(false) | AsmFunctionField::encode(false) |
251 HasSimpleParametersField::encode(has_simple_parameters) | 253 HasSimpleParametersField::encode(has_simple_parameters) |
252 FunctionKindField::encode(FunctionKind::kNormalFunction); 254 FunctionKindField::encode(FunctionKind::kNormalFunction);
253 scope_info->SetFlags(flags); 255 scope_info->SetFlags(flags);
254 scope_info->SetParameterCount(parameter_count); 256 scope_info->SetParameterCount(parameter_count);
255 scope_info->SetStackLocalCount(stack_local_count); 257 scope_info->SetStackLocalCount(stack_local_count);
256 scope_info->SetContextLocalCount(context_local_count); 258 scope_info->SetContextLocalCount(context_local_count);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 bool ScopeInfo::CallsEval() { 306 bool ScopeInfo::CallsEval() {
305 return length() > 0 && CallsEvalField::decode(Flags()); 307 return length() > 0 && CallsEvalField::decode(Flags());
306 } 308 }
307 309
308 310
309 LanguageMode ScopeInfo::language_mode() { 311 LanguageMode ScopeInfo::language_mode() {
310 return length() > 0 ? LanguageModeField::decode(Flags()) : SLOPPY; 312 return length() > 0 ? LanguageModeField::decode(Flags()) : SLOPPY;
311 } 313 }
312 314
313 315
316 bool ScopeInfo::is_declaration_scope() {
317 return DeclarationScopeField::decode(Flags());
318 }
319
320
314 int ScopeInfo::LocalCount() { 321 int ScopeInfo::LocalCount() {
315 return StackLocalCount() + ContextLocalCount(); 322 return StackLocalCount() + ContextLocalCount();
316 } 323 }
317 324
318 325
319 int ScopeInfo::StackSlotCount() { 326 int ScopeInfo::StackSlotCount() {
320 if (length() > 0) { 327 if (length() > 0) {
321 bool function_name_stack_slot = 328 bool function_name_stack_slot =
322 FunctionVariableField::decode(Flags()) == STACK; 329 FunctionVariableField::decode(Flags()) == STACK;
323 return StackLocalCount() + (function_name_stack_slot ? 1 : 0); 330 return StackLocalCount() + (function_name_stack_slot ? 1 : 0);
324 } 331 }
325 return 0; 332 return 0;
326 } 333 }
327 334
328 335
329 int ScopeInfo::ContextLength() { 336 int ScopeInfo::ContextLength() {
330 if (length() > 0) { 337 if (length() > 0) {
331 int context_locals = ContextLocalCount(); 338 int context_locals = ContextLocalCount();
332 int context_globals = ContextGlobalCount(); 339 int context_globals = ContextGlobalCount();
333 bool function_name_context_slot = 340 bool function_name_context_slot =
334 FunctionVariableField::decode(Flags()) == CONTEXT; 341 FunctionVariableField::decode(Flags()) == CONTEXT;
335 bool has_context = context_locals > 0 || context_globals > 0 || 342 bool has_context = context_locals > 0 || context_globals > 0 ||
336 function_name_context_slot || 343 function_name_context_slot ||
337 scope_type() == WITH_SCOPE || 344 scope_type() == WITH_SCOPE ||
345 (scope_type() == BLOCK_SCOPE && CallsSloppyEval() &&
346 is_declaration_scope()) ||
338 (scope_type() == ARROW_SCOPE && CallsSloppyEval()) || 347 (scope_type() == ARROW_SCOPE && CallsSloppyEval()) ||
339 (scope_type() == FUNCTION_SCOPE && CallsSloppyEval()) || 348 (scope_type() == FUNCTION_SCOPE && CallsSloppyEval()) ||
340 scope_type() == MODULE_SCOPE; 349 scope_type() == MODULE_SCOPE;
341 350
342 if (has_context) { 351 if (has_context) {
343 return Context::MIN_CONTEXT_SLOTS + context_locals + context_globals + 352 return Context::MIN_CONTEXT_SLOTS + context_locals + context_globals +
344 (function_name_context_slot ? 1 : 0); 353 (function_name_context_slot ? 1 : 0);
345 } 354 }
346 } 355 }
347 return 0; 356 return 0;
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 info->set_mode(i, var->mode()); 839 info->set_mode(i, var->mode());
831 DCHECK(var->index() >= 0); 840 DCHECK(var->index() >= 0);
832 info->set_index(i, var->index()); 841 info->set_index(i, var->index());
833 } 842 }
834 DCHECK(i == info->length()); 843 DCHECK(i == info->length());
835 return info; 844 return info;
836 } 845 }
837 846
838 } // namespace internal 847 } // namespace internal
839 } // namespace v8 848 } // namespace v8
OLDNEW
« src/contexts.cc ('K') | « src/runtime/runtime-scopes.cc ('k') | src/scopes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698