OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 #include "bootstrapper.h" | 30 #include "bootstrapper.h" |
31 #include "debug.h" | 31 #include "debug.h" |
32 #include "scopeinfo.h" | 32 #include "scopeinfo.h" |
33 | 33 |
34 namespace v8 { | 34 namespace v8 { |
35 namespace internal { | 35 namespace internal { |
36 | 36 |
37 Context* Context::declaration_context() { | 37 Context* Context::declaration_context() { |
38 Context* current = this; | 38 Context* current = this; |
39 while (!current->IsFunctionContext() && !current->IsGlobalContext()) { | 39 while (!current->IsFunctionContext() && !current->IsNativeContext()) { |
40 current = current->previous(); | 40 current = current->previous(); |
41 ASSERT(current->closure() == closure()); | 41 ASSERT(current->closure() == closure()); |
42 } | 42 } |
43 return current; | 43 return current; |
44 } | 44 } |
45 | 45 |
46 | 46 |
47 JSBuiltinsObject* Context::builtins() { | 47 JSBuiltinsObject* Context::builtins() { |
48 GlobalObject* object = global(); | 48 GlobalObject* object = global(); |
49 if (object->IsJSGlobalObject()) { | 49 if (object->IsJSGlobalObject()) { |
50 return JSGlobalObject::cast(object)->builtins(); | 50 return JSGlobalObject::cast(object)->builtins(); |
51 } else { | 51 } else { |
52 ASSERT(object->IsJSBuiltinsObject()); | 52 ASSERT(object->IsJSBuiltinsObject()); |
53 return JSBuiltinsObject::cast(object); | 53 return JSBuiltinsObject::cast(object); |
54 } | 54 } |
55 } | 55 } |
56 | 56 |
57 | 57 |
58 Context* Context::global_context() { | 58 Context* Context::native_context() { |
59 // Fast case: the global object for this context has been set. In | 59 // Fast case: the global object for this context has been set. In |
60 // that case, the global object has a direct pointer to the global | 60 // that case, the global object has a direct pointer to the global |
61 // context. | 61 // context. |
62 if (global()->IsGlobalObject()) { | 62 if (global()->IsGlobalObject()) { |
63 return global()->global_context(); | 63 return global()->native_context(); |
64 } | 64 } |
65 | 65 |
66 // During bootstrapping, the global object might not be set and we | 66 // During bootstrapping, the global object might not be set and we |
67 // have to search the context chain to find the global context. | 67 // have to search the context chain to find the native context. |
68 ASSERT(Isolate::Current()->bootstrapper()->IsActive()); | 68 ASSERT(Isolate::Current()->bootstrapper()->IsActive()); |
69 Context* current = this; | 69 Context* current = this; |
70 while (!current->IsGlobalContext()) { | 70 while (!current->IsNativeContext()) { |
71 JSFunction* closure = JSFunction::cast(current->closure()); | 71 JSFunction* closure = JSFunction::cast(current->closure()); |
72 current = Context::cast(closure->context()); | 72 current = Context::cast(closure->context()); |
73 } | 73 } |
74 return current; | 74 return current; |
75 } | 75 } |
76 | 76 |
77 | 77 |
78 JSObject* Context::global_proxy() { | 78 JSObject* Context::global_proxy() { |
79 return global_context()->global_proxy_object(); | 79 return native_context()->global_proxy_object(); |
80 } | 80 } |
81 | 81 |
82 void Context::set_global_proxy(JSObject* object) { | 82 void Context::set_global_proxy(JSObject* object) { |
83 global_context()->set_global_proxy_object(object); | 83 native_context()->set_global_proxy_object(object); |
84 } | 84 } |
85 | 85 |
86 | 86 |
87 Handle<Object> Context::Lookup(Handle<String> name, | 87 Handle<Object> Context::Lookup(Handle<String> name, |
88 ContextLookupFlags flags, | 88 ContextLookupFlags flags, |
89 int* index, | 89 int* index, |
90 PropertyAttributes* attributes, | 90 PropertyAttributes* attributes, |
91 BindingFlags* binding_flags) { | 91 BindingFlags* binding_flags) { |
92 Isolate* isolate = GetIsolate(); | 92 Isolate* isolate = GetIsolate(); |
93 Handle<Context> context(this, isolate); | 93 Handle<Context> context(this, isolate); |
94 | 94 |
95 bool follow_context_chain = (flags & FOLLOW_CONTEXT_CHAIN) != 0; | 95 bool follow_context_chain = (flags & FOLLOW_CONTEXT_CHAIN) != 0; |
96 *index = -1; | 96 *index = -1; |
97 *attributes = ABSENT; | 97 *attributes = ABSENT; |
98 *binding_flags = MISSING_BINDING; | 98 *binding_flags = MISSING_BINDING; |
99 | 99 |
100 if (FLAG_trace_contexts) { | 100 if (FLAG_trace_contexts) { |
101 PrintF("Context::Lookup("); | 101 PrintF("Context::Lookup("); |
102 name->ShortPrint(); | 102 name->ShortPrint(); |
103 PrintF(")\n"); | 103 PrintF(")\n"); |
104 } | 104 } |
105 | 105 |
106 do { | 106 do { |
107 if (FLAG_trace_contexts) { | 107 if (FLAG_trace_contexts) { |
108 PrintF(" - looking in context %p", reinterpret_cast<void*>(*context)); | 108 PrintF(" - looking in context %p", reinterpret_cast<void*>(*context)); |
109 if (context->IsGlobalContext()) PrintF(" (global context)"); | 109 if (context->IsNativeContext()) PrintF(" (native context)"); |
110 PrintF("\n"); | 110 PrintF("\n"); |
111 } | 111 } |
112 | 112 |
113 // 1. Check global objects, subjects of with, and extension objects. | 113 // 1. Check global objects, subjects of with, and extension objects. |
114 if (context->IsGlobalContext() || | 114 if (context->IsNativeContext() || |
115 context->IsWithContext() || | 115 context->IsWithContext() || |
116 (context->IsFunctionContext() && context->has_extension())) { | 116 (context->IsFunctionContext() && context->has_extension())) { |
117 Handle<JSObject> object(JSObject::cast(context->extension()), isolate); | 117 Handle<JSObject> object(JSObject::cast(context->extension()), isolate); |
118 // Context extension objects needs to behave as if they have no | 118 // Context extension objects needs to behave as if they have no |
119 // prototype. So even if we want to follow prototype chains, we need | 119 // prototype. So even if we want to follow prototype chains, we need |
120 // to only do a local lookup for context extension objects. | 120 // to only do a local lookup for context extension objects. |
121 if ((flags & FOLLOW_PROTOTYPE_CHAIN) == 0 || | 121 if ((flags & FOLLOW_PROTOTYPE_CHAIN) == 0 || |
122 object->IsJSContextExtensionObject()) { | 122 object->IsJSContextExtensionObject()) { |
123 *attributes = object->GetLocalPropertyAttribute(*name); | 123 *attributes = object->GetLocalPropertyAttribute(*name); |
124 } else { | 124 } else { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 PrintF("=> found in catch context\n"); | 219 PrintF("=> found in catch context\n"); |
220 } | 220 } |
221 *index = Context::THROWN_OBJECT_INDEX; | 221 *index = Context::THROWN_OBJECT_INDEX; |
222 *attributes = NONE; | 222 *attributes = NONE; |
223 *binding_flags = MUTABLE_IS_INITIALIZED; | 223 *binding_flags = MUTABLE_IS_INITIALIZED; |
224 return context; | 224 return context; |
225 } | 225 } |
226 } | 226 } |
227 | 227 |
228 // 3. Prepare to continue with the previous (next outermost) context. | 228 // 3. Prepare to continue with the previous (next outermost) context. |
229 if (context->IsGlobalContext()) { | 229 if (context->IsNativeContext()) { |
230 follow_context_chain = false; | 230 follow_context_chain = false; |
231 } else { | 231 } else { |
232 context = Handle<Context>(context->previous(), isolate); | 232 context = Handle<Context>(context->previous(), isolate); |
233 } | 233 } |
234 } while (follow_context_chain); | 234 } while (follow_context_chain); |
235 | 235 |
236 if (FLAG_trace_contexts) { | 236 if (FLAG_trace_contexts) { |
237 PrintF("=> no property/slot found\n"); | 237 PrintF("=> no property/slot found\n"); |
238 } | 238 } |
239 return Handle<Object>::null(); | 239 return Handle<Object>::null(); |
240 } | 240 } |
241 | 241 |
242 | 242 |
243 void Context::AddOptimizedFunction(JSFunction* function) { | 243 void Context::AddOptimizedFunction(JSFunction* function) { |
244 ASSERT(IsGlobalContext()); | 244 ASSERT(IsNativeContext()); |
245 #ifdef DEBUG | 245 #ifdef DEBUG |
246 if (FLAG_enable_slow_asserts) { | 246 if (FLAG_enable_slow_asserts) { |
247 Object* element = get(OPTIMIZED_FUNCTIONS_LIST); | 247 Object* element = get(OPTIMIZED_FUNCTIONS_LIST); |
248 while (!element->IsUndefined()) { | 248 while (!element->IsUndefined()) { |
249 CHECK(element != function); | 249 CHECK(element != function); |
250 element = JSFunction::cast(element)->next_function_link(); | 250 element = JSFunction::cast(element)->next_function_link(); |
251 } | 251 } |
252 } | 252 } |
253 | 253 |
254 CHECK(function->next_function_link()->IsUndefined()); | 254 CHECK(function->next_function_link()->IsUndefined()); |
255 | 255 |
256 // Check that the context belongs to the weak global contexts list. | 256 // Check that the context belongs to the weak native contexts list. |
257 bool found = false; | 257 bool found = false; |
258 Object* context = GetHeap()->global_contexts_list(); | 258 Object* context = GetHeap()->native_contexts_list(); |
259 while (!context->IsUndefined()) { | 259 while (!context->IsUndefined()) { |
260 if (context == this) { | 260 if (context == this) { |
261 found = true; | 261 found = true; |
262 break; | 262 break; |
263 } | 263 } |
264 context = Context::cast(context)->get(Context::NEXT_CONTEXT_LINK); | 264 context = Context::cast(context)->get(Context::NEXT_CONTEXT_LINK); |
265 } | 265 } |
266 CHECK(found); | 266 CHECK(found); |
267 #endif | 267 #endif |
268 function->set_next_function_link(get(OPTIMIZED_FUNCTIONS_LIST)); | 268 function->set_next_function_link(get(OPTIMIZED_FUNCTIONS_LIST)); |
269 set(OPTIMIZED_FUNCTIONS_LIST, function); | 269 set(OPTIMIZED_FUNCTIONS_LIST, function); |
270 } | 270 } |
271 | 271 |
272 | 272 |
273 void Context::RemoveOptimizedFunction(JSFunction* function) { | 273 void Context::RemoveOptimizedFunction(JSFunction* function) { |
274 ASSERT(IsGlobalContext()); | 274 ASSERT(IsNativeContext()); |
275 Object* element = get(OPTIMIZED_FUNCTIONS_LIST); | 275 Object* element = get(OPTIMIZED_FUNCTIONS_LIST); |
276 JSFunction* prev = NULL; | 276 JSFunction* prev = NULL; |
277 while (!element->IsUndefined()) { | 277 while (!element->IsUndefined()) { |
278 JSFunction* element_function = JSFunction::cast(element); | 278 JSFunction* element_function = JSFunction::cast(element); |
279 ASSERT(element_function->next_function_link()->IsUndefined() || | 279 ASSERT(element_function->next_function_link()->IsUndefined() || |
280 element_function->next_function_link()->IsJSFunction()); | 280 element_function->next_function_link()->IsJSFunction()); |
281 if (element_function == function) { | 281 if (element_function == function) { |
282 if (prev == NULL) { | 282 if (prev == NULL) { |
283 set(OPTIMIZED_FUNCTIONS_LIST, element_function->next_function_link()); | 283 set(OPTIMIZED_FUNCTIONS_LIST, element_function->next_function_link()); |
284 } else { | 284 } else { |
285 prev->set_next_function_link(element_function->next_function_link()); | 285 prev->set_next_function_link(element_function->next_function_link()); |
286 } | 286 } |
287 element_function->set_next_function_link(GetHeap()->undefined_value()); | 287 element_function->set_next_function_link(GetHeap()->undefined_value()); |
288 return; | 288 return; |
289 } | 289 } |
290 prev = element_function; | 290 prev = element_function; |
291 element = element_function->next_function_link(); | 291 element = element_function->next_function_link(); |
292 } | 292 } |
293 UNREACHABLE(); | 293 UNREACHABLE(); |
294 } | 294 } |
295 | 295 |
296 | 296 |
297 Object* Context::OptimizedFunctionsListHead() { | 297 Object* Context::OptimizedFunctionsListHead() { |
298 ASSERT(IsGlobalContext()); | 298 ASSERT(IsNativeContext()); |
299 return get(OPTIMIZED_FUNCTIONS_LIST); | 299 return get(OPTIMIZED_FUNCTIONS_LIST); |
300 } | 300 } |
301 | 301 |
302 | 302 |
303 void Context::ClearOptimizedFunctions() { | 303 void Context::ClearOptimizedFunctions() { |
304 set(OPTIMIZED_FUNCTIONS_LIST, GetHeap()->undefined_value()); | 304 set(OPTIMIZED_FUNCTIONS_LIST, GetHeap()->undefined_value()); |
305 } | 305 } |
306 | 306 |
307 | 307 |
308 #ifdef DEBUG | 308 #ifdef DEBUG |
309 bool Context::IsBootstrappingOrValidParentContext( | 309 bool Context::IsBootstrappingOrValidParentContext( |
310 Object* object, Context* child) { | 310 Object* object, Context* child) { |
311 // During bootstrapping we allow all objects to pass as | 311 // During bootstrapping we allow all objects to pass as |
312 // contexts. This is necessary to fix circular dependencies. | 312 // contexts. This is necessary to fix circular dependencies. |
313 if (Isolate::Current()->bootstrapper()->IsActive()) return true; | 313 if (Isolate::Current()->bootstrapper()->IsActive()) return true; |
314 if (!object->IsContext()) return false; | 314 if (!object->IsContext()) return false; |
315 Context* context = Context::cast(object); | 315 Context* context = Context::cast(object); |
316 return context->IsGlobalContext() || context->IsModuleContext() || | 316 return context->IsNativeContext() || context->IsModuleContext() || |
317 !child->IsModuleContext(); | 317 !child->IsModuleContext(); |
318 } | 318 } |
319 | 319 |
320 | 320 |
321 bool Context::IsBootstrappingOrGlobalObject(Object* object) { | 321 bool Context::IsBootstrappingOrGlobalObject(Object* object) { |
322 // During bootstrapping we allow all objects to pass as global | 322 // During bootstrapping we allow all objects to pass as global |
323 // objects. This is necessary to fix circular dependencies. | 323 // objects. This is necessary to fix circular dependencies. |
324 Isolate* isolate = Isolate::Current(); | 324 Isolate* isolate = Isolate::Current(); |
325 return isolate->heap()->gc_state() != Heap::NOT_IN_GC || | 325 return isolate->heap()->gc_state() != Heap::NOT_IN_GC || |
326 isolate->bootstrapper()->IsActive() || | 326 isolate->bootstrapper()->IsActive() || |
327 object->IsGlobalObject(); | 327 object->IsGlobalObject(); |
328 } | 328 } |
329 #endif | 329 #endif |
330 | 330 |
331 } } // namespace v8::internal | 331 } } // namespace v8::internal |
OLD | NEW |