OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 // [ extension ] A pointer to an extension JSObject, or NULL. Used to | 186 // [ extension ] A pointer to an extension JSObject, or NULL. Used to |
187 // implement 'with' statements and dynamic declarations | 187 // implement 'with' statements and dynamic declarations |
188 // (through 'eval'). The object in a 'with' statement is | 188 // (through 'eval'). The object in a 'with' statement is |
189 // stored in the extension slot of a 'with' context. | 189 // stored in the extension slot of a 'with' context. |
190 // Dynamically declared variables/functions are also added | 190 // Dynamically declared variables/functions are also added |
191 // to lazily allocated extension object. Context::Lookup | 191 // to lazily allocated extension object. Context::Lookup |
192 // searches the extension object for properties. | 192 // searches the extension object for properties. |
193 // For block contexts, contains the respective ScopeInfo. | 193 // For block contexts, contains the respective ScopeInfo. |
194 // For module contexts, points back to the respective JSModule. | 194 // For module contexts, points back to the respective JSModule. |
195 // | 195 // |
196 // [ global ] A pointer to the global object. Provided for quick | 196 // [ global_object ] A pointer to the global object. Provided for quick |
197 // access to the global object from inside the code (since | 197 // access to the global object from inside the code (since |
198 // we always have a context pointer). | 198 // we always have a context pointer). |
199 // | 199 // |
200 // In addition, function contexts may have statically allocated context slots | 200 // In addition, function contexts may have statically allocated context slots |
201 // to store local variables/functions that are accessed from inner functions | 201 // to store local variables/functions that are accessed from inner functions |
202 // (via static context addresses) or through 'eval' (dynamic context lookups). | 202 // (via static context addresses) or through 'eval' (dynamic context lookups). |
203 // Finally, the native context contains additional slots for fast access to | 203 // Finally, the native context contains additional slots for fast access to |
204 // native properties. | 204 // native properties. |
205 | 205 |
206 class Context: public FixedArray { | 206 class Context: public FixedArray { |
207 public: | 207 public: |
208 // Conversions. | 208 // Conversions. |
209 static Context* cast(Object* context) { | 209 static Context* cast(Object* context) { |
210 ASSERT(context->IsContext()); | 210 ASSERT(context->IsContext()); |
211 return reinterpret_cast<Context*>(context); | 211 return reinterpret_cast<Context*>(context); |
212 } | 212 } |
213 | 213 |
214 // The default context slot layout; indices are FixedArray slot indices. | 214 // The default context slot layout; indices are FixedArray slot indices. |
215 enum { | 215 enum { |
216 // These slots are in all contexts. | 216 // These slots are in all contexts. |
217 CLOSURE_INDEX, | 217 CLOSURE_INDEX, |
218 PREVIOUS_INDEX, | 218 PREVIOUS_INDEX, |
219 // The extension slot is used for either the global object (in global | 219 // The extension slot is used for either the global object (in global |
220 // contexts), eval extension object (function contexts), subject of with | 220 // contexts), eval extension object (function contexts), subject of with |
221 // (with contexts), or the variable name (catch contexts), the serialized | 221 // (with contexts), or the variable name (catch contexts), the serialized |
222 // scope info (block contexts), or the module instance (module contexts). | 222 // scope info (block contexts), or the module instance (module contexts). |
223 EXTENSION_INDEX, | 223 EXTENSION_INDEX, |
224 GLOBAL_INDEX, | 224 GLOBAL_OBJECT_INDEX, |
225 MIN_CONTEXT_SLOTS, | 225 MIN_CONTEXT_SLOTS, |
226 | 226 |
227 // This slot holds the thrown value in catch contexts. | 227 // This slot holds the thrown value in catch contexts. |
228 THROWN_OBJECT_INDEX = MIN_CONTEXT_SLOTS, | 228 THROWN_OBJECT_INDEX = MIN_CONTEXT_SLOTS, |
229 | 229 |
230 // These slots are only in native contexts. | 230 // These slots are only in native contexts. |
231 GLOBAL_PROXY_INDEX = MIN_CONTEXT_SLOTS, | 231 GLOBAL_PROXY_INDEX = MIN_CONTEXT_SLOTS, |
232 SECURITY_TOKEN_INDEX, | 232 SECURITY_TOKEN_INDEX, |
233 ARGUMENTS_BOILERPLATE_INDEX, | 233 ARGUMENTS_BOILERPLATE_INDEX, |
234 ALIASED_ARGUMENTS_BOILERPLATE_INDEX, | 234 ALIASED_ARGUMENTS_BOILERPLATE_INDEX, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 Object* extension() { return get(EXTENSION_INDEX); } | 314 Object* extension() { return get(EXTENSION_INDEX); } |
315 void set_extension(Object* object) { set(EXTENSION_INDEX, object); } | 315 void set_extension(Object* object) { set(EXTENSION_INDEX, object); } |
316 | 316 |
317 JSModule* module() { return JSModule::cast(get(EXTENSION_INDEX)); } | 317 JSModule* module() { return JSModule::cast(get(EXTENSION_INDEX)); } |
318 void set_module(JSModule* module) { set(EXTENSION_INDEX, module); } | 318 void set_module(JSModule* module) { set(EXTENSION_INDEX, module); } |
319 | 319 |
320 // Get the context where var declarations will be hoisted to, which | 320 // Get the context where var declarations will be hoisted to, which |
321 // may be the context itself. | 321 // may be the context itself. |
322 Context* declaration_context(); | 322 Context* declaration_context(); |
323 | 323 |
324 GlobalObject* global() { | 324 GlobalObject* global_object() { |
325 Object* result = get(GLOBAL_INDEX); | 325 Object* result = get(GLOBAL_OBJECT_INDEX); |
326 ASSERT(IsBootstrappingOrGlobalObject(result)); | 326 ASSERT(IsBootstrappingOrGlobalObject(result)); |
327 return reinterpret_cast<GlobalObject*>(result); | 327 return reinterpret_cast<GlobalObject*>(result); |
328 } | 328 } |
329 void set_global(GlobalObject* global) { set(GLOBAL_INDEX, global); } | 329 void set_global_object(GlobalObject* object) { |
| 330 set(GLOBAL_OBJECT_INDEX, object); |
| 331 } |
330 | 332 |
331 // Returns a JSGlobalProxy object or null. | 333 // Returns a JSGlobalProxy object or null. |
332 JSObject* global_proxy(); | 334 JSObject* global_proxy(); |
333 void set_global_proxy(JSObject* global); | 335 void set_global_proxy(JSObject* global); |
334 | 336 |
335 // The builtins object. | 337 // The builtins object. |
336 JSBuiltinsObject* builtins(); | 338 JSBuiltinsObject* builtins(); |
337 | 339 |
338 // Compute the native context by traversing the context chain. | 340 // Compute the native context by traversing the context chain. |
339 Context* native_context(); | 341 Context* native_context(); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 #ifdef DEBUG | 434 #ifdef DEBUG |
433 // Bootstrapping-aware type checks. | 435 // Bootstrapping-aware type checks. |
434 static bool IsBootstrappingOrValidParentContext(Object* object, Context* kid); | 436 static bool IsBootstrappingOrValidParentContext(Object* object, Context* kid); |
435 static bool IsBootstrappingOrGlobalObject(Object* object); | 437 static bool IsBootstrappingOrGlobalObject(Object* object); |
436 #endif | 438 #endif |
437 }; | 439 }; |
438 | 440 |
439 } } // namespace v8::internal | 441 } } // namespace v8::internal |
440 | 442 |
441 #endif // V8_CONTEXTS_H_ | 443 #endif // V8_CONTEXTS_H_ |
OLD | NEW |