OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef V8_CONTEXTS_INL_H_ |
| 6 #define V8_CONTEXTS_INL_H_ |
| 7 |
| 8 #include "src/contexts.h" |
| 9 #include "src/objects-inl.h" |
| 10 |
| 11 namespace v8 { |
| 12 namespace internal { |
| 13 |
| 14 |
| 15 // static |
| 16 ScriptContextTable* ScriptContextTable::cast(Object* context) { |
| 17 DCHECK(context->IsScriptContextTable()); |
| 18 return reinterpret_cast<ScriptContextTable*>(context); |
| 19 } |
| 20 |
| 21 |
| 22 int ScriptContextTable::used() const { |
| 23 return Smi::cast(get(kUsedSlot))->value(); |
| 24 } |
| 25 |
| 26 |
| 27 void ScriptContextTable::set_used(int used) { |
| 28 set(kUsedSlot, Smi::FromInt(used)); |
| 29 } |
| 30 |
| 31 |
| 32 // static |
| 33 Handle<Context> ScriptContextTable::GetContext(Handle<ScriptContextTable> table, |
| 34 int i) { |
| 35 DCHECK(i < table->used()); |
| 36 return Handle<Context>::cast(FixedArray::get(table, i + kFirstContextSlot)); |
| 37 } |
| 38 |
| 39 |
| 40 // static |
| 41 Context* Context::cast(Object* context) { |
| 42 DCHECK(context->IsContext()); |
| 43 return reinterpret_cast<Context*>(context); |
| 44 } |
| 45 |
| 46 |
| 47 JSFunction* Context::closure() { return JSFunction::cast(get(CLOSURE_INDEX)); } |
| 48 void Context::set_closure(JSFunction* closure) { set(CLOSURE_INDEX, closure); } |
| 49 |
| 50 |
| 51 Context* Context::previous() { |
| 52 Object* result = get(PREVIOUS_INDEX); |
| 53 DCHECK(IsBootstrappingOrValidParentContext(result, this)); |
| 54 return reinterpret_cast<Context*>(result); |
| 55 } |
| 56 void Context::set_previous(Context* context) { set(PREVIOUS_INDEX, context); } |
| 57 |
| 58 |
| 59 bool Context::has_extension() { return extension() != nullptr; } |
| 60 Object* Context::extension() { return get(EXTENSION_INDEX); } |
| 61 void Context::set_extension(Object* object) { set(EXTENSION_INDEX, object); } |
| 62 |
| 63 |
| 64 JSModule* Context::module() { return JSModule::cast(get(EXTENSION_INDEX)); } |
| 65 void Context::set_module(JSModule* module) { set(EXTENSION_INDEX, module); } |
| 66 |
| 67 |
| 68 GlobalObject* Context::global_object() { |
| 69 Object* result = get(GLOBAL_OBJECT_INDEX); |
| 70 DCHECK(IsBootstrappingOrGlobalObject(this->GetIsolate(), result)); |
| 71 return reinterpret_cast<GlobalObject*>(result); |
| 72 } |
| 73 |
| 74 |
| 75 void Context::set_global_object(GlobalObject* object) { |
| 76 set(GLOBAL_OBJECT_INDEX, object); |
| 77 } |
| 78 |
| 79 |
| 80 bool Context::IsNativeContext() { |
| 81 Map* map = this->map(); |
| 82 return map == map->GetHeap()->native_context_map(); |
| 83 } |
| 84 |
| 85 |
| 86 bool Context::IsFunctionContext() { |
| 87 Map* map = this->map(); |
| 88 return map == map->GetHeap()->function_context_map(); |
| 89 } |
| 90 |
| 91 |
| 92 bool Context::IsCatchContext() { |
| 93 Map* map = this->map(); |
| 94 return map == map->GetHeap()->catch_context_map(); |
| 95 } |
| 96 |
| 97 |
| 98 bool Context::IsWithContext() { |
| 99 Map* map = this->map(); |
| 100 return map == map->GetHeap()->with_context_map(); |
| 101 } |
| 102 |
| 103 |
| 104 bool Context::IsBlockContext() { |
| 105 Map* map = this->map(); |
| 106 return map == map->GetHeap()->block_context_map(); |
| 107 } |
| 108 |
| 109 |
| 110 bool Context::IsModuleContext() { |
| 111 Map* map = this->map(); |
| 112 return map == map->GetHeap()->module_context_map(); |
| 113 } |
| 114 |
| 115 |
| 116 bool Context::IsScriptContext() { |
| 117 Map* map = this->map(); |
| 118 return map == map->GetHeap()->script_context_map(); |
| 119 } |
| 120 |
| 121 |
| 122 bool Context::HasSameSecurityTokenAs(Context* that) { |
| 123 return this->global_object()->native_context()->security_token() == |
| 124 that->global_object()->native_context()->security_token(); |
| 125 } |
| 126 |
| 127 |
| 128 #define NATIVE_CONTEXT_FIELD_ACCESSORS(index, type, name) \ |
| 129 void Context::set_##name(type* value) { \ |
| 130 DCHECK(IsNativeContext()); \ |
| 131 set(index, value); \ |
| 132 } \ |
| 133 bool Context::is_##name(type* value) { \ |
| 134 DCHECK(IsNativeContext()); \ |
| 135 return type::cast(get(index)) == value; \ |
| 136 } \ |
| 137 type* Context::name() { \ |
| 138 DCHECK(IsNativeContext()); \ |
| 139 return type::cast(get(index)); \ |
| 140 } |
| 141 NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_FIELD_ACCESSORS) |
| 142 #undef NATIVE_CONTEXT_FIELD_ACCESSORS |
| 143 |
| 144 |
| 145 } // namespace internal |
| 146 } // namespace v8 |
| 147 |
| 148 #endif // V8_CONTEXTS_INL_H_ |
OLD | NEW |