diff options
Diffstat (limited to 'deps/v8/src/contexts.h')
-rw-r--r-- | deps/v8/src/contexts.h | 64 |
1 files changed, 38 insertions, 26 deletions
diff --git a/deps/v8/src/contexts.h b/deps/v8/src/contexts.h index d154b82ca..cfc576cec 100644 --- a/deps/v8/src/contexts.h +++ b/deps/v8/src/contexts.h @@ -96,7 +96,7 @@ enum BindingFlags { // must always be allocated via Heap::AllocateContext() or // Factory::NewContext. -#define GLOBAL_CONTEXT_FIELDS(V) \ +#define NATIVE_CONTEXT_FIELDS(V) \ V(GLOBAL_PROXY_INDEX, JSObject, global_proxy_object) \ V(SECURITY_TOKEN_INDEX, Object, security_token) \ V(BOOLEAN_FUNCTION_INDEX, JSFunction, boolean_function) \ @@ -190,16 +190,19 @@ enum BindingFlags { // Dynamically declared variables/functions are also added // to lazily allocated extension object. Context::Lookup // searches the extension object for properties. +// For global and block contexts, contains the respective +// ScopeInfo. +// For module contexts, points back to the respective JSModule. // -// [ global ] A pointer to the global object. Provided for quick +// [ global_object ] A pointer to the global object. Provided for quick // access to the global object from inside the code (since // we always have a context pointer). // // In addition, function contexts may have statically allocated context slots // to store local variables/functions that are accessed from inner functions // (via static context addresses) or through 'eval' (dynamic context lookups). -// Finally, the global context contains additional slots for fast access to -// global properties. +// Finally, the native context contains additional slots for fast access to +// native properties. class Context: public FixedArray { public: @@ -217,15 +220,15 @@ class Context: public FixedArray { // The extension slot is used for either the global object (in global // contexts), eval extension object (function contexts), subject of with // (with contexts), or the variable name (catch contexts), the serialized - // scope info (block contexts). + // scope info (block contexts), or the module instance (module contexts). EXTENSION_INDEX, - GLOBAL_INDEX, + GLOBAL_OBJECT_INDEX, MIN_CONTEXT_SLOTS, // This slot holds the thrown value in catch contexts. THROWN_OBJECT_INDEX = MIN_CONTEXT_SLOTS, - // These slots are only in global contexts. + // These slots are only in native contexts. GLOBAL_PROXY_INDEX = MIN_CONTEXT_SLOTS, SECURITY_TOKEN_INDEX, ARGUMENTS_BOILERPLATE_INDEX, @@ -292,7 +295,7 @@ class Context: public FixedArray { NEXT_CONTEXT_LINK, // Weak. // Total number of slots. - GLOBAL_CONTEXT_SLOTS, + NATIVE_CONTEXT_SLOTS, FIRST_WEAK_SLOT = OPTIMIZED_FUNCTIONS_LIST }; @@ -303,7 +306,7 @@ class Context: public FixedArray { Context* previous() { Object* result = unchecked_previous(); - ASSERT(IsBootstrappingOrContext(result)); + ASSERT(IsBootstrappingOrValidParentContext(result, this)); return reinterpret_cast<Context*>(result); } void set_previous(Context* context) { set(PREVIOUS_INDEX, context); } @@ -312,16 +315,21 @@ class Context: public FixedArray { Object* extension() { return get(EXTENSION_INDEX); } void set_extension(Object* object) { set(EXTENSION_INDEX, object); } + JSModule* module() { return JSModule::cast(get(EXTENSION_INDEX)); } + void set_module(JSModule* module) { set(EXTENSION_INDEX, module); } + // Get the context where var declarations will be hoisted to, which // may be the context itself. Context* declaration_context(); - GlobalObject* global() { - Object* result = get(GLOBAL_INDEX); + GlobalObject* global_object() { + Object* result = get(GLOBAL_OBJECT_INDEX); ASSERT(IsBootstrappingOrGlobalObject(result)); return reinterpret_cast<GlobalObject*>(result); } - void set_global(GlobalObject* global) { set(GLOBAL_INDEX, global); } + void set_global_object(GlobalObject* object) { + set(GLOBAL_OBJECT_INDEX, object); + } // Returns a JSGlobalProxy object or null. JSObject* global_proxy(); @@ -330,11 +338,11 @@ class Context: public FixedArray { // The builtins object. JSBuiltinsObject* builtins(); - // Compute the global context by traversing the context chain. - Context* global_context(); + // Compute the native context by traversing the context chain. + Context* native_context(); - // Predicates for context types. IsGlobalContext is defined on Object - // because we frequently have to know if arbitrary objects are global + // Predicates for context types. IsNativeContext is defined on Object + // because we frequently have to know if arbitrary objects are natives // contexts. bool IsFunctionContext() { Map* map = this->map(); @@ -356,30 +364,34 @@ class Context: public FixedArray { Map* map = this->map(); return map == map->GetHeap()->module_context_map(); } + bool IsGlobalContext() { + Map* map = this->map(); + return map == map->GetHeap()->global_context_map(); + } - // Tells whether the global context is marked with out of memory. + // Tells whether the native context is marked with out of memory. inline bool has_out_of_memory(); - // Mark the global context with out of memory. + // Mark the native context with out of memory. inline void mark_out_of_memory(); - // A global context hold a list of all functions which have been optimized. + // A native context hold a list of all functions which have been optimized. void AddOptimizedFunction(JSFunction* function); void RemoveOptimizedFunction(JSFunction* function); Object* OptimizedFunctionsListHead(); void ClearOptimizedFunctions(); -#define GLOBAL_CONTEXT_FIELD_ACCESSORS(index, type, name) \ +#define NATIVE_CONTEXT_FIELD_ACCESSORS(index, type, name) \ void set_##name(type* value) { \ - ASSERT(IsGlobalContext()); \ + ASSERT(IsNativeContext()); \ set(index, value); \ } \ type* name() { \ - ASSERT(IsGlobalContext()); \ + ASSERT(IsNativeContext()); \ return type::cast(get(index)); \ } - GLOBAL_CONTEXT_FIELDS(GLOBAL_CONTEXT_FIELD_ACCESSORS) -#undef GLOBAL_CONTEXT_FIELD_ACCESSORS + NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_FIELD_ACCESSORS) +#undef NATIVE_CONTEXT_FIELD_ACCESSORS // Lookup the slot called name, starting with the current context. // There are three possibilities: @@ -409,7 +421,7 @@ class Context: public FixedArray { return kHeaderSize + index * kPointerSize - kHeapObjectTag; } - static const int kSize = kHeaderSize + GLOBAL_CONTEXT_SLOTS * kPointerSize; + static const int kSize = kHeaderSize + NATIVE_CONTEXT_SLOTS * kPointerSize; // GC support. typedef FixedBodyDescriptor< @@ -426,7 +438,7 @@ class Context: public FixedArray { #ifdef DEBUG // Bootstrapping-aware type checks. - static bool IsBootstrappingOrContext(Object* object); + static bool IsBootstrappingOrValidParentContext(Object* object, Context* kid); static bool IsBootstrappingOrGlobalObject(Object* object); #endif }; |