OLD | NEW |
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 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 | 371 |
372 // Check context slot lookup. | 372 // Check context slot lookup. |
373 VariableMode mode; | 373 VariableMode mode; |
374 int index = scope_info_->ContextSlotIndex(*name, &mode); | 374 int index = scope_info_->ContextSlotIndex(*name, &mode); |
375 if (index < 0) { | 375 if (index < 0) { |
376 // Check parameters. | 376 // Check parameters. |
377 mode = VAR; | 377 mode = VAR; |
378 index = scope_info_->ParameterIndex(*name); | 378 index = scope_info_->ParameterIndex(*name); |
379 if (index < 0) { | 379 if (index < 0) { |
380 // Check the function name. | 380 // Check the function name. |
381 index = scope_info_->FunctionContextSlotIndex(*name); | 381 index = scope_info_->FunctionContextSlotIndex(*name, NULL); |
382 if (index < 0) return NULL; | 382 if (index < 0) return NULL; |
383 } | 383 } |
384 } | 384 } |
385 | 385 |
386 Variable* var = | 386 Variable* var = |
387 variables_.Declare(this, name, mode, true, Variable::NORMAL); | 387 variables_.Declare(this, name, mode, true, Variable::NORMAL); |
388 var->AllocateTo(Variable::CONTEXT, index); | 388 var->AllocateTo(Variable::CONTEXT, index); |
389 return var; | 389 return var; |
390 } | 390 } |
391 | 391 |
392 | 392 |
393 Variable* Scope::Lookup(Handle<String> name) { | 393 Variable* Scope::Lookup(Handle<String> name) { |
394 for (Scope* scope = this; | 394 for (Scope* scope = this; |
395 scope != NULL; | 395 scope != NULL; |
396 scope = scope->outer_scope()) { | 396 scope = scope->outer_scope()) { |
397 Variable* var = scope->LocalLookup(name); | 397 Variable* var = scope->LocalLookup(name); |
398 if (var != NULL) return var; | 398 if (var != NULL) return var; |
399 } | 399 } |
400 return NULL; | 400 return NULL; |
401 } | 401 } |
402 | 402 |
403 | 403 |
404 Variable* Scope::DeclareFunctionVar(Handle<String> name) { | 404 Variable* Scope::DeclareFunctionVar(Handle<String> name, VariableMode mode) { |
405 ASSERT(is_function_scope() && function_ == NULL); | 405 ASSERT(is_function_scope() && function_ == NULL); |
406 Variable* function_var = | 406 Variable* function_var = |
407 new Variable(this, name, CONST, true, Variable::NORMAL); | 407 new Variable(this, name, mode, true, Variable::NORMAL); |
408 function_ = new(isolate_->zone()) VariableProxy(isolate_, function_var); | 408 function_ = new(isolate_->zone()) VariableProxy(isolate_, function_var); |
409 return function_var; | 409 return function_var; |
410 } | 410 } |
411 | 411 |
412 | 412 |
413 void Scope::DeclareParameter(Handle<String> name, VariableMode mode) { | 413 void Scope::DeclareParameter(Handle<String> name, VariableMode mode) { |
414 ASSERT(!already_resolved()); | 414 ASSERT(!already_resolved()); |
415 ASSERT(is_function_scope()); | 415 ASSERT(is_function_scope()); |
416 Variable* var = | 416 Variable* var = |
417 variables_.Declare(this, name, mode, true, Variable::NORMAL); | 417 variables_.Declare(this, name, mode, true, Variable::NORMAL); |
418 params_.Add(var); | 418 params_.Add(var); |
419 } | 419 } |
420 | 420 |
421 | 421 |
422 Variable* Scope::DeclareLocal(Handle<String> name, VariableMode mode) { | 422 Variable* Scope::DeclareLocal(Handle<String> name, VariableMode mode) { |
423 ASSERT(!already_resolved()); | 423 ASSERT(!already_resolved()); |
424 // This function handles VAR and CONST modes. DYNAMIC variables are | 424 // This function handles VAR and CONST modes. DYNAMIC variables are |
425 // introduces during variable allocation, INTERNAL variables are allocated | 425 // introduces during variable allocation, INTERNAL variables are allocated |
426 // explicitly, and TEMPORARY variables are allocated via NewTemporary(). | 426 // explicitly, and TEMPORARY variables are allocated via NewTemporary(). |
427 ASSERT(mode == VAR || mode == CONST || mode == LET); | 427 ASSERT(mode == VAR || |
| 428 mode == CONST || |
| 429 mode == CONST_HARMONY || |
| 430 mode == LET); |
428 ++num_var_or_const_; | 431 ++num_var_or_const_; |
429 return variables_.Declare(this, name, mode, true, Variable::NORMAL); | 432 return variables_.Declare(this, name, mode, true, Variable::NORMAL); |
430 } | 433 } |
431 | 434 |
432 | 435 |
433 Variable* Scope::DeclareGlobal(Handle<String> name) { | 436 Variable* Scope::DeclareGlobal(Handle<String> name) { |
434 ASSERT(is_global_scope()); | 437 ASSERT(is_global_scope()); |
435 return variables_.Declare(this, name, DYNAMIC_GLOBAL, | 438 return variables_.Declare(this, name, DYNAMIC_GLOBAL, |
436 true, | 439 true, |
437 Variable::NORMAL); | 440 Variable::NORMAL); |
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1156 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && | 1159 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && |
1157 !must_have_local_context) { | 1160 !must_have_local_context) { |
1158 num_heap_slots_ = 0; | 1161 num_heap_slots_ = 0; |
1159 } | 1162 } |
1160 | 1163 |
1161 // Allocation done. | 1164 // Allocation done. |
1162 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); | 1165 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); |
1163 } | 1166 } |
1164 | 1167 |
1165 } } // namespace v8::internal | 1168 } } // namespace v8::internal |
OLD | NEW |