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

Side by Side Diff: src/scopes.cc

Issue 8221004: Move declaration of SerializedScopeInfo from variables.h to objects.h (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 // Dummy constructor 79 // Dummy constructor
80 VariableMap::VariableMap(bool gotta_love_static_overloading) : HashMap() {} 80 VariableMap::VariableMap(bool gotta_love_static_overloading) : HashMap() {}
81 81
82 VariableMap::VariableMap() : HashMap(Match, &LocalsMapAllocator, 8) {} 82 VariableMap::VariableMap() : HashMap(Match, &LocalsMapAllocator, 8) {}
83 VariableMap::~VariableMap() {} 83 VariableMap::~VariableMap() {}
84 84
85 85
86 Variable* VariableMap::Declare(Scope* scope, 86 Variable* VariableMap::Declare(Scope* scope,
87 Handle<String> name, 87 Handle<String> name,
88 Variable::Mode mode, 88 VariableMode mode,
89 bool is_valid_lhs, 89 bool is_valid_lhs,
90 Variable::Kind kind) { 90 Variable::Kind kind) {
91 HashMap::Entry* p = HashMap::Lookup(name.location(), name->Hash(), true); 91 HashMap::Entry* p = HashMap::Lookup(name.location(), name->Hash(), true);
92 if (p->value == NULL) { 92 if (p->value == NULL) {
93 // The variable has not been declared yet -> insert it. 93 // The variable has not been declared yet -> insert it.
94 ASSERT(p->key == name.location()); 94 ASSERT(p->key == name.location());
95 p->value = new Variable(scope, name, mode, is_valid_lhs, kind); 95 p->value = new Variable(scope, name, mode, is_valid_lhs, kind);
96 } 96 }
97 return reinterpret_cast<Variable*>(p->value); 97 return reinterpret_cast<Variable*>(p->value);
98 } 98 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 temps_(0), 172 temps_(0),
173 params_(0), 173 params_(0),
174 unresolved_(0), 174 unresolved_(0),
175 decls_(0), 175 decls_(0),
176 already_resolved_(true) { 176 already_resolved_(true) {
177 SetDefaults(CATCH_SCOPE, NULL, Handle<SerializedScopeInfo>::null()); 177 SetDefaults(CATCH_SCOPE, NULL, Handle<SerializedScopeInfo>::null());
178 AddInnerScope(inner_scope); 178 AddInnerScope(inner_scope);
179 ++num_var_or_const_; 179 ++num_var_or_const_;
180 Variable* variable = variables_.Declare(this, 180 Variable* variable = variables_.Declare(this,
181 catch_variable_name, 181 catch_variable_name,
182 Variable::VAR, 182 VAR,
183 true, // Valid left-hand side. 183 true, // Valid left-hand side.
184 Variable::NORMAL); 184 Variable::NORMAL);
185 AllocateHeapSlot(variable); 185 AllocateHeapSlot(variable);
186 } 186 }
187 187
188 188
189 void Scope::SetDefaults(Type type, 189 void Scope::SetDefaults(Type type,
190 Scope* outer_scope, 190 Scope* outer_scope,
191 Handle<SerializedScopeInfo> scope_info) { 191 Handle<SerializedScopeInfo> scope_info) {
192 outer_scope_ = outer_scope; 192 outer_scope_ = outer_scope;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 if (is_catch_scope() || is_block_scope()) { 303 if (is_catch_scope() || is_block_scope()) {
304 ASSERT(outer_scope() != NULL); 304 ASSERT(outer_scope() != NULL);
305 receiver_ = outer_scope()->receiver(); 305 receiver_ = outer_scope()->receiver();
306 } else { 306 } else {
307 ASSERT(is_function_scope() || 307 ASSERT(is_function_scope() ||
308 is_global_scope() || 308 is_global_scope() ||
309 is_eval_scope()); 309 is_eval_scope());
310 Variable* var = 310 Variable* var =
311 variables_.Declare(this, 311 variables_.Declare(this,
312 isolate_->factory()->this_symbol(), 312 isolate_->factory()->this_symbol(),
313 Variable::VAR, 313 VAR,
314 false, 314 false,
315 Variable::THIS); 315 Variable::THIS);
316 var->AllocateTo(Variable::PARAMETER, -1); 316 var->AllocateTo(Variable::PARAMETER, -1);
317 receiver_ = var; 317 receiver_ = var;
318 } 318 }
319 319
320 if (is_function_scope()) { 320 if (is_function_scope()) {
321 // Declare 'arguments' variable which exists in all functions. 321 // Declare 'arguments' variable which exists in all functions.
322 // Note that it might never be accessed, in which case it won't be 322 // Note that it might never be accessed, in which case it won't be
323 // allocated during variable allocation. 323 // allocated during variable allocation.
324 variables_.Declare(this, 324 variables_.Declare(this,
325 isolate_->factory()->arguments_symbol(), 325 isolate_->factory()->arguments_symbol(),
326 Variable::VAR, 326 VAR,
327 true, 327 true,
328 Variable::ARGUMENTS); 328 Variable::ARGUMENTS);
329 } 329 }
330 } 330 }
331 331
332 332
333 Scope* Scope::FinalizeBlockScope() { 333 Scope* Scope::FinalizeBlockScope() {
334 ASSERT(is_block_scope()); 334 ASSERT(is_block_scope());
335 ASSERT(temps_.is_empty()); 335 ASSERT(temps_.is_empty());
336 ASSERT(params_.is_empty()); 336 ASSERT(params_.is_empty());
(...skipping 29 matching lines...) Expand all
366 } 366 }
367 // If we have a serialized scope info, we might find the variable there. 367 // If we have a serialized scope info, we might find the variable there.
368 // 368 //
369 // We should never lookup 'arguments' in this scope as it is implicitly 369 // We should never lookup 'arguments' in this scope as it is implicitly
370 // present in every scope. 370 // present in every scope.
371 ASSERT(*name != *isolate_->factory()->arguments_symbol()); 371 ASSERT(*name != *isolate_->factory()->arguments_symbol());
372 // There should be no local slot with the given name. 372 // There should be no local slot with the given name.
373 ASSERT(scope_info_->StackSlotIndex(*name) < 0); 373 ASSERT(scope_info_->StackSlotIndex(*name) < 0);
374 374
375 // Check context slot lookup. 375 // Check context slot lookup.
376 Variable::Mode mode; 376 VariableMode mode;
377 int index = scope_info_->ContextSlotIndex(*name, &mode); 377 int index = scope_info_->ContextSlotIndex(*name, &mode);
378 if (index < 0) { 378 if (index < 0) {
379 // Check parameters. 379 // Check parameters.
380 mode = Variable::VAR; 380 mode = VAR;
381 index = scope_info_->ParameterIndex(*name); 381 index = scope_info_->ParameterIndex(*name);
382 if (index < 0) { 382 if (index < 0) {
383 // Check the function name. 383 // Check the function name.
384 index = scope_info_->FunctionContextSlotIndex(*name); 384 index = scope_info_->FunctionContextSlotIndex(*name);
385 if (index < 0) return NULL; 385 if (index < 0) return NULL;
386 } 386 }
387 } 387 }
388 388
389 Variable* var = 389 Variable* var =
390 variables_.Declare(this, name, mode, true, Variable::NORMAL); 390 variables_.Declare(this, name, mode, true, Variable::NORMAL);
391 var->AllocateTo(Variable::CONTEXT, index); 391 var->AllocateTo(Variable::CONTEXT, index);
392 return var; 392 return var;
393 } 393 }
394 394
395 395
396 Variable* Scope::Lookup(Handle<String> name) { 396 Variable* Scope::Lookup(Handle<String> name) {
397 for (Scope* scope = this; 397 for (Scope* scope = this;
398 scope != NULL; 398 scope != NULL;
399 scope = scope->outer_scope()) { 399 scope = scope->outer_scope()) {
400 Variable* var = scope->LocalLookup(name); 400 Variable* var = scope->LocalLookup(name);
401 if (var != NULL) return var; 401 if (var != NULL) return var;
402 } 402 }
403 return NULL; 403 return NULL;
404 } 404 }
405 405
406 406
407 Variable* Scope::DeclareFunctionVar(Handle<String> name) { 407 Variable* Scope::DeclareFunctionVar(Handle<String> name) {
408 ASSERT(is_function_scope() && function_ == NULL); 408 ASSERT(is_function_scope() && function_ == NULL);
409 Variable* function_var = 409 Variable* function_var =
410 new Variable(this, name, Variable::CONST, true, Variable::NORMAL); 410 new Variable(this, name, CONST, true, Variable::NORMAL);
411 function_ = new(isolate_->zone()) VariableProxy(isolate_, function_var); 411 function_ = new(isolate_->zone()) VariableProxy(isolate_, function_var);
412 return function_var; 412 return function_var;
413 } 413 }
414 414
415 415
416 void Scope::DeclareParameter(Handle<String> name, Variable::Mode mode) { 416 void Scope::DeclareParameter(Handle<String> name, VariableMode mode) {
417 ASSERT(!already_resolved()); 417 ASSERT(!already_resolved());
418 ASSERT(is_function_scope()); 418 ASSERT(is_function_scope());
419 Variable* var = 419 Variable* var =
420 variables_.Declare(this, name, mode, true, Variable::NORMAL); 420 variables_.Declare(this, name, mode, true, Variable::NORMAL);
421 params_.Add(var); 421 params_.Add(var);
422 } 422 }
423 423
424 424
425 Variable* Scope::DeclareLocal(Handle<String> name, Variable::Mode mode) { 425 Variable* Scope::DeclareLocal(Handle<String> name, VariableMode mode) {
426 ASSERT(!already_resolved()); 426 ASSERT(!already_resolved());
427 // This function handles VAR and CONST modes. DYNAMIC variables are 427 // This function handles VAR and CONST modes. DYNAMIC variables are
428 // introduces during variable allocation, INTERNAL variables are allocated 428 // introduces during variable allocation, INTERNAL variables are allocated
429 // explicitly, and TEMPORARY variables are allocated via NewTemporary(). 429 // explicitly, and TEMPORARY variables are allocated via NewTemporary().
430 ASSERT(mode == Variable::VAR || 430 ASSERT(mode == VAR || mode == CONST || mode == LET);
431 mode == Variable::CONST ||
432 mode == Variable::LET);
433 ++num_var_or_const_; 431 ++num_var_or_const_;
434 return variables_.Declare(this, name, mode, true, Variable::NORMAL); 432 return variables_.Declare(this, name, mode, true, Variable::NORMAL);
435 } 433 }
436 434
437 435
438 Variable* Scope::DeclareGlobal(Handle<String> name) { 436 Variable* Scope::DeclareGlobal(Handle<String> name) {
439 ASSERT(is_global_scope()); 437 ASSERT(is_global_scope());
440 return variables_.Declare(this, name, Variable::DYNAMIC_GLOBAL, 438 return variables_.Declare(this, name, DYNAMIC_GLOBAL,
441 true, 439 true,
442 Variable::NORMAL); 440 Variable::NORMAL);
443 } 441 }
444 442
445 443
446 VariableProxy* Scope::NewUnresolved(Handle<String> name, 444 VariableProxy* Scope::NewUnresolved(Handle<String> name,
447 bool inside_with, 445 bool inside_with,
448 int position) { 446 int position) {
449 // Note that we must not share the unresolved variables with 447 // Note that we must not share the unresolved variables with
450 // the same name because they may be removed selectively via 448 // the same name because they may be removed selectively via
(...skipping 15 matching lines...) Expand all
466 return; 464 return;
467 } 465 }
468 } 466 }
469 } 467 }
470 468
471 469
472 Variable* Scope::NewTemporary(Handle<String> name) { 470 Variable* Scope::NewTemporary(Handle<String> name) {
473 ASSERT(!already_resolved()); 471 ASSERT(!already_resolved());
474 Variable* var = new Variable(this, 472 Variable* var = new Variable(this,
475 name, 473 name,
476 Variable::TEMPORARY, 474 TEMPORARY,
477 true, 475 true,
478 Variable::NORMAL); 476 Variable::NORMAL);
479 temps_.Add(var); 477 temps_.Add(var);
480 return var; 478 return var;
481 } 479 }
482 480
483 481
484 void Scope::AddDeclaration(Declaration* declaration) { 482 void Scope::AddDeclaration(Declaration* declaration) {
485 decls_.Add(declaration); 483 decls_.Add(declaration);
486 } 484 }
(...skipping 11 matching lines...) Expand all
498 void Scope::VisitIllegalRedeclaration(AstVisitor* visitor) { 496 void Scope::VisitIllegalRedeclaration(AstVisitor* visitor) {
499 ASSERT(HasIllegalRedeclaration()); 497 ASSERT(HasIllegalRedeclaration());
500 illegal_redecl_->Accept(visitor); 498 illegal_redecl_->Accept(visitor);
501 } 499 }
502 500
503 501
504 Declaration* Scope::CheckConflictingVarDeclarations() { 502 Declaration* Scope::CheckConflictingVarDeclarations() {
505 int length = decls_.length(); 503 int length = decls_.length();
506 for (int i = 0; i < length; i++) { 504 for (int i = 0; i < length; i++) {
507 Declaration* decl = decls_[i]; 505 Declaration* decl = decls_[i];
508 if (decl->mode() != Variable::VAR) continue; 506 if (decl->mode() != VAR) continue;
509 Handle<String> name = decl->proxy()->name(); 507 Handle<String> name = decl->proxy()->name();
510 bool cond = true; 508 bool cond = true;
511 for (Scope* scope = decl->scope(); cond ; scope = scope->outer_scope_) { 509 for (Scope* scope = decl->scope(); cond ; scope = scope->outer_scope_) {
512 // There is a conflict if there exists a non-VAR binding. 510 // There is a conflict if there exists a non-VAR binding.
513 Variable* other_var = scope->variables_.Lookup(name); 511 Variable* other_var = scope->variables_.Lookup(name);
514 if (other_var != NULL && other_var->mode() != Variable::VAR) { 512 if (other_var != NULL && other_var->mode() != VAR) {
515 return decl; 513 return decl;
516 } 514 }
517 515
518 // Include declaration scope in the iteration but stop after. 516 // Include declaration scope in the iteration but stop after.
519 if (!scope->is_block_scope() && !scope->is_catch_scope()) cond = false; 517 if (!scope->is_block_scope() && !scope->is_catch_scope()) cond = false;
520 } 518 }
521 } 519 }
522 return NULL; 520 return NULL;
523 } 521 }
524 522
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 Indent(n1, "// temporary vars\n"); 770 Indent(n1, "// temporary vars\n");
773 for (int i = 0; i < temps_.length(); i++) { 771 for (int i = 0; i < temps_.length(); i++) {
774 PrintVar(n1, temps_[i]); 772 PrintVar(n1, temps_[i]);
775 } 773 }
776 774
777 Indent(n1, "// local vars\n"); 775 Indent(n1, "// local vars\n");
778 PrintMap(n1, &variables_); 776 PrintMap(n1, &variables_);
779 777
780 Indent(n1, "// dynamic vars\n"); 778 Indent(n1, "// dynamic vars\n");
781 if (dynamics_ != NULL) { 779 if (dynamics_ != NULL) {
782 PrintMap(n1, dynamics_->GetMap(Variable::DYNAMIC)); 780 PrintMap(n1, dynamics_->GetMap(DYNAMIC));
783 PrintMap(n1, dynamics_->GetMap(Variable::DYNAMIC_LOCAL)); 781 PrintMap(n1, dynamics_->GetMap(DYNAMIC_LOCAL));
784 PrintMap(n1, dynamics_->GetMap(Variable::DYNAMIC_GLOBAL)); 782 PrintMap(n1, dynamics_->GetMap(DYNAMIC_GLOBAL));
785 } 783 }
786 784
787 // Print inner scopes (disable by providing negative n). 785 // Print inner scopes (disable by providing negative n).
788 if (n >= 0) { 786 if (n >= 0) {
789 for (int i = 0; i < inner_scopes_.length(); i++) { 787 for (int i = 0; i < inner_scopes_.length(); i++) {
790 PrintF("\n"); 788 PrintF("\n");
791 inner_scopes_[i]->Print(n1); 789 inner_scopes_[i]->Print(n1);
792 } 790 }
793 } 791 }
794 792
795 Indent(n0, "}\n"); 793 Indent(n0, "}\n");
796 } 794 }
797 #endif // DEBUG 795 #endif // DEBUG
798 796
799 797
800 Variable* Scope::NonLocal(Handle<String> name, Variable::Mode mode) { 798 Variable* Scope::NonLocal(Handle<String> name, VariableMode mode) {
801 if (dynamics_ == NULL) dynamics_ = new DynamicScopePart(); 799 if (dynamics_ == NULL) dynamics_ = new DynamicScopePart();
802 VariableMap* map = dynamics_->GetMap(mode); 800 VariableMap* map = dynamics_->GetMap(mode);
803 Variable* var = map->Lookup(name); 801 Variable* var = map->Lookup(name);
804 if (var == NULL) { 802 if (var == NULL) {
805 // Declare a new non-local. 803 // Declare a new non-local.
806 var = map->Declare(NULL, name, mode, true, Variable::NORMAL); 804 var = map->Declare(NULL, name, mode, true, Variable::NORMAL);
807 // Allocate it by giving it a dynamic lookup. 805 // Allocate it by giving it a dynamic lookup.
808 var->AllocateTo(Variable::LOOKUP, -1); 806 var->AllocateTo(Variable::LOOKUP, -1);
809 } 807 }
810 return var; 808 return var;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 Variable* invalidated_local = NULL; 894 Variable* invalidated_local = NULL;
897 Variable* var = LookupRecursive(proxy->name(), false, &invalidated_local); 895 Variable* var = LookupRecursive(proxy->name(), false, &invalidated_local);
898 896
899 if (proxy->inside_with()) { 897 if (proxy->inside_with()) {
900 // If we are inside a local 'with' statement, all bets are off 898 // If we are inside a local 'with' statement, all bets are off
901 // and we cannot resolve the proxy to a local variable even if 899 // and we cannot resolve the proxy to a local variable even if
902 // we found an outer matching variable. 900 // we found an outer matching variable.
903 // Note that we must do a lookup anyway, because if we find one, 901 // Note that we must do a lookup anyway, because if we find one,
904 // we must mark that variable as potentially accessed from this 902 // we must mark that variable as potentially accessed from this
905 // inner scope (the property may not be in the 'with' object). 903 // inner scope (the property may not be in the 'with' object).
906 var = NonLocal(proxy->name(), Variable::DYNAMIC); 904 var = NonLocal(proxy->name(), DYNAMIC);
907 905
908 } else { 906 } else {
909 // We are not inside a local 'with' statement. 907 // We are not inside a local 'with' statement.
910 908
911 if (var == NULL) { 909 if (var == NULL) {
912 // We did not find the variable. We have a global variable 910 // We did not find the variable. We have a global variable
913 // if we are in the global scope (we know already that we 911 // if we are in the global scope (we know already that we
914 // are outside a 'with' statement) or if there is no way 912 // are outside a 'with' statement) or if there is no way
915 // that the variable might be introduced dynamically (through 913 // that the variable might be introduced dynamically (through
916 // a local or outer eval() call, or an outer 'with' statement), 914 // a local or outer eval() call, or an outer 'with' statement),
917 // or we don't know about the outer scope (because we are 915 // or we don't know about the outer scope (because we are
918 // in an eval scope). 916 // in an eval scope).
919 if (is_global_scope() || 917 if (is_global_scope() ||
920 !(scope_inside_with_ || outer_scope_is_eval_scope_ || 918 !(scope_inside_with_ || outer_scope_is_eval_scope_ ||
921 scope_calls_eval_ || outer_scope_calls_eval_)) { 919 scope_calls_eval_ || outer_scope_calls_eval_)) {
922 // We must have a global variable. 920 // We must have a global variable.
923 ASSERT(global_scope != NULL); 921 ASSERT(global_scope != NULL);
924 var = global_scope->DeclareGlobal(proxy->name()); 922 var = global_scope->DeclareGlobal(proxy->name());
925 923
926 } else if (scope_inside_with_) { 924 } else if (scope_inside_with_) {
927 // If we are inside a with statement we give up and look up 925 // If we are inside a with statement we give up and look up
928 // the variable at runtime. 926 // the variable at runtime.
929 var = NonLocal(proxy->name(), Variable::DYNAMIC); 927 var = NonLocal(proxy->name(), DYNAMIC);
930 928
931 } else if (invalidated_local != NULL) { 929 } else if (invalidated_local != NULL) {
932 // No with statements are involved and we found a local 930 // No with statements are involved and we found a local
933 // variable that might be shadowed by eval introduced 931 // variable that might be shadowed by eval introduced
934 // variables. 932 // variables.
935 var = NonLocal(proxy->name(), Variable::DYNAMIC_LOCAL); 933 var = NonLocal(proxy->name(), DYNAMIC_LOCAL);
936 var->set_local_if_not_shadowed(invalidated_local); 934 var->set_local_if_not_shadowed(invalidated_local);
937 935
938 } else if (outer_scope_is_eval_scope_) { 936 } else if (outer_scope_is_eval_scope_) {
939 // No with statements and we did not find a local and the code 937 // No with statements and we did not find a local and the code
940 // is executed with a call to eval. The context contains 938 // is executed with a call to eval. The context contains
941 // scope information that we can use to determine if the 939 // scope information that we can use to determine if the
942 // variable is global if it is not shadowed by eval-introduced 940 // variable is global if it is not shadowed by eval-introduced
943 // variables. 941 // variables.
944 if (context->GlobalIfNotShadowedByEval(proxy->name())) { 942 if (context->GlobalIfNotShadowedByEval(proxy->name())) {
945 var = NonLocal(proxy->name(), Variable::DYNAMIC_GLOBAL); 943 var = NonLocal(proxy->name(), DYNAMIC_GLOBAL);
946 944
947 } else { 945 } else {
948 var = NonLocal(proxy->name(), Variable::DYNAMIC); 946 var = NonLocal(proxy->name(), DYNAMIC);
949 } 947 }
950 948
951 } else { 949 } else {
952 // No with statements and we did not find a local and the code 950 // No with statements and we did not find a local and the code
953 // is not executed with a call to eval. We know that this 951 // is not executed with a call to eval. We know that this
954 // variable is global unless it is shadowed by eval-introduced 952 // variable is global unless it is shadowed by eval-introduced
955 // variables. 953 // variables.
956 var = NonLocal(proxy->name(), Variable::DYNAMIC_GLOBAL); 954 var = NonLocal(proxy->name(), DYNAMIC_GLOBAL);
957 } 955 }
958 } 956 }
959 } 957 }
960 958
961 proxy->BindTo(var); 959 proxy->BindTo(var);
962 } 960 }
963 961
964 962
965 void Scope::ResolveVariablesRecursively(Scope* global_scope, 963 void Scope::ResolveVariablesRecursively(Scope* global_scope,
966 Handle<Context> context) { 964 Handle<Context> context) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 1031
1034 1032
1035 bool Scope::MustAllocateInContext(Variable* var) { 1033 bool Scope::MustAllocateInContext(Variable* var) {
1036 // If var is accessed from an inner scope, or if there is a possibility 1034 // If var is accessed from an inner scope, or if there is a possibility
1037 // that it might be accessed from the current or an inner scope (through 1035 // that it might be accessed from the current or an inner scope (through
1038 // an eval() call or a runtime with lookup), it must be allocated in the 1036 // an eval() call or a runtime with lookup), it must be allocated in the
1039 // context. 1037 // context.
1040 // 1038 //
1041 // Exceptions: temporary variables are never allocated in a context; 1039 // Exceptions: temporary variables are never allocated in a context;
1042 // catch-bound variables are always allocated in a context. 1040 // catch-bound variables are always allocated in a context.
1043 if (var->mode() == Variable::TEMPORARY) return false; 1041 if (var->mode() == TEMPORARY) return false;
1044 if (is_catch_scope() || is_block_scope()) return true; 1042 if (is_catch_scope() || is_block_scope()) return true;
1045 return var->is_accessed_from_inner_scope() || 1043 return var->is_accessed_from_inner_scope() ||
1046 scope_calls_eval_ || 1044 scope_calls_eval_ ||
1047 inner_scope_calls_eval_ || 1045 inner_scope_calls_eval_ ||
1048 scope_contains_with_ || 1046 scope_contains_with_ ||
1049 var->is_global(); 1047 var->is_global();
1050 } 1048 }
1051 1049
1052 1050
1053 bool Scope::HasArgumentsParameter() { 1051 bool Scope::HasArgumentsParameter() {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1199 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && 1197 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS &&
1200 !must_have_local_context) { 1198 !must_have_local_context) {
1201 num_heap_slots_ = 0; 1199 num_heap_slots_ = 0;
1202 } 1200 }
1203 1201
1204 // Allocation done. 1202 // Allocation done.
1205 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); 1203 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS);
1206 } 1204 }
1207 1205
1208 } } // namespace v8::internal 1206 } } // namespace v8::internal
OLDNEW
« src/parser.cc ('K') | « src/scopes.h ('k') | src/v8globals.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698