blob: 441ef9d9c32b6a70b7af5440f1a61fc1e8310c1b [file] [log] [blame]
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001// Copyright 2011 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#include "v8.h"
29
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +000030#include "bootstrapper.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000031#include "debug.h"
32#include "scopeinfo.h"
33
kasperl@chromium.org71affb52009-05-26 05:44:31 +000034namespace v8 {
35namespace internal {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000036
vegorov@chromium.org3cf47312011-06-29 13:20:01 +000037Context* Context::declaration_context() {
38 Context* current = this;
yangguo@chromium.org46839fb2012-08-28 09:06:19 +000039 while (!current->IsFunctionContext() && !current->IsNativeContext()) {
vegorov@chromium.org3cf47312011-06-29 13:20:01 +000040 current = current->previous();
41 ASSERT(current->closure() == closure());
42 }
43 return current;
44}
45
46
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000047JSBuiltinsObject* Context::builtins() {
yangguo@chromium.org46839fb2012-08-28 09:06:19 +000048 GlobalObject* object = global_object();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000049 if (object->IsJSGlobalObject()) {
50 return JSGlobalObject::cast(object)->builtins();
51 } else {
52 ASSERT(object->IsJSBuiltinsObject());
53 return JSBuiltinsObject::cast(object);
54 }
55}
56
57
ulan@chromium.org8e8d8822012-11-23 14:36:46 +000058Context* Context::global_context() {
59 Context* current = this;
60 while (!current->IsGlobalContext()) {
61 current = current->previous();
62 }
63 return current;
64}
65
66
yangguo@chromium.org46839fb2012-08-28 09:06:19 +000067Context* Context::native_context() {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000068 // Fast case: the global object for this context has been set. In
69 // that case, the global object has a direct pointer to the global
70 // context.
yangguo@chromium.org46839fb2012-08-28 09:06:19 +000071 if (global_object()->IsGlobalObject()) {
72 return global_object()->native_context();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000073 }
kasperl@chromium.org7b9eafd2009-12-21 15:20:30 +000074
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000075 // During bootstrapping, the global object might not be set and we
yangguo@chromium.org46839fb2012-08-28 09:06:19 +000076 // have to search the context chain to find the native context.
mstarzinger@chromium.orge9000182013-09-03 11:25:39 +000077 ASSERT(this->GetIsolate()->bootstrapper()->IsActive());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000078 Context* current = this;
yangguo@chromium.org46839fb2012-08-28 09:06:19 +000079 while (!current->IsNativeContext()) {
kasperl@chromium.org7b9eafd2009-12-21 15:20:30 +000080 JSFunction* closure = JSFunction::cast(current->closure());
81 current = Context::cast(closure->context());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000082 }
83 return current;
84}
85
86
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +000087JSObject* Context::global_proxy() {
yangguo@chromium.org46839fb2012-08-28 09:06:19 +000088 return native_context()->global_proxy_object();
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +000089}
90
mstarzinger@chromium.orge0e1b0d2013-07-08 08:38:06 +000091
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +000092void Context::set_global_proxy(JSObject* object) {
yangguo@chromium.org46839fb2012-08-28 09:06:19 +000093 native_context()->set_global_proxy_object(object);
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +000094}
95
96
whesse@chromium.org7b260152011-06-20 15:33:18 +000097Handle<Object> Context::Lookup(Handle<String> name,
98 ContextLookupFlags flags,
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +000099 int* index,
yangguo@chromium.org80c42ed2011-08-31 09:03:56 +0000100 PropertyAttributes* attributes,
101 BindingFlags* binding_flags) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000102 Isolate* isolate = GetIsolate();
103 Handle<Context> context(this, isolate);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000104
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000105 bool follow_context_chain = (flags & FOLLOW_CONTEXT_CHAIN) != 0;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000106 *index = -1;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000107 *attributes = ABSENT;
yangguo@chromium.org80c42ed2011-08-31 09:03:56 +0000108 *binding_flags = MISSING_BINDING;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000109
110 if (FLAG_trace_contexts) {
111 PrintF("Context::Lookup(");
112 name->ShortPrint();
113 PrintF(")\n");
114 }
115
116 do {
117 if (FLAG_trace_contexts) {
kmillikin@chromium.orgf05f2912010-09-30 10:07:24 +0000118 PrintF(" - looking in context %p", reinterpret_cast<void*>(*context));
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000119 if (context->IsNativeContext()) PrintF(" (native context)");
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000120 PrintF("\n");
121 }
122
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000123 // 1. Check global objects, subjects of with, and extension objects.
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000124 if (context->IsNativeContext() ||
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000125 context->IsWithContext() ||
126 (context->IsFunctionContext() && context->has_extension())) {
jkummerow@chromium.orgba72ec82013-07-22 09:21:20 +0000127 Handle<JSReceiver> object(
128 JSReceiver::cast(context->extension()), isolate);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000129 // Context extension objects needs to behave as if they have no
130 // prototype. So even if we want to follow prototype chains, we need
131 // to only do a local lookup for context extension objects.
132 if ((flags & FOLLOW_PROTOTYPE_CHAIN) == 0 ||
133 object->IsJSContextExtensionObject()) {
134 *attributes = object->GetLocalPropertyAttribute(*name);
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000135 } else {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000136 *attributes = object->GetPropertyAttribute(*name);
137 }
jkummerow@chromium.orgba72ec82013-07-22 09:21:20 +0000138 if (isolate->has_pending_exception()) return Handle<Object>();
139
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000140 if (*attributes != ABSENT) {
141 if (FLAG_trace_contexts) {
142 PrintF("=> found property in context object %p\n",
143 reinterpret_cast<void*>(*object));
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000144 }
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000145 return object;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000146 }
147 }
148
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000149 // 2. Check the context proper if it has slots.
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000150 if (context->IsFunctionContext() || context->IsBlockContext()) {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000151 // Use serialized scope information of functions and blocks to search
152 // for the context index.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000153 Handle<ScopeInfo> scope_info;
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000154 if (context->IsFunctionContext()) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000155 scope_info = Handle<ScopeInfo>(
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000156 context->closure()->shared()->scope_info(), isolate);
157 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000158 scope_info = Handle<ScopeInfo>(
159 ScopeInfo::cast(context->extension()), isolate);
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000160 }
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000161 VariableMode mode;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000162 InitializationFlag init_flag;
163 int slot_index = scope_info->ContextSlotIndex(*name, &mode, &init_flag);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000164 ASSERT(slot_index < 0 || slot_index >= MIN_CONTEXT_SLOTS);
165 if (slot_index >= 0) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000166 if (FLAG_trace_contexts) {
167 PrintF("=> found local in context slot %d (mode = %d)\n",
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000168 slot_index, mode);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000169 }
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000170 *index = slot_index;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000171 // Note: Fixed context slots are statically allocated by the compiler.
172 // Statically allocated variables always have a statically known mode,
173 // which is the mode with which they were declared when added to the
174 // scope. Thus, the DYNAMIC mode (which corresponds to dynamically
175 // declared variables that were introduced through declaration nodes)
176 // must not appear here.
177 switch (mode) {
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000178 case INTERNAL: // Fall through.
179 case VAR:
yangguo@chromium.org80c42ed2011-08-31 09:03:56 +0000180 *attributes = NONE;
181 *binding_flags = MUTABLE_IS_INITIALIZED;
182 break;
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000183 case LET:
whesse@chromium.org7b260152011-06-20 15:33:18 +0000184 *attributes = NONE;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000185 *binding_flags = (init_flag == kNeedsInitialization)
186 ? MUTABLE_CHECK_INITIALIZED : MUTABLE_IS_INITIALIZED;
whesse@chromium.org7b260152011-06-20 15:33:18 +0000187 break;
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000188 case CONST:
whesse@chromium.org7b260152011-06-20 15:33:18 +0000189 *attributes = READ_ONLY;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000190 *binding_flags = (init_flag == kNeedsInitialization)
191 ? IMMUTABLE_CHECK_INITIALIZED : IMMUTABLE_IS_INITIALIZED;
whesse@chromium.org7b260152011-06-20 15:33:18 +0000192 break;
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000193 case CONST_HARMONY:
194 *attributes = READ_ONLY;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000195 *binding_flags = (init_flag == kNeedsInitialization)
196 ? IMMUTABLE_CHECK_INITIALIZED_HARMONY :
197 IMMUTABLE_IS_INITIALIZED_HARMONY;
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000198 break;
ulan@chromium.org8e8d8822012-11-23 14:36:46 +0000199 case MODULE:
200 *attributes = READ_ONLY;
201 *binding_flags = IMMUTABLE_IS_INITIALIZED_HARMONY;
202 break;
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000203 case DYNAMIC:
204 case DYNAMIC_GLOBAL:
205 case DYNAMIC_LOCAL:
206 case TEMPORARY:
whesse@chromium.org7b260152011-06-20 15:33:18 +0000207 UNREACHABLE();
208 break;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000209 }
210 return context;
211 }
212
whesse@chromium.org7b260152011-06-20 15:33:18 +0000213 // Check the slot corresponding to the intermediate context holding
214 // only the function name variable.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000215 if (follow_context_chain && context->IsFunctionContext()) {
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000216 VariableMode mode;
217 int function_index = scope_info->FunctionContextSlotIndex(*name, &mode);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000218 if (function_index >= 0) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000219 if (FLAG_trace_contexts) {
220 PrintF("=> found intermediate function in context slot %d\n",
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000221 function_index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000222 }
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000223 *index = function_index;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000224 *attributes = READ_ONLY;
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000225 ASSERT(mode == CONST || mode == CONST_HARMONY);
226 *binding_flags = (mode == CONST)
227 ? IMMUTABLE_IS_INITIALIZED : IMMUTABLE_IS_INITIALIZED_HARMONY;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000228 return context;
229 }
230 }
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000231
232 } else if (context->IsCatchContext()) {
233 // Catch contexts have the variable name in the extension slot.
234 if (name->Equals(String::cast(context->extension()))) {
235 if (FLAG_trace_contexts) {
236 PrintF("=> found in catch context\n");
237 }
238 *index = Context::THROWN_OBJECT_INDEX;
239 *attributes = NONE;
240 *binding_flags = MUTABLE_IS_INITIALIZED;
241 return context;
242 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000243 }
244
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000245 // 3. Prepare to continue with the previous (next outermost) context.
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000246 if (context->IsNativeContext()) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000247 follow_context_chain = false;
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000248 } else {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000249 context = Handle<Context>(context->previous(), isolate);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000250 }
251 } while (follow_context_chain);
252
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000253 if (FLAG_trace_contexts) {
254 PrintF("=> no property/slot found\n");
255 }
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000256 return Handle<Object>::null();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000257}
258
259
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000260void Context::AddOptimizedFunction(JSFunction* function) {
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000261 ASSERT(IsNativeContext());
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000262#ifdef DEBUG
svenpanne@chromium.org619781a2012-07-05 08:22:44 +0000263 if (FLAG_enable_slow_asserts) {
264 Object* element = get(OPTIMIZED_FUNCTIONS_LIST);
265 while (!element->IsUndefined()) {
266 CHECK(element != function);
267 element = JSFunction::cast(element)->next_function_link();
268 }
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000269 }
270
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000271 // Check that the context belongs to the weak native contexts list.
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000272 bool found = false;
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000273 Object* context = GetHeap()->native_contexts_list();
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000274 while (!context->IsUndefined()) {
275 if (context == this) {
276 found = true;
277 break;
278 }
279 context = Context::cast(context)->get(Context::NEXT_CONTEXT_LINK);
280 }
281 CHECK(found);
282#endif
verwaest@chromium.orge4ee6de2012-11-06 12:13:00 +0000283
284 // If the function link field is already used then the function was
285 // enqueued as a code flushing candidate and we remove it now.
286 if (!function->next_function_link()->IsUndefined()) {
287 CodeFlusher* flusher = GetHeap()->mark_compact_collector()->code_flusher();
288 flusher->EvictCandidate(function);
289 }
290
291 ASSERT(function->next_function_link()->IsUndefined());
292
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000293 function->set_next_function_link(get(OPTIMIZED_FUNCTIONS_LIST));
294 set(OPTIMIZED_FUNCTIONS_LIST, function);
295}
296
297
298void Context::RemoveOptimizedFunction(JSFunction* function) {
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000299 ASSERT(IsNativeContext());
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000300 Object* element = get(OPTIMIZED_FUNCTIONS_LIST);
301 JSFunction* prev = NULL;
302 while (!element->IsUndefined()) {
303 JSFunction* element_function = JSFunction::cast(element);
304 ASSERT(element_function->next_function_link()->IsUndefined() ||
305 element_function->next_function_link()->IsJSFunction());
306 if (element_function == function) {
307 if (prev == NULL) {
308 set(OPTIMIZED_FUNCTIONS_LIST, element_function->next_function_link());
309 } else {
310 prev->set_next_function_link(element_function->next_function_link());
311 }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000312 element_function->set_next_function_link(GetHeap()->undefined_value());
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000313 return;
314 }
315 prev = element_function;
316 element = element_function->next_function_link();
317 }
318 UNREACHABLE();
319}
320
321
jkummerow@chromium.org3d00d0a2013-09-04 13:57:32 +0000322void Context::SetOptimizedFunctionsListHead(Object* head) {
323 ASSERT(IsNativeContext());
324 set(OPTIMIZED_FUNCTIONS_LIST, head);
325}
326
327
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000328Object* Context::OptimizedFunctionsListHead() {
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000329 ASSERT(IsNativeContext());
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000330 return get(OPTIMIZED_FUNCTIONS_LIST);
331}
332
333
jkummerow@chromium.org3d00d0a2013-09-04 13:57:32 +0000334void Context::AddOptimizedCode(Code* code) {
335 ASSERT(IsNativeContext());
336 ASSERT(code->kind() == Code::OPTIMIZED_FUNCTION);
337 ASSERT(code->next_code_link()->IsUndefined());
338 code->set_next_code_link(get(OPTIMIZED_CODE_LIST));
339 set(OPTIMIZED_CODE_LIST, code);
340}
341
342
343void Context::SetOptimizedCodeListHead(Object* head) {
344 ASSERT(IsNativeContext());
345 set(OPTIMIZED_CODE_LIST, head);
346}
347
348
349Object* Context::OptimizedCodeListHead() {
350 ASSERT(IsNativeContext());
351 return get(OPTIMIZED_CODE_LIST);
352}
353
354
355void Context::SetDeoptimizedCodeListHead(Object* head) {
356 ASSERT(IsNativeContext());
357 set(DEOPTIMIZED_CODE_LIST, head);
358}
359
360
361Object* Context::DeoptimizedCodeListHead() {
362 ASSERT(IsNativeContext());
363 return get(DEOPTIMIZED_CODE_LIST);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000364}
365
366
ulan@chromium.org56c14af2012-09-20 12:51:09 +0000367Handle<Object> Context::ErrorMessageForCodeGenerationFromStrings() {
ulan@chromium.org09d7ab52013-02-25 15:50:35 +0000368 Handle<Object> result(error_message_for_code_gen_from_strings(),
369 GetIsolate());
370 if (!result->IsUndefined()) return result;
371 return GetIsolate()->factory()->NewStringFromAscii(i::CStrVector(
372 "Code generation from strings disallowed for this context"));
ulan@chromium.org56c14af2012-09-20 12:51:09 +0000373}
374
375
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000376#ifdef DEBUG
danno@chromium.org81cac2b2012-07-10 11:28:27 +0000377bool Context::IsBootstrappingOrValidParentContext(
378 Object* object, Context* child) {
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000379 // During bootstrapping we allow all objects to pass as
380 // contexts. This is necessary to fix circular dependencies.
ulan@chromium.org09d7ab52013-02-25 15:50:35 +0000381 if (child->GetIsolate()->bootstrapper()->IsActive()) return true;
danno@chromium.org81cac2b2012-07-10 11:28:27 +0000382 if (!object->IsContext()) return false;
383 Context* context = Context::cast(object);
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000384 return context->IsNativeContext() || context->IsGlobalContext() ||
385 context->IsModuleContext() || !child->IsModuleContext();
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000386}
387
388
mstarzinger@chromium.orge9000182013-09-03 11:25:39 +0000389bool Context::IsBootstrappingOrGlobalObject(Isolate* isolate, Object* object) {
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000390 // During bootstrapping we allow all objects to pass as global
391 // objects. This is necessary to fix circular dependencies.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000392 return isolate->heap()->gc_state() != Heap::NOT_IN_GC ||
393 isolate->bootstrapper()->IsActive() ||
394 object->IsGlobalObject();
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000395}
396#endif
397
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000398} } // namespace v8::internal