| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_CONTEXTS_H_ | 5 #ifndef V8_CONTEXTS_H_ |
| 6 #define V8_CONTEXTS_H_ | 6 #define V8_CONTEXTS_H_ |
| 7 | 7 |
| 8 #include "src/heap/heap.h" | 8 #include "src/heap/heap.h" |
| 9 #include "src/objects.h" | 9 #include "src/objects.h" |
| 10 | 10 |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 // function contexts, and non-NULL for 'with' contexts. | 292 // function contexts, and non-NULL for 'with' contexts. |
| 293 // Used to implement the 'with' statement. | 293 // Used to implement the 'with' statement. |
| 294 // | 294 // |
| 295 // [ extension ] A pointer to an extension JSObject, or NULL. Used to | 295 // [ extension ] A pointer to an extension JSObject, or NULL. Used to |
| 296 // implement 'with' statements and dynamic declarations | 296 // implement 'with' statements and dynamic declarations |
| 297 // (through 'eval'). The object in a 'with' statement is | 297 // (through 'eval'). The object in a 'with' statement is |
| 298 // stored in the extension slot of a 'with' context. | 298 // stored in the extension slot of a 'with' context. |
| 299 // Dynamically declared variables/functions are also added | 299 // Dynamically declared variables/functions are also added |
| 300 // to lazily allocated extension object. Context::Lookup | 300 // to lazily allocated extension object. Context::Lookup |
| 301 // searches the extension object for properties. | 301 // searches the extension object for properties. |
| 302 // For global and block contexts, contains the respective | 302 // For script and block contexts, contains the respective |
| 303 // ScopeInfo. | 303 // ScopeInfo. For block contexts representing sloppy declaration |
| 304 // block scopes, it may also be a struct being a |
| 305 // SloppyBlockWithEvalContextExtension, pairing the ScopeInfo |
| 306 // with an extension object. |
| 304 // For module contexts, points back to the respective JSModule. | 307 // For module contexts, points back to the respective JSModule. |
| 305 // | 308 // |
| 306 // [ global_object ] A pointer to the global object. Provided for quick | 309 // [ global_object ] A pointer to the global object. Provided for quick |
| 307 // access to the global object from inside the code (since | 310 // access to the global object from inside the code (since |
| 308 // we always have a context pointer). | 311 // we always have a context pointer). |
| 309 // | 312 // |
| 310 // In addition, function contexts may have statically allocated context slots | 313 // In addition, function contexts may have statically allocated context slots |
| 311 // to store local variables/functions that are accessed from inner functions | 314 // to store local variables/functions that are accessed from inner functions |
| 312 // (via static context addresses) or through 'eval' (dynamic context lookups). | 315 // (via static context addresses) or through 'eval' (dynamic context lookups). |
| 313 // The native context contains additional slots for fast access to native | 316 // The native context contains additional slots for fast access to native |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 JSFunction* closure() { return JSFunction::cast(get(CLOSURE_INDEX)); } | 366 JSFunction* closure() { return JSFunction::cast(get(CLOSURE_INDEX)); } |
| 364 void set_closure(JSFunction* closure) { set(CLOSURE_INDEX, closure); } | 367 void set_closure(JSFunction* closure) { set(CLOSURE_INDEX, closure); } |
| 365 | 368 |
| 366 Context* previous() { | 369 Context* previous() { |
| 367 Object* result = unchecked_previous(); | 370 Object* result = unchecked_previous(); |
| 368 DCHECK(IsBootstrappingOrValidParentContext(result, this)); | 371 DCHECK(IsBootstrappingOrValidParentContext(result, this)); |
| 369 return reinterpret_cast<Context*>(result); | 372 return reinterpret_cast<Context*>(result); |
| 370 } | 373 } |
| 371 void set_previous(Context* context) { set(PREVIOUS_INDEX, context); } | 374 void set_previous(Context* context) { set(PREVIOUS_INDEX, context); } |
| 372 | 375 |
| 373 bool has_extension() { return extension() != NULL; } | 376 bool has_extension() { return extension() != nullptr; } |
| 374 Object* extension() { return get(EXTENSION_INDEX); } | 377 Object* extension() { return get(EXTENSION_INDEX); } |
| 375 void set_extension(Object* object) { set(EXTENSION_INDEX, object); } | 378 void set_extension(Object* object) { set(EXTENSION_INDEX, object); } |
| 379 JSObject* extension_object(); |
| 380 JSReceiver* extension_receiver(); |
| 381 ScopeInfo* scope_info(); |
| 382 String* catch_name(); |
| 376 | 383 |
| 377 JSModule* module() { return JSModule::cast(get(EXTENSION_INDEX)); } | 384 JSModule* module() { return JSModule::cast(get(EXTENSION_INDEX)); } |
| 378 void set_module(JSModule* module) { set(EXTENSION_INDEX, module); } | 385 void set_module(JSModule* module) { set(EXTENSION_INDEX, module); } |
| 379 | 386 |
| 380 // Get the context where var declarations will be hoisted to, which | 387 // Get the context where var declarations will be hoisted to, which |
| 381 // may be the context itself. | 388 // may be the context itself. |
| 382 Context* declaration_context(); | 389 Context* declaration_context(); |
| 390 bool is_declaration_context(); |
| 383 | 391 |
| 384 GlobalObject* global_object() { | 392 GlobalObject* global_object() { |
| 385 Object* result = get(GLOBAL_OBJECT_INDEX); | 393 Object* result = get(GLOBAL_OBJECT_INDEX); |
| 386 DCHECK(IsBootstrappingOrGlobalObject(this->GetIsolate(), result)); | 394 DCHECK(IsBootstrappingOrGlobalObject(this->GetIsolate(), result)); |
| 387 return reinterpret_cast<GlobalObject*>(result); | 395 return reinterpret_cast<GlobalObject*>(result); |
| 388 } | 396 } |
| 389 void set_global_object(GlobalObject* object) { | 397 void set_global_object(GlobalObject* object) { |
| 390 set(GLOBAL_OBJECT_INDEX, object); | 398 set(GLOBAL_OBJECT_INDEX, object); |
| 391 } | 399 } |
| 392 | 400 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 static bool IsBootstrappingOrGlobalObject(Isolate* isolate, Object* object); | 557 static bool IsBootstrappingOrGlobalObject(Isolate* isolate, Object* object); |
| 550 #endif | 558 #endif |
| 551 | 559 |
| 552 STATIC_ASSERT(kHeaderSize == Internals::kContextHeaderSize); | 560 STATIC_ASSERT(kHeaderSize == Internals::kContextHeaderSize); |
| 553 STATIC_ASSERT(EMBEDDER_DATA_INDEX == Internals::kContextEmbedderDataIndex); | 561 STATIC_ASSERT(EMBEDDER_DATA_INDEX == Internals::kContextEmbedderDataIndex); |
| 554 }; | 562 }; |
| 555 | 563 |
| 556 } } // namespace v8::internal | 564 } } // namespace v8::internal |
| 557 | 565 |
| 558 #endif // V8_CONTEXTS_H_ | 566 #endif // V8_CONTEXTS_H_ |
| OLD | NEW |