• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "src/objects/regexp-match-info.h"
11 
12 namespace v8 {
13 namespace internal {
14 
15 
16 // static
cast(Object * context)17 ScriptContextTable* ScriptContextTable::cast(Object* context) {
18   DCHECK(context->IsScriptContextTable());
19   return reinterpret_cast<ScriptContextTable*>(context);
20 }
21 
22 
used()23 int ScriptContextTable::used() const {
24   return Smi::cast(get(kUsedSlot))->value();
25 }
26 
27 
set_used(int used)28 void ScriptContextTable::set_used(int used) {
29   set(kUsedSlot, Smi::FromInt(used));
30 }
31 
32 
33 // static
GetContext(Handle<ScriptContextTable> table,int i)34 Handle<Context> ScriptContextTable::GetContext(Handle<ScriptContextTable> table,
35                                                int i) {
36   DCHECK(i < table->used());
37   return Handle<Context>::cast(
38       FixedArray::get(*table, i + kFirstContextSlot, table->GetIsolate()));
39 }
40 
41 
42 // static
cast(Object * context)43 Context* Context::cast(Object* context) {
44   DCHECK(context->IsContext());
45   return reinterpret_cast<Context*>(context);
46 }
47 
48 
closure()49 JSFunction* Context::closure() { return JSFunction::cast(get(CLOSURE_INDEX)); }
set_closure(JSFunction * closure)50 void Context::set_closure(JSFunction* closure) { set(CLOSURE_INDEX, closure); }
51 
52 
previous()53 Context* Context::previous() {
54   Object* result = get(PREVIOUS_INDEX);
55   DCHECK(IsBootstrappingOrValidParentContext(result, this));
56   return reinterpret_cast<Context*>(result);
57 }
set_previous(Context * context)58 void Context::set_previous(Context* context) { set(PREVIOUS_INDEX, context); }
59 
next_context_link()60 Object* Context::next_context_link() { return get(Context::NEXT_CONTEXT_LINK); }
61 
has_extension()62 bool Context::has_extension() { return !extension()->IsTheHole(GetIsolate()); }
extension()63 HeapObject* Context::extension() {
64   return HeapObject::cast(get(EXTENSION_INDEX));
65 }
set_extension(HeapObject * object)66 void Context::set_extension(HeapObject* object) {
67   set(EXTENSION_INDEX, object);
68 }
69 
70 
native_context()71 Context* Context::native_context() {
72   Object* result = get(NATIVE_CONTEXT_INDEX);
73   DCHECK(IsBootstrappingOrNativeContext(this->GetIsolate(), result));
74   return reinterpret_cast<Context*>(result);
75 }
76 
77 
set_native_context(Context * context)78 void Context::set_native_context(Context* context) {
79   set(NATIVE_CONTEXT_INDEX, context);
80 }
81 
82 
IsNativeContext()83 bool Context::IsNativeContext() {
84   Map* map = this->map();
85   return map == map->GetHeap()->native_context_map();
86 }
87 
88 
IsFunctionContext()89 bool Context::IsFunctionContext() {
90   Map* map = this->map();
91   return map == map->GetHeap()->function_context_map();
92 }
93 
94 
IsCatchContext()95 bool Context::IsCatchContext() {
96   Map* map = this->map();
97   return map == map->GetHeap()->catch_context_map();
98 }
99 
100 
IsWithContext()101 bool Context::IsWithContext() {
102   Map* map = this->map();
103   return map == map->GetHeap()->with_context_map();
104 }
105 
IsDebugEvaluateContext()106 bool Context::IsDebugEvaluateContext() {
107   Map* map = this->map();
108   return map == map->GetHeap()->debug_evaluate_context_map();
109 }
110 
IsBlockContext()111 bool Context::IsBlockContext() {
112   Map* map = this->map();
113   return map == map->GetHeap()->block_context_map();
114 }
115 
116 
IsModuleContext()117 bool Context::IsModuleContext() {
118   Map* map = this->map();
119   return map == map->GetHeap()->module_context_map();
120 }
121 
IsEvalContext()122 bool Context::IsEvalContext() {
123   Map* map = this->map();
124   return map == map->GetHeap()->eval_context_map();
125 }
126 
IsScriptContext()127 bool Context::IsScriptContext() {
128   Map* map = this->map();
129   return map == map->GetHeap()->script_context_map();
130 }
131 
OptimizedCodeMapIsCleared()132 bool Context::OptimizedCodeMapIsCleared() {
133   return osr_code_table() == GetHeap()->empty_fixed_array();
134 }
135 
HasSameSecurityTokenAs(Context * that)136 bool Context::HasSameSecurityTokenAs(Context* that) {
137   return this->native_context()->security_token() ==
138          that->native_context()->security_token();
139 }
140 
141 
142 #define NATIVE_CONTEXT_FIELD_ACCESSORS(index, type, name) \
143   void Context::set_##name(type* value) {                 \
144     DCHECK(IsNativeContext());                            \
145     set(index, value);                                    \
146   }                                                       \
147   bool Context::is_##name(type* value) {                  \
148     DCHECK(IsNativeContext());                            \
149     return type::cast(get(index)) == value;               \
150   }                                                       \
151   type* Context::name() {                                 \
152     DCHECK(IsNativeContext());                            \
153     return type::cast(get(index));                        \
154   }
155 NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_FIELD_ACCESSORS)
156 #undef NATIVE_CONTEXT_FIELD_ACCESSORS
157 
158 
159 }  // namespace internal
160 }  // namespace v8
161 
162 #endif  // V8_CONTEXTS_INL_H_
163