| 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 native_object_notifier_perform_change) \ | 177 native_object_notifier_perform_change) \ |
| 178 V(SLOPPY_GENERATOR_FUNCTION_MAP_INDEX, Map, sloppy_generator_function_map) \ | 178 V(SLOPPY_GENERATOR_FUNCTION_MAP_INDEX, Map, sloppy_generator_function_map) \ |
| 179 V(STRICT_GENERATOR_FUNCTION_MAP_INDEX, Map, strict_generator_function_map) \ | 179 V(STRICT_GENERATOR_FUNCTION_MAP_INDEX, Map, strict_generator_function_map) \ |
| 180 V(GENERATOR_OBJECT_PROTOTYPE_MAP_INDEX, Map, generator_object_prototype_map) \ | 180 V(GENERATOR_OBJECT_PROTOTYPE_MAP_INDEX, Map, generator_object_prototype_map) \ |
| 181 V(ITERATOR_RESULT_MAP_INDEX, Map, iterator_result_map) \ | 181 V(ITERATOR_RESULT_MAP_INDEX, Map, iterator_result_map) \ |
| 182 V(MAP_ITERATOR_MAP_INDEX, Map, map_iterator_map) \ | 182 V(MAP_ITERATOR_MAP_INDEX, Map, map_iterator_map) \ |
| 183 V(SET_ITERATOR_MAP_INDEX, Map, set_iterator_map) \ | 183 V(SET_ITERATOR_MAP_INDEX, Map, set_iterator_map) \ |
| 184 V(ITERATOR_SYMBOL_INDEX, Symbol, iterator_symbol) \ | 184 V(ITERATOR_SYMBOL_INDEX, Symbol, iterator_symbol) \ |
| 185 V(UNSCOPABLES_SYMBOL_INDEX, Symbol, unscopables_symbol) \ | 185 V(UNSCOPABLES_SYMBOL_INDEX, Symbol, unscopables_symbol) \ |
| 186 V(ARRAY_VALUES_ITERATOR_INDEX, JSFunction, array_values_iterator) \ | 186 V(ARRAY_VALUES_ITERATOR_INDEX, JSFunction, array_values_iterator) \ |
| 187 V(GLOBAL_CONTEXT_TABLE_INDEX, GlobalContextTable, global_context_table) | 187 V(SCRIPT_CONTEXT_TABLE_INDEX, ScriptContextTable, script_context_table) |
| 188 | 188 |
| 189 | 189 |
| 190 // A table of all global contexts. Every loaded top-level script with top-level | 190 // A table of all script contexts. Every loaded top-level script with top-level |
| 191 // lexical declarations contributes its GlobalContext into this table. | 191 // lexical declarations contributes its ScriptContext into this table. |
| 192 // | 192 // |
| 193 // The table is a fixed array, its first slot is the current used count and | 193 // The table is a fixed array, its first slot is the current used count and |
| 194 // the subsequent slots 1..used contain GlobalContexts. | 194 // the subsequent slots 1..used contain ScriptContexts. |
| 195 class GlobalContextTable : public FixedArray { | 195 class ScriptContextTable : public FixedArray { |
| 196 public: | 196 public: |
| 197 // Conversions. | 197 // Conversions. |
| 198 static GlobalContextTable* cast(Object* context) { | 198 static ScriptContextTable* cast(Object* context) { |
| 199 DCHECK(context->IsGlobalContextTable()); | 199 DCHECK(context->IsScriptContextTable()); |
| 200 return reinterpret_cast<GlobalContextTable*>(context); | 200 return reinterpret_cast<ScriptContextTable*>(context); |
| 201 } | 201 } |
| 202 | 202 |
| 203 struct LookupResult { | 203 struct LookupResult { |
| 204 int context_index; | 204 int context_index; |
| 205 int slot_index; | 205 int slot_index; |
| 206 VariableMode mode; | 206 VariableMode mode; |
| 207 InitializationFlag init_flag; | 207 InitializationFlag init_flag; |
| 208 MaybeAssignedFlag maybe_assigned_flag; | 208 MaybeAssignedFlag maybe_assigned_flag; |
| 209 }; | 209 }; |
| 210 | 210 |
| 211 int used() const { return Smi::cast(get(kUsedSlot))->value(); } | 211 int used() const { return Smi::cast(get(kUsedSlot))->value(); } |
| 212 | 212 |
| 213 void set_used(int used) { set(kUsedSlot, Smi::FromInt(used)); } | 213 void set_used(int used) { set(kUsedSlot, Smi::FromInt(used)); } |
| 214 | 214 |
| 215 static Handle<Context> GetContext(Handle<GlobalContextTable> table, int i) { | 215 static Handle<Context> GetContext(Handle<ScriptContextTable> table, int i) { |
| 216 DCHECK(i < table->used()); | 216 DCHECK(i < table->used()); |
| 217 return Handle<Context>::cast(FixedArray::get(table, i + 1)); | 217 return Handle<Context>::cast(FixedArray::get(table, i + 1)); |
| 218 } | 218 } |
| 219 | 219 |
| 220 // Lookup a variable `name` in a GlobalContextTable. | 220 // Lookup a variable `name` in a ScriptContextTable. |
| 221 // If it returns true, the variable is found and `result` contains | 221 // If it returns true, the variable is found and `result` contains |
| 222 // valid information about its location. | 222 // valid information about its location. |
| 223 // If it returns false, `result` is untouched. | 223 // If it returns false, `result` is untouched. |
| 224 MUST_USE_RESULT | 224 MUST_USE_RESULT |
| 225 static bool Lookup(Handle<GlobalContextTable> table, Handle<String> name, | 225 static bool Lookup(Handle<ScriptContextTable> table, Handle<String> name, |
| 226 LookupResult* result); | 226 LookupResult* result); |
| 227 | 227 |
| 228 MUST_USE_RESULT | 228 MUST_USE_RESULT |
| 229 static Handle<GlobalContextTable> Extend(Handle<GlobalContextTable> table, | 229 static Handle<ScriptContextTable> Extend(Handle<ScriptContextTable> table, |
| 230 Handle<Context> global_context); | 230 Handle<Context> script_context); |
| 231 | 231 |
| 232 static int GetContextOffset(int context_index) { | 232 static int GetContextOffset(int context_index) { |
| 233 return kFirstContextOffset + context_index * kPointerSize; | 233 return kFirstContextOffset + context_index * kPointerSize; |
| 234 } | 234 } |
| 235 | 235 |
| 236 private: | 236 private: |
| 237 static const int kUsedSlot = 0; | 237 static const int kUsedSlot = 0; |
| 238 static const int kFirstContextOffset = | 238 static const int kFirstContextOffset = |
| 239 FixedArray::kHeaderSize + (kUsedSlot + 1) * kPointerSize; | 239 FixedArray::kHeaderSize + (kUsedSlot + 1) * kPointerSize; |
| 240 | 240 |
| 241 DISALLOW_IMPLICIT_CONSTRUCTORS(GlobalContextTable); | 241 DISALLOW_IMPLICIT_CONSTRUCTORS(ScriptContextTable); |
| 242 }; | 242 }; |
| 243 | 243 |
| 244 // JSFunctions are pairs (context, function code), sometimes also called | 244 // JSFunctions are pairs (context, function code), sometimes also called |
| 245 // closures. A Context object is used to represent function contexts and | 245 // closures. A Context object is used to represent function contexts and |
| 246 // dynamically pushed 'with' contexts (or 'scopes' in ECMA-262 speak). | 246 // dynamically pushed 'with' contexts (or 'scopes' in ECMA-262 speak). |
| 247 // | 247 // |
| 248 // At runtime, the contexts build a stack in parallel to the execution | 248 // At runtime, the contexts build a stack in parallel to the execution |
| 249 // stack, with the top-most context being the current context. All contexts | 249 // stack, with the top-most context being the current context. All contexts |
| 250 // have the following slots: | 250 // have the following slots: |
| 251 // | 251 // |
| (...skipping 25 matching lines...) Expand all Loading... |
| 277 // access to the global object from inside the code (since | 277 // access to the global object from inside the code (since |
| 278 // we always have a context pointer). | 278 // we always have a context pointer). |
| 279 // | 279 // |
| 280 // In addition, function contexts may have statically allocated context slots | 280 // In addition, function contexts may have statically allocated context slots |
| 281 // to store local variables/functions that are accessed from inner functions | 281 // to store local variables/functions that are accessed from inner functions |
| 282 // (via static context addresses) or through 'eval' (dynamic context lookups). | 282 // (via static context addresses) or through 'eval' (dynamic context lookups). |
| 283 // The native context contains additional slots for fast access to native | 283 // The native context contains additional slots for fast access to native |
| 284 // properties. | 284 // properties. |
| 285 // | 285 // |
| 286 // Finally, with Harmony scoping, the JSFunction representing a top level | 286 // Finally, with Harmony scoping, the JSFunction representing a top level |
| 287 // script will have the GlobalContext rather than a FunctionContext. | 287 // script will have the ScriptContext rather than a FunctionContext. |
| 288 // Global contexts from all top-level scripts are gathered in | 288 // Script contexts from all top-level scripts are gathered in |
| 289 // GlobalContextTable. | 289 // ScriptContextTable. |
| 290 | 290 |
| 291 class Context: public FixedArray { | 291 class Context: public FixedArray { |
| 292 public: | 292 public: |
| 293 // Conversions. | 293 // Conversions. |
| 294 static Context* cast(Object* context) { | 294 static Context* cast(Object* context) { |
| 295 DCHECK(context->IsContext()); | 295 DCHECK(context->IsContext()); |
| 296 return reinterpret_cast<Context*>(context); | 296 return reinterpret_cast<Context*>(context); |
| 297 } | 297 } |
| 298 | 298 |
| 299 // The default context slot layout; indices are FixedArray slot indices. | 299 // The default context slot layout; indices are FixedArray slot indices. |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 NATIVE_OBJECT_NOTIFIER_PERFORM_CHANGE, | 411 NATIVE_OBJECT_NOTIFIER_PERFORM_CHANGE, |
| 412 SLOPPY_GENERATOR_FUNCTION_MAP_INDEX, | 412 SLOPPY_GENERATOR_FUNCTION_MAP_INDEX, |
| 413 STRICT_GENERATOR_FUNCTION_MAP_INDEX, | 413 STRICT_GENERATOR_FUNCTION_MAP_INDEX, |
| 414 GENERATOR_OBJECT_PROTOTYPE_MAP_INDEX, | 414 GENERATOR_OBJECT_PROTOTYPE_MAP_INDEX, |
| 415 ITERATOR_RESULT_MAP_INDEX, | 415 ITERATOR_RESULT_MAP_INDEX, |
| 416 MAP_ITERATOR_MAP_INDEX, | 416 MAP_ITERATOR_MAP_INDEX, |
| 417 SET_ITERATOR_MAP_INDEX, | 417 SET_ITERATOR_MAP_INDEX, |
| 418 ITERATOR_SYMBOL_INDEX, | 418 ITERATOR_SYMBOL_INDEX, |
| 419 UNSCOPABLES_SYMBOL_INDEX, | 419 UNSCOPABLES_SYMBOL_INDEX, |
| 420 ARRAY_VALUES_ITERATOR_INDEX, | 420 ARRAY_VALUES_ITERATOR_INDEX, |
| 421 GLOBAL_CONTEXT_TABLE_INDEX, | 421 SCRIPT_CONTEXT_TABLE_INDEX, |
| 422 MAP_CACHE_INDEX, | 422 MAP_CACHE_INDEX, |
| 423 | 423 |
| 424 // Properties from here are treated as weak references by the full GC. | 424 // Properties from here are treated as weak references by the full GC. |
| 425 // Scavenge treats them as strong references. | 425 // Scavenge treats them as strong references. |
| 426 OPTIMIZED_FUNCTIONS_LIST, // Weak. | 426 OPTIMIZED_FUNCTIONS_LIST, // Weak. |
| 427 OPTIMIZED_CODE_LIST, // Weak. | 427 OPTIMIZED_CODE_LIST, // Weak. |
| 428 DEOPTIMIZED_CODE_LIST, // Weak. | 428 DEOPTIMIZED_CODE_LIST, // Weak. |
| 429 NEXT_CONTEXT_LINK, // Weak. | 429 NEXT_CONTEXT_LINK, // Weak. |
| 430 | 430 |
| 431 // Total number of slots. | 431 // Total number of slots. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 set(GLOBAL_OBJECT_INDEX, object); | 464 set(GLOBAL_OBJECT_INDEX, object); |
| 465 } | 465 } |
| 466 | 466 |
| 467 // Returns a JSGlobalProxy object or null. | 467 // Returns a JSGlobalProxy object or null. |
| 468 JSObject* global_proxy(); | 468 JSObject* global_proxy(); |
| 469 void set_global_proxy(JSObject* global); | 469 void set_global_proxy(JSObject* global); |
| 470 | 470 |
| 471 // The builtins object. | 471 // The builtins object. |
| 472 JSBuiltinsObject* builtins(); | 472 JSBuiltinsObject* builtins(); |
| 473 | 473 |
| 474 // Get the innermost global context by traversing the context chain. | 474 // Get the script context by traversing the context chain. |
| 475 Context* global_context(); | 475 Context* script_context(); |
| 476 | 476 |
| 477 // Compute the native context by traversing the context chain. | 477 // Compute the native context by traversing the context chain. |
| 478 Context* native_context(); | 478 Context* native_context(); |
| 479 | 479 |
| 480 // Predicates for context types. IsNativeContext is also defined on Object | 480 // Predicates for context types. IsNativeContext is also defined on Object |
| 481 // because we frequently have to know if arbitrary objects are natives | 481 // because we frequently have to know if arbitrary objects are natives |
| 482 // contexts. | 482 // contexts. |
| 483 bool IsNativeContext() { | 483 bool IsNativeContext() { |
| 484 Map* map = this->map(); | 484 Map* map = this->map(); |
| 485 return map == map->GetHeap()->native_context_map(); | 485 return map == map->GetHeap()->native_context_map(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 497 return map == map->GetHeap()->with_context_map(); | 497 return map == map->GetHeap()->with_context_map(); |
| 498 } | 498 } |
| 499 bool IsBlockContext() { | 499 bool IsBlockContext() { |
| 500 Map* map = this->map(); | 500 Map* map = this->map(); |
| 501 return map == map->GetHeap()->block_context_map(); | 501 return map == map->GetHeap()->block_context_map(); |
| 502 } | 502 } |
| 503 bool IsModuleContext() { | 503 bool IsModuleContext() { |
| 504 Map* map = this->map(); | 504 Map* map = this->map(); |
| 505 return map == map->GetHeap()->module_context_map(); | 505 return map == map->GetHeap()->module_context_map(); |
| 506 } | 506 } |
| 507 bool IsGlobalContext() { | 507 bool IsScriptContext() { |
| 508 Map* map = this->map(); | 508 Map* map = this->map(); |
| 509 return map == map->GetHeap()->global_context_map(); | 509 return map == map->GetHeap()->script_context_map(); |
| 510 } | 510 } |
| 511 | 511 |
| 512 bool HasSameSecurityTokenAs(Context* that) { | 512 bool HasSameSecurityTokenAs(Context* that) { |
| 513 return this->global_object()->native_context()->security_token() == | 513 return this->global_object()->native_context()->security_token() == |
| 514 that->global_object()->native_context()->security_token(); | 514 that->global_object()->native_context()->security_token(); |
| 515 } | 515 } |
| 516 | 516 |
| 517 // A native context holds a list of all functions with optimized code. | 517 // A native context holds a list of all functions with optimized code. |
| 518 void AddOptimizedFunction(JSFunction* function); | 518 void AddOptimizedFunction(JSFunction* function); |
| 519 void RemoveOptimizedFunction(JSFunction* function); | 519 void RemoveOptimizedFunction(JSFunction* function); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 static bool IsBootstrappingOrGlobalObject(Isolate* isolate, Object* object); | 611 static bool IsBootstrappingOrGlobalObject(Isolate* isolate, Object* object); |
| 612 #endif | 612 #endif |
| 613 | 613 |
| 614 STATIC_ASSERT(kHeaderSize == Internals::kContextHeaderSize); | 614 STATIC_ASSERT(kHeaderSize == Internals::kContextHeaderSize); |
| 615 STATIC_ASSERT(EMBEDDER_DATA_INDEX == Internals::kContextEmbedderDataIndex); | 615 STATIC_ASSERT(EMBEDDER_DATA_INDEX == Internals::kContextEmbedderDataIndex); |
| 616 }; | 616 }; |
| 617 | 617 |
| 618 } } // namespace v8::internal | 618 } } // namespace v8::internal |
| 619 | 619 |
| 620 #endif // V8_CONTEXTS_H_ | 620 #endif // V8_CONTEXTS_H_ |
| OLD | NEW |