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.h" | 8 #include "src/heap.h" |
9 #include "src/objects.h" | 9 #include "src/objects.h" |
10 | 10 |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 // The native context contains additional slots for fast access to native | 244 // The native context contains additional slots for fast access to native |
245 // properties. | 245 // properties. |
246 // | 246 // |
247 // Finally, with Harmony scoping, the JSFunction representing a top level | 247 // Finally, with Harmony scoping, the JSFunction representing a top level |
248 // script will have the GlobalContext rather than a FunctionContext. | 248 // script will have the GlobalContext rather than a FunctionContext. |
249 | 249 |
250 class Context: public FixedArray { | 250 class Context: public FixedArray { |
251 public: | 251 public: |
252 // Conversions. | 252 // Conversions. |
253 static Context* cast(Object* context) { | 253 static Context* cast(Object* context) { |
254 ASSERT(context->IsContext()); | 254 DCHECK(context->IsContext()); |
255 return reinterpret_cast<Context*>(context); | 255 return reinterpret_cast<Context*>(context); |
256 } | 256 } |
257 | 257 |
258 // The default context slot layout; indices are FixedArray slot indices. | 258 // The default context slot layout; indices are FixedArray slot indices. |
259 enum { | 259 enum { |
260 // These slots are in all contexts. | 260 // These slots are in all contexts. |
261 CLOSURE_INDEX, | 261 CLOSURE_INDEX, |
262 PREVIOUS_INDEX, | 262 PREVIOUS_INDEX, |
263 // The extension slot is used for either the global object (in global | 263 // The extension slot is used for either the global object (in global |
264 // contexts), eval extension object (function contexts), subject of with | 264 // contexts), eval extension object (function contexts), subject of with |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 NATIVE_CONTEXT_SLOTS, | 407 NATIVE_CONTEXT_SLOTS, |
408 FIRST_WEAK_SLOT = OPTIMIZED_FUNCTIONS_LIST | 408 FIRST_WEAK_SLOT = OPTIMIZED_FUNCTIONS_LIST |
409 }; | 409 }; |
410 | 410 |
411 // Direct slot access. | 411 // Direct slot access. |
412 JSFunction* closure() { return JSFunction::cast(get(CLOSURE_INDEX)); } | 412 JSFunction* closure() { return JSFunction::cast(get(CLOSURE_INDEX)); } |
413 void set_closure(JSFunction* closure) { set(CLOSURE_INDEX, closure); } | 413 void set_closure(JSFunction* closure) { set(CLOSURE_INDEX, closure); } |
414 | 414 |
415 Context* previous() { | 415 Context* previous() { |
416 Object* result = unchecked_previous(); | 416 Object* result = unchecked_previous(); |
417 ASSERT(IsBootstrappingOrValidParentContext(result, this)); | 417 DCHECK(IsBootstrappingOrValidParentContext(result, this)); |
418 return reinterpret_cast<Context*>(result); | 418 return reinterpret_cast<Context*>(result); |
419 } | 419 } |
420 void set_previous(Context* context) { set(PREVIOUS_INDEX, context); } | 420 void set_previous(Context* context) { set(PREVIOUS_INDEX, context); } |
421 | 421 |
422 bool has_extension() { return extension() != NULL; } | 422 bool has_extension() { return extension() != NULL; } |
423 Object* extension() { return get(EXTENSION_INDEX); } | 423 Object* extension() { return get(EXTENSION_INDEX); } |
424 void set_extension(Object* object) { set(EXTENSION_INDEX, object); } | 424 void set_extension(Object* object) { set(EXTENSION_INDEX, object); } |
425 | 425 |
426 JSModule* module() { return JSModule::cast(get(EXTENSION_INDEX)); } | 426 JSModule* module() { return JSModule::cast(get(EXTENSION_INDEX)); } |
427 void set_module(JSModule* module) { set(EXTENSION_INDEX, module); } | 427 void set_module(JSModule* module) { set(EXTENSION_INDEX, module); } |
428 | 428 |
429 // Get the context where var declarations will be hoisted to, which | 429 // Get the context where var declarations will be hoisted to, which |
430 // may be the context itself. | 430 // may be the context itself. |
431 Context* declaration_context(); | 431 Context* declaration_context(); |
432 | 432 |
433 GlobalObject* global_object() { | 433 GlobalObject* global_object() { |
434 Object* result = get(GLOBAL_OBJECT_INDEX); | 434 Object* result = get(GLOBAL_OBJECT_INDEX); |
435 ASSERT(IsBootstrappingOrGlobalObject(this->GetIsolate(), result)); | 435 DCHECK(IsBootstrappingOrGlobalObject(this->GetIsolate(), result)); |
436 return reinterpret_cast<GlobalObject*>(result); | 436 return reinterpret_cast<GlobalObject*>(result); |
437 } | 437 } |
438 void set_global_object(GlobalObject* object) { | 438 void set_global_object(GlobalObject* object) { |
439 set(GLOBAL_OBJECT_INDEX, object); | 439 set(GLOBAL_OBJECT_INDEX, object); |
440 } | 440 } |
441 | 441 |
442 // Returns a JSGlobalProxy object or null. | 442 // Returns a JSGlobalProxy object or null. |
443 JSObject* global_proxy(); | 443 JSObject* global_proxy(); |
444 void set_global_proxy(JSObject* global); | 444 void set_global_proxy(JSObject* global); |
445 | 445 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 void AddOptimizedCode(Code* code); | 500 void AddOptimizedCode(Code* code); |
501 void SetOptimizedCodeListHead(Object* head); | 501 void SetOptimizedCodeListHead(Object* head); |
502 Object* OptimizedCodeListHead(); | 502 Object* OptimizedCodeListHead(); |
503 void SetDeoptimizedCodeListHead(Object* head); | 503 void SetDeoptimizedCodeListHead(Object* head); |
504 Object* DeoptimizedCodeListHead(); | 504 Object* DeoptimizedCodeListHead(); |
505 | 505 |
506 Handle<Object> ErrorMessageForCodeGenerationFromStrings(); | 506 Handle<Object> ErrorMessageForCodeGenerationFromStrings(); |
507 | 507 |
508 #define NATIVE_CONTEXT_FIELD_ACCESSORS(index, type, name) \ | 508 #define NATIVE_CONTEXT_FIELD_ACCESSORS(index, type, name) \ |
509 void set_##name(type* value) { \ | 509 void set_##name(type* value) { \ |
510 ASSERT(IsNativeContext()); \ | 510 DCHECK(IsNativeContext()); \ |
511 set(index, value); \ | 511 set(index, value); \ |
512 } \ | 512 } \ |
513 bool is_##name(type* value) { \ | 513 bool is_##name(type* value) { \ |
514 ASSERT(IsNativeContext()); \ | 514 DCHECK(IsNativeContext()); \ |
515 return type::cast(get(index)) == value; \ | 515 return type::cast(get(index)) == value; \ |
516 } \ | 516 } \ |
517 type* name() { \ | 517 type* name() { \ |
518 ASSERT(IsNativeContext()); \ | 518 DCHECK(IsNativeContext()); \ |
519 return type::cast(get(index)); \ | 519 return type::cast(get(index)); \ |
520 } | 520 } |
521 NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_FIELD_ACCESSORS) | 521 NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_FIELD_ACCESSORS) |
522 #undef NATIVE_CONTEXT_FIELD_ACCESSORS | 522 #undef NATIVE_CONTEXT_FIELD_ACCESSORS |
523 | 523 |
524 // Lookup the slot called name, starting with the current context. | 524 // Lookup the slot called name, starting with the current context. |
525 // There are three possibilities: | 525 // There are three possibilities: |
526 // | 526 // |
527 // 1) result->IsContext(): | 527 // 1) result->IsContext(): |
528 // The binding was found in a context. *index is always the | 528 // The binding was found in a context. *index is always the |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 static bool IsBootstrappingOrGlobalObject(Isolate* isolate, Object* object); | 580 static bool IsBootstrappingOrGlobalObject(Isolate* isolate, Object* object); |
581 #endif | 581 #endif |
582 | 582 |
583 STATIC_ASSERT(kHeaderSize == Internals::kContextHeaderSize); | 583 STATIC_ASSERT(kHeaderSize == Internals::kContextHeaderSize); |
584 STATIC_ASSERT(EMBEDDER_DATA_INDEX == Internals::kContextEmbedderDataIndex); | 584 STATIC_ASSERT(EMBEDDER_DATA_INDEX == Internals::kContextEmbedderDataIndex); |
585 }; | 585 }; |
586 | 586 |
587 } } // namespace v8::internal | 587 } } // namespace v8::internal |
588 | 588 |
589 #endif // V8_CONTEXTS_H_ | 589 #endif // V8_CONTEXTS_H_ |
OLD | NEW |