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

Side by Side Diff: src/scopes.cc

Issue 7992005: Block scoped const variables. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased. 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
« src/parser.cc ('K') | « src/scopes.h ('k') | src/token.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 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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 369
370 // Check context slot lookup. 370 // Check context slot lookup.
371 VariableMode mode; 371 VariableMode mode;
372 int index = scope_info_->ContextSlotIndex(*name, &mode); 372 int index = scope_info_->ContextSlotIndex(*name, &mode);
373 if (index < 0) { 373 if (index < 0) {
374 // Check parameters. 374 // Check parameters.
375 mode = VAR; 375 mode = VAR;
376 index = scope_info_->ParameterIndex(*name); 376 index = scope_info_->ParameterIndex(*name);
377 if (index < 0) { 377 if (index < 0) {
378 // Check the function name. 378 // Check the function name.
379 index = scope_info_->FunctionContextSlotIndex(*name); 379 index = scope_info_->FunctionContextSlotIndex(*name, NULL);
380 if (index < 0) return NULL; 380 if (index < 0) return NULL;
381 } 381 }
382 } 382 }
383 383
384 Variable* var = 384 Variable* var =
385 variables_.Declare(this, name, mode, true, Variable::NORMAL); 385 variables_.Declare(this, name, mode, true, Variable::NORMAL);
386 var->AllocateTo(Variable::CONTEXT, index); 386 var->AllocateTo(Variable::CONTEXT, index);
387 return var; 387 return var;
388 } 388 }
389 389
390 390
391 Variable* Scope::Lookup(Handle<String> name) { 391 Variable* Scope::Lookup(Handle<String> name) {
392 for (Scope* scope = this; 392 for (Scope* scope = this;
393 scope != NULL; 393 scope != NULL;
394 scope = scope->outer_scope()) { 394 scope = scope->outer_scope()) {
395 Variable* var = scope->LocalLookup(name); 395 Variable* var = scope->LocalLookup(name);
396 if (var != NULL) return var; 396 if (var != NULL) return var;
397 } 397 }
398 return NULL; 398 return NULL;
399 } 399 }
400 400
401 401
402 Variable* Scope::DeclareFunctionVar(Handle<String> name) { 402 Variable* Scope::DeclareFunctionVar(Handle<String> name, VariableMode mode) {
403 ASSERT(is_function_scope() && function_ == NULL); 403 ASSERT(is_function_scope() && function_ == NULL);
404 Variable* function_var = 404 Variable* function_var =
405 new Variable(this, name, CONST, true, Variable::NORMAL); 405 new Variable(this, name, mode, true, Variable::NORMAL);
406 function_ = new(isolate_->zone()) VariableProxy(isolate_, function_var); 406 function_ = new(isolate_->zone()) VariableProxy(isolate_, function_var);
407 return function_var; 407 return function_var;
408 } 408 }
409 409
410 410
411 void Scope::DeclareParameter(Handle<String> name, VariableMode mode) { 411 void Scope::DeclareParameter(Handle<String> name, VariableMode mode) {
412 ASSERT(!already_resolved()); 412 ASSERT(!already_resolved());
413 ASSERT(is_function_scope()); 413 ASSERT(is_function_scope());
414 Variable* var = 414 Variable* var =
415 variables_.Declare(this, name, mode, true, Variable::NORMAL); 415 variables_.Declare(this, name, mode, true, Variable::NORMAL);
416 params_.Add(var); 416 params_.Add(var);
417 } 417 }
418 418
419 419
420 Variable* Scope::DeclareLocal(Handle<String> name, VariableMode mode) { 420 Variable* Scope::DeclareLocal(Handle<String> name, VariableMode mode) {
421 ASSERT(!already_resolved()); 421 ASSERT(!already_resolved());
422 // This function handles VAR and CONST modes. DYNAMIC variables are 422 // This function handles VAR and CONST modes. DYNAMIC variables are
423 // introduces during variable allocation, INTERNAL variables are allocated 423 // introduces during variable allocation, INTERNAL variables are allocated
424 // explicitly, and TEMPORARY variables are allocated via NewTemporary(). 424 // explicitly, and TEMPORARY variables are allocated via NewTemporary().
425 ASSERT(mode == VAR || mode == CONST || mode == LET); 425 ASSERT(mode == VAR ||
426 mode == CONST ||
427 mode == CONST_HARMONY ||
428 mode == LET);
426 ++num_var_or_const_; 429 ++num_var_or_const_;
427 return variables_.Declare(this, name, mode, true, Variable::NORMAL); 430 return variables_.Declare(this, name, mode, true, Variable::NORMAL);
428 } 431 }
429 432
430 433
431 Variable* Scope::DeclareGlobal(Handle<String> name) { 434 Variable* Scope::DeclareGlobal(Handle<String> name) {
432 ASSERT(is_global_scope()); 435 ASSERT(is_global_scope());
433 return variables_.Declare(this, name, DYNAMIC_GLOBAL, 436 return variables_.Declare(this, name, DYNAMIC_GLOBAL,
434 true, 437 true,
435 Variable::NORMAL); 438 Variable::NORMAL);
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && 1139 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS &&
1137 !must_have_local_context) { 1140 !must_have_local_context) {
1138 num_heap_slots_ = 0; 1141 num_heap_slots_ = 0;
1139 } 1142 }
1140 1143
1141 // Allocation done. 1144 // Allocation done.
1142 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); 1145 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS);
1143 } 1146 }
1144 1147
1145 } } // namespace v8::internal 1148 } } // namespace v8::internal
OLDNEW
« src/parser.cc ('K') | « src/scopes.h ('k') | src/token.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698