00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef V8_CONTEXTS_H_
00029 #define V8_CONTEXTS_H_
00030
00031 namespace v8 { namespace internal {
00032
00033
00034 enum ContextLookupFlags {
00035 FOLLOW_CONTEXT_CHAIN = 1,
00036 FOLLOW_PROTOTYPE_CHAIN = 2,
00037
00038 DONT_FOLLOW_CHAINS = 0,
00039 FOLLOW_CHAINS = FOLLOW_CONTEXT_CHAIN | FOLLOW_PROTOTYPE_CHAIN
00040 };
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 #define GLOBAL_CONTEXT_FIELDS(V) \
00059 V(GLOBAL_PROXY_INDEX, JSObject, global_proxy_object) \
00060 V(SECURITY_TOKEN_INDEX, Object, security_token) \
00061 V(BOOLEAN_FUNCTION_INDEX, JSFunction, boolean_function) \
00062 V(NUMBER_FUNCTION_INDEX, JSFunction, number_function) \
00063 V(STRING_FUNCTION_INDEX, JSFunction, string_function) \
00064 V(OBJECT_FUNCTION_INDEX, JSFunction, object_function) \
00065 V(ARRAY_FUNCTION_INDEX, JSFunction, array_function) \
00066 V(DATE_FUNCTION_INDEX, JSFunction, date_function) \
00067 V(REGEXP_FUNCTION_INDEX, JSFunction, regexp_function) \
00068 V(INITIAL_OBJECT_PROTOTYPE_INDEX, JSObject, initial_object_prototype) \
00069 V(CREATE_DATE_FUN_INDEX, JSFunction, create_date_fun) \
00070 V(TO_NUMBER_FUN_INDEX, JSFunction, to_number_fun) \
00071 V(TO_STRING_FUN_INDEX, JSFunction, to_string_fun) \
00072 V(TO_DETAIL_STRING_FUN_INDEX, JSFunction, to_detail_string_fun) \
00073 V(TO_OBJECT_FUN_INDEX, JSFunction, to_object_fun) \
00074 V(TO_INTEGER_FUN_INDEX, JSFunction, to_integer_fun) \
00075 V(TO_UINT32_FUN_INDEX, JSFunction, to_uint32_fun) \
00076 V(TO_INT32_FUN_INDEX, JSFunction, to_int32_fun) \
00077 V(TO_BOOLEAN_FUN_INDEX, JSFunction, to_boolean_fun) \
00078 V(INSTANTIATE_FUN_INDEX, JSFunction, instantiate_fun) \
00079 V(CONFIGURE_INSTANCE_FUN_INDEX, JSFunction, configure_instance_fun) \
00080 V(FUNCTION_MAP_INDEX, Map, function_map) \
00081 V(FUNCTION_INSTANCE_MAP_INDEX, Map, function_instance_map) \
00082 V(JS_ARRAY_MAP_INDEX, Map, js_array_map)\
00083 V(SPECIAL_FUNCTION_TABLE_INDEX, FixedArray, special_function_table) \
00084 V(ARGUMENTS_BOILERPLATE_INDEX, JSObject, arguments_boilerplate) \
00085 V(MESSAGE_LISTENERS_INDEX, JSObject, message_listeners) \
00086 V(DEBUG_EVENT_LISTENERS_INDEX, JSObject, debug_event_listeners) \
00087 V(MAKE_MESSAGE_FUN_INDEX, JSFunction, make_message_fun) \
00088 V(GET_STACK_TRACE_LINE_INDEX, JSFunction, get_stack_trace_line_fun) \
00089 V(CONFIGURE_GLOBAL_INDEX, JSFunction, configure_global_fun) \
00090 V(FUNCTION_CACHE_INDEX, JSObject, function_cache) \
00091 V(RUNTIME_CONTEXT_INDEX, Context, runtime_context) \
00092 V(CALL_AS_FUNCTION_DELEGATE_INDEX, JSFunction, call_as_function_delegate) \
00093 V(EMPTY_SCRIPT_INDEX, Script, empty_script) \
00094 V(SCRIPT_FUNCTION_INDEX, JSFunction, script_function) \
00095 V(CONTEXT_EXTENSION_FUNCTION_INDEX, JSFunction, context_extension_function) \
00096 V(OUT_OF_MEMORY_INDEX, Object, out_of_memory) \
00097 V(MAP_CACHE_INDEX, Object, map_cache)
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 class Context: public FixedArray {
00159 public:
00160
00161 static Context* cast(Object* context) {
00162 ASSERT(context->IsContext());
00163 return reinterpret_cast<Context*>(context);
00164 }
00165
00166
00167 enum {
00168
00169 CLOSURE_INDEX,
00170 FCONTEXT_INDEX,
00171 PREVIOUS_INDEX,
00172 EXTENSION_INDEX,
00173 GLOBAL_INDEX,
00174 MIN_CONTEXT_SLOTS,
00175
00176
00177 GLOBAL_PROXY_INDEX = MIN_CONTEXT_SLOTS,
00178 SECURITY_TOKEN_INDEX,
00179 ARGUMENTS_BOILERPLATE_INDEX,
00180 JS_ARRAY_MAP_INDEX,
00181 FUNCTION_MAP_INDEX,
00182 FUNCTION_INSTANCE_MAP_INDEX,
00183 INITIAL_OBJECT_PROTOTYPE_INDEX,
00184 BOOLEAN_FUNCTION_INDEX,
00185 NUMBER_FUNCTION_INDEX,
00186 STRING_FUNCTION_INDEX,
00187 OBJECT_FUNCTION_INDEX,
00188 ARRAY_FUNCTION_INDEX,
00189 DATE_FUNCTION_INDEX,
00190 REGEXP_FUNCTION_INDEX,
00191 CREATE_DATE_FUN_INDEX,
00192 TO_NUMBER_FUN_INDEX,
00193 TO_STRING_FUN_INDEX,
00194 TO_DETAIL_STRING_FUN_INDEX,
00195 TO_OBJECT_FUN_INDEX,
00196 TO_INTEGER_FUN_INDEX,
00197 TO_UINT32_FUN_INDEX,
00198 TO_INT32_FUN_INDEX,
00199 TO_BOOLEAN_FUN_INDEX,
00200 INSTANTIATE_FUN_INDEX,
00201 CONFIGURE_INSTANCE_FUN_INDEX,
00202 SPECIAL_FUNCTION_TABLE_INDEX,
00203 MESSAGE_LISTENERS_INDEX,
00204 DEBUG_EVENT_LISTENERS_INDEX,
00205 MAKE_MESSAGE_FUN_INDEX,
00206 GET_STACK_TRACE_LINE_INDEX,
00207 CONFIGURE_GLOBAL_INDEX,
00208 FUNCTION_CACHE_INDEX,
00209 RUNTIME_CONTEXT_INDEX,
00210 CALL_AS_FUNCTION_DELEGATE_INDEX,
00211 EMPTY_SCRIPT_INDEX,
00212 SCRIPT_FUNCTION_INDEX,
00213 CONTEXT_EXTENSION_FUNCTION_INDEX,
00214 OUT_OF_MEMORY_INDEX,
00215 MAP_CACHE_INDEX,
00216 GLOBAL_CONTEXT_SLOTS
00217 };
00218
00219
00220 JSFunction* closure() { return JSFunction::cast(get(CLOSURE_INDEX)); }
00221 void set_closure(JSFunction* closure) { set(CLOSURE_INDEX, closure); }
00222
00223 Context* fcontext() { return Context::cast(get(FCONTEXT_INDEX)); }
00224 void set_fcontext(Context* context) { set(FCONTEXT_INDEX, context); }
00225
00226 Context* previous() {
00227 Object* result = unchecked_previous();
00228 ASSERT(IsBootstrappingOrContext(result));
00229 return reinterpret_cast<Context*>(result);
00230 }
00231 void set_previous(Context* context) { set(PREVIOUS_INDEX, context); }
00232
00233 bool has_extension() { return unchecked_extension() != NULL; }
00234 JSObject* extension() { return JSObject::cast(unchecked_extension()); }
00235 void set_extension(JSObject* object) { set(EXTENSION_INDEX, object); }
00236
00237 GlobalObject* global() {
00238 Object* result = get(GLOBAL_INDEX);
00239 ASSERT(IsBootstrappingOrGlobalObject(result));
00240 return reinterpret_cast<GlobalObject*>(result);
00241 }
00242 void set_global(GlobalObject* global) { set(GLOBAL_INDEX, global); }
00243
00244
00245 JSObject* global_proxy();
00246 void set_global_proxy(JSObject* global);
00247
00248
00249 JSBuiltinsObject* builtins();
00250
00251
00252 Context* global_context();
00253
00254
00255 bool is_function_context() { return unchecked_previous() == NULL; }
00256
00257
00258 bool has_out_of_memory() {
00259 return global_context()->out_of_memory() == Heap::true_value();
00260 }
00261
00262
00263 void mark_out_of_memory() {
00264 global_context()->set_out_of_memory(Heap::true_value());
00265 }
00266
00267 #define GLOBAL_CONTEXT_FIELD_ACCESSORS(index, type, name) \
00268 void set_##name(type* value) { \
00269 ASSERT(IsGlobalContext()); \
00270 set(index, value); \
00271 } \
00272 type* name() { \
00273 ASSERT(IsGlobalContext()); \
00274 return type::cast(get(index)); \
00275 }
00276 GLOBAL_CONTEXT_FIELDS(GLOBAL_CONTEXT_FIELD_ACCESSORS)
00277 #undef GLOBAL_CONTEXT_FIELD_ACCESSORS
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300 Handle<Object> Lookup(Handle<String> name, ContextLookupFlags flags,
00301 int* index_, PropertyAttributes* attributes);
00302
00303
00304 static int SlotOffset(int index) {
00305 return kHeaderSize + index * kPointerSize - kHeapObjectTag;
00306 }
00307
00308 private:
00309
00310 Object* unchecked_previous() { return get(PREVIOUS_INDEX); }
00311 Object* unchecked_extension() { return get(EXTENSION_INDEX); }
00312
00313 #ifdef DEBUG
00314
00315 static bool IsBootstrappingOrContext(Object* object);
00316 static bool IsBootstrappingOrGlobalObject(Object* object);
00317 #endif
00318 };
00319
00320 } }
00321
00322 #endif // V8_CONTEXTS_H_