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

Side by Side Diff: src/scopes.cc

Issue 12673: Change implementation of eval to make an exact distinction between direct eva... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 12 years 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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 if (is_function_scope()) { 177 if (is_function_scope()) {
178 // Declare 'arguments' variable which exists in all functions. 178 // Declare 'arguments' variable which exists in all functions.
179 // Note that it may never be accessed, in which case it won't 179 // Note that it may never be accessed, in which case it won't
180 // be allocated during variable allocation. 180 // be allocated during variable allocation.
181 Declare(Factory::arguments_symbol(), Variable::VAR); 181 Declare(Factory::arguments_symbol(), Variable::VAR);
182 } 182 }
183 } 183 }
184 184
185 185
186 186
187 Variable* Scope::LookupLocal(Handle<String> name) {
188 return locals_.Lookup(name);
189 }
190
191
187 Variable* Scope::Lookup(Handle<String> name) { 192 Variable* Scope::Lookup(Handle<String> name) {
188 return locals_.Lookup(name); 193 for (Scope* scope = this;
194 scope != NULL;
195 scope = scope->outer_scope()) {
196 Variable* var = scope->LookupLocal(name);
197 if (var != NULL) return var;
198 }
199 return NULL;
189 } 200 }
190 201
191 202
192 Variable* Scope::DeclareFunctionVar(Handle<String> name) { 203 Variable* Scope::DeclareFunctionVar(Handle<String> name) {
193 ASSERT(is_function_scope() && function_ == NULL); 204 ASSERT(is_function_scope() && function_ == NULL);
194 function_ = new Variable(this, name, Variable::CONST, true, false); 205 function_ = new Variable(this, name, Variable::CONST, true, false);
195 return function_; 206 return function_;
196 } 207 }
197 208
198 209
199 Variable* Scope::Declare(Handle<String> name, Variable::Mode mode) { 210 Variable* Scope::Declare(Handle<String> name, Variable::Mode mode) {
200 // DYNAMIC variables are introduces during variable allocation, 211 // DYNAMIC variables are introduces during variable allocation,
201 // INTERNAL variables are allocated explicitly, and TEMPORARY 212 // INTERNAL variables are allocated explicitly, and TEMPORARY
202 // variables are allocated via NewTemporary(). 213 // variables are allocated via NewTemporary().
203 ASSERT(mode == Variable::VAR || mode == Variable::CONST); 214 ASSERT(mode == Variable::VAR || mode == Variable::CONST);
204 return locals_.Declare(this, name, mode, true, false); 215 return locals_.Declare(this, name, mode, true, false);
205 } 216 }
206 217
207 218
208 void Scope::AddParameter(Variable* var) { 219 void Scope::AddParameter(Variable* var) {
209 ASSERT(is_function_scope()); 220 ASSERT(is_function_scope());
210 ASSERT(Lookup(var->name()) == var); 221 ASSERT(LookupLocal(var->name()) == var);
211 params_.Add(var); 222 params_.Add(var);
212 } 223 }
213 224
214 225
215 VariableProxy* Scope::NewUnresolved(Handle<String> name, bool inside_with) { 226 VariableProxy* Scope::NewUnresolved(Handle<String> name, bool inside_with) {
216 // Note that we must not share the unresolved variables with 227 // Note that we must not share the unresolved variables with
217 // the same name because they may be removed selectively via 228 // the same name because they may be removed selectively via
218 // RemoveUnresolved(). 229 // RemoveUnresolved().
219 VariableProxy* proxy = new VariableProxy(name, false, inside_with); 230 VariableProxy* proxy = new VariableProxy(name, false, inside_with);
220 unresolved_.Add(proxy); 231 unresolved_.Add(proxy);
(...skipping 30 matching lines...) Expand all
251 void Scope::SetIllegalRedeclaration(Expression* expression) { 262 void Scope::SetIllegalRedeclaration(Expression* expression) {
252 // Only set the illegal redeclaration expression the 263 // Only set the illegal redeclaration expression the
253 // first time the function is called. 264 // first time the function is called.
254 if (!HasIllegalRedeclaration()) { 265 if (!HasIllegalRedeclaration()) {
255 illegal_redecl_ = expression; 266 illegal_redecl_ = expression;
256 } 267 }
257 ASSERT(HasIllegalRedeclaration()); 268 ASSERT(HasIllegalRedeclaration());
258 } 269 }
259 270
260 271
261 void Scope::VisitIllegalRedeclaration(Visitor* visitor) { 272 void Scope::VisitIllegalRedeclaration(AstVisitor* visitor) {
262 ASSERT(HasIllegalRedeclaration()); 273 ASSERT(HasIllegalRedeclaration());
263 illegal_redecl_->Accept(visitor); 274 illegal_redecl_->Accept(visitor);
264 } 275 }
265 276
266 277
267 template<class Allocator> 278 template<class Allocator>
268 void Scope::CollectUsedVariables(List<Variable*, Allocator>* locals) { 279 void Scope::CollectUsedVariables(List<Variable*, Allocator>* locals) {
269 // Collect variables in this scope. 280 // Collect variables in this scope.
270 // Note that the function_ variable - if present - is not 281 // Note that the function_ variable - if present - is not
271 // collected here but handled separately in ScopeInfo 282 // collected here but handled separately in ScopeInfo
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 // variable that is introduced dynamically via an 'eval' call or a 'with' 517 // variable that is introduced dynamically via an 'eval' call or a 'with'
507 // statement). 518 // statement).
508 Variable* Scope::LookupRecursive(Handle<String> name, bool inner_lookup) { 519 Variable* Scope::LookupRecursive(Handle<String> name, bool inner_lookup) {
509 // If we find a variable, but the current scope calls 'eval', the found 520 // If we find a variable, but the current scope calls 'eval', the found
510 // variable may not be the correct one (the 'eval' may introduce a 521 // variable may not be the correct one (the 'eval' may introduce a
511 // property with the same name). In that case, remember that the variable 522 // property with the same name). In that case, remember that the variable
512 // found is just a guess. 523 // found is just a guess.
513 bool guess = scope_calls_eval_; 524 bool guess = scope_calls_eval_;
514 525
515 // Try to find the variable in this scope. 526 // Try to find the variable in this scope.
516 Variable* var = Lookup(name); 527 Variable* var = LookupLocal(name);
517 528
518 if (var != NULL) { 529 if (var != NULL) {
519 // We found a variable. If this is not an inner lookup, we are done. 530 // We found a variable. If this is not an inner lookup, we are done.
520 // (Even if there is an 'eval' in this scope which introduces the 531 // (Even if there is an 'eval' in this scope which introduces the
521 // same variable again, the resulting variable remains the same. 532 // same variable again, the resulting variable remains the same.
522 // Note that enclosing 'with' statements are handled at the call site.) 533 // Note that enclosing 'with' statements are handled at the call site.)
523 if (!inner_lookup) 534 if (!inner_lookup)
524 return var; 535 return var;
525 536
526 } else { 537 } else {
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 } 711 }
701 712
702 713
703 void Scope::AllocateHeapSlot(Variable* var) { 714 void Scope::AllocateHeapSlot(Variable* var) {
704 var->rewrite_ = new Slot(var, Slot::CONTEXT, num_heap_slots_++); 715 var->rewrite_ = new Slot(var, Slot::CONTEXT, num_heap_slots_++);
705 } 716 }
706 717
707 718
708 void Scope::AllocateParameterLocals() { 719 void Scope::AllocateParameterLocals() {
709 ASSERT(is_function_scope()); 720 ASSERT(is_function_scope());
710 Variable* arguments = Lookup(Factory::arguments_symbol()); 721 Variable* arguments = LookupLocal(Factory::arguments_symbol());
711 ASSERT(arguments != NULL); // functions have 'arguments' declared implicitly 722 ASSERT(arguments != NULL); // functions have 'arguments' declared implicitly
712 if (MustAllocate(arguments) && !HasArgumentsParameter()) { 723 if (MustAllocate(arguments) && !HasArgumentsParameter()) {
713 // 'arguments' is used. Unless there is also a parameter called 724 // 'arguments' is used. Unless there is also a parameter called
714 // 'arguments', we must be conservative and access all parameters via 725 // 'arguments', we must be conservative and access all parameters via
715 // the arguments object: The i'th parameter is rewritten into 726 // the arguments object: The i'th parameter is rewritten into
716 // '.arguments[i]' (*). If we have a parameter named 'arguments', a 727 // '.arguments[i]' (*). If we have a parameter named 'arguments', a
717 // (new) value is always assigned to it via the function 728 // (new) value is always assigned to it via the function
718 // invocation. Then 'arguments' denotes that specific parameter value 729 // invocation. Then 'arguments' denotes that specific parameter value
719 // and cannot be used to access the parameters, which is why we don't 730 // and cannot be used to access the parameters, which is why we don't
720 // need to rewrite in that case. 731 // need to rewrite in that case.
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && 897 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS &&
887 !must_have_local_context) { 898 !must_have_local_context) {
888 num_heap_slots_ = 0; 899 num_heap_slots_ = 0;
889 } 900 }
890 901
891 // Allocation done. 902 // Allocation done.
892 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); 903 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS);
893 } 904 }
894 905
895 } } // namespace v8::internal 906 } } // namespace v8::internal
OLDNEW
« src/codegen-ia32.cc ('K') | « src/scopes.h ('k') | src/usage-analyzer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698