OLD | NEW |
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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 } while (follow_context_chain); | 191 } while (follow_context_chain); |
192 | 192 |
193 // slot not found | 193 // slot not found |
194 if (FLAG_trace_contexts) { | 194 if (FLAG_trace_contexts) { |
195 PrintF("=> no property/slot found\n"); | 195 PrintF("=> no property/slot found\n"); |
196 } | 196 } |
197 return Handle<Object>::null(); | 197 return Handle<Object>::null(); |
198 } | 198 } |
199 | 199 |
200 | 200 |
| 201 bool Context::GlobalIfNotShadowedByEval(Handle<String> name) { |
| 202 Context* context = this; |
| 203 |
| 204 // Check that there is no local with the given name in contexts |
| 205 // before the global context and check that there are no context |
| 206 // extension objects (conservative check for with statements). |
| 207 while (!context->IsGlobalContext()) { |
| 208 // Check if the context is a potentially a with context. |
| 209 if (context->has_extension()) return false; |
| 210 |
| 211 // Not a with context so it must be a function context. |
| 212 ASSERT(context->is_function_context()); |
| 213 |
| 214 // Check non-parameter locals. |
| 215 Handle<Code> code(context->closure()->code()); |
| 216 Variable::Mode mode; |
| 217 int index = ScopeInfo<>::ContextSlotIndex(*code, *name, &mode); |
| 218 ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS); |
| 219 if (index >= 0) return false; |
| 220 |
| 221 // Check parameter locals. |
| 222 int param_index = ScopeInfo<>::ParameterIndex(*code, *name); |
| 223 if (param_index >= 0) return false; |
| 224 |
| 225 // Check context only holding the function name variable. |
| 226 index = ScopeInfo<>::FunctionContextSlotIndex(*code, *name); |
| 227 if (index >= 0) return false; |
| 228 context = Context::cast(context->closure()->context()); |
| 229 } |
| 230 |
| 231 // No local or potential with statement found so the variable is |
| 232 // global unless it is shadowed by an eval-introduced variable. |
| 233 return true; |
| 234 } |
| 235 |
| 236 |
201 #ifdef DEBUG | 237 #ifdef DEBUG |
202 bool Context::IsBootstrappingOrContext(Object* object) { | 238 bool Context::IsBootstrappingOrContext(Object* object) { |
203 // During bootstrapping we allow all objects to pass as | 239 // During bootstrapping we allow all objects to pass as |
204 // contexts. This is necessary to fix circular dependencies. | 240 // contexts. This is necessary to fix circular dependencies. |
205 return Bootstrapper::IsActive() || object->IsContext(); | 241 return Bootstrapper::IsActive() || object->IsContext(); |
206 } | 242 } |
207 | 243 |
208 | 244 |
209 bool Context::IsBootstrappingOrGlobalObject(Object* object) { | 245 bool Context::IsBootstrappingOrGlobalObject(Object* object) { |
210 // During bootstrapping we allow all objects to pass as global | 246 // During bootstrapping we allow all objects to pass as global |
211 // objects. This is necessary to fix circular dependencies. | 247 // objects. This is necessary to fix circular dependencies. |
212 return Bootstrapper::IsActive() || object->IsGlobalObject(); | 248 return Bootstrapper::IsActive() || object->IsGlobalObject(); |
213 } | 249 } |
214 #endif | 250 #endif |
215 | 251 |
216 } } // namespace v8::internal | 252 } } // namespace v8::internal |
OLD | NEW |