| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/contexts.h" | 5 #include "src/contexts.h" |
| 6 | 6 |
| 7 #include "src/ast/scopeinfo.h" | 7 #include "src/ast/scopeinfo.h" |
| 8 #include "src/bootstrapper.h" | 8 #include "src/bootstrapper.h" |
| 9 #include "src/debug/debug.h" | 9 #include "src/debug/debug.h" |
| 10 #include "src/isolate-inl.h" | 10 #include "src/isolate-inl.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 return ScopeInfo::cast(object); | 111 return ScopeInfo::cast(object); |
| 112 } | 112 } |
| 113 | 113 |
| 114 | 114 |
| 115 String* Context::catch_name() { | 115 String* Context::catch_name() { |
| 116 DCHECK(IsCatchContext()); | 116 DCHECK(IsCatchContext()); |
| 117 return String::cast(extension()); | 117 return String::cast(extension()); |
| 118 } | 118 } |
| 119 | 119 |
| 120 | 120 |
| 121 JSGlobalObject* Context::global_object() { | |
| 122 return JSGlobalObject::cast(native_context()->extension()); | |
| 123 } | |
| 124 | |
| 125 | |
| 126 Context* Context::script_context() { | 121 Context* Context::script_context() { |
| 127 Context* current = this; | 122 Context* current = this; |
| 128 while (!current->IsScriptContext()) { | 123 while (!current->IsScriptContext()) { |
| 129 current = current->previous(); | 124 current = current->previous(); |
| 130 } | 125 } |
| 131 return current; | 126 return current; |
| 132 } | 127 } |
| 133 | 128 |
| 134 | 129 |
| 130 Context* Context::native_context() { |
| 131 // Fast case: the receiver context is already a native context. |
| 132 if (IsNativeContext()) return this; |
| 133 // The global object has a direct pointer to the native context. If the |
| 134 // following DCHECK fails, the native context is probably being accessed |
| 135 // indirectly during bootstrapping. This is unsupported. |
| 136 DCHECK(global_object()->IsJSGlobalObject()); |
| 137 return global_object()->native_context(); |
| 138 } |
| 139 |
| 140 |
| 135 JSObject* Context::global_proxy() { | 141 JSObject* Context::global_proxy() { |
| 136 return native_context()->global_proxy_object(); | 142 return native_context()->global_proxy_object(); |
| 137 } | 143 } |
| 138 | 144 |
| 139 | 145 |
| 140 void Context::set_global_proxy(JSObject* object) { | 146 void Context::set_global_proxy(JSObject* object) { |
| 141 native_context()->set_global_proxy_object(object); | 147 native_context()->set_global_proxy_object(object); |
| 142 } | 148 } |
| 143 | 149 |
| 144 | 150 |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 Handle<JSFunction> function) { | 550 Handle<JSFunction> function) { |
| 545 #define COMPARE_FUNCTION(index, type, name) \ | 551 #define COMPARE_FUNCTION(index, type, name) \ |
| 546 if (*function == native_context->get(index)) return true; | 552 if (*function == native_context->get(index)) return true; |
| 547 NATIVE_CONTEXT_JS_BUILTINS(COMPARE_FUNCTION); | 553 NATIVE_CONTEXT_JS_BUILTINS(COMPARE_FUNCTION); |
| 548 #undef COMPARE_FUNCTION | 554 #undef COMPARE_FUNCTION |
| 549 return false; | 555 return false; |
| 550 } | 556 } |
| 551 | 557 |
| 552 | 558 |
| 553 #ifdef DEBUG | 559 #ifdef DEBUG |
| 554 | |
| 555 bool Context::IsBootstrappingOrNativeContext(Isolate* isolate, Object* object) { | |
| 556 // During bootstrapping we allow all objects to pass as global | |
| 557 // objects. This is necessary to fix circular dependencies. | |
| 558 return isolate->heap()->gc_state() != Heap::NOT_IN_GC || | |
| 559 isolate->bootstrapper()->IsActive() || object->IsNativeContext(); | |
| 560 } | |
| 561 | |
| 562 | |
| 563 bool Context::IsBootstrappingOrValidParentContext( | 560 bool Context::IsBootstrappingOrValidParentContext( |
| 564 Object* object, Context* child) { | 561 Object* object, Context* child) { |
| 565 // During bootstrapping we allow all objects to pass as | 562 // During bootstrapping we allow all objects to pass as |
| 566 // contexts. This is necessary to fix circular dependencies. | 563 // contexts. This is necessary to fix circular dependencies. |
| 567 if (child->GetIsolate()->bootstrapper()->IsActive()) return true; | 564 if (child->GetIsolate()->bootstrapper()->IsActive()) return true; |
| 568 if (!object->IsContext()) return false; | 565 if (!object->IsContext()) return false; |
| 569 Context* context = Context::cast(object); | 566 Context* context = Context::cast(object); |
| 570 return context->IsNativeContext() || context->IsScriptContext() || | 567 return context->IsNativeContext() || context->IsScriptContext() || |
| 571 context->IsModuleContext() || !child->IsModuleContext(); | 568 context->IsModuleContext() || !child->IsModuleContext(); |
| 572 } | 569 } |
| 573 | 570 |
| 571 |
| 572 bool Context::IsBootstrappingOrGlobalObject(Isolate* isolate, Object* object) { |
| 573 // During bootstrapping we allow all objects to pass as global |
| 574 // objects. This is necessary to fix circular dependencies. |
| 575 return isolate->heap()->gc_state() != Heap::NOT_IN_GC || |
| 576 isolate->bootstrapper()->IsActive() || object->IsJSGlobalObject(); |
| 577 } |
| 574 #endif | 578 #endif |
| 575 | 579 |
| 576 | 580 |
| 577 void Context::IncrementErrorsThrown() { | 581 void Context::IncrementErrorsThrown() { |
| 578 DCHECK(IsNativeContext()); | 582 DCHECK(IsNativeContext()); |
| 579 | 583 |
| 580 int previous_value = errors_thrown()->value(); | 584 int previous_value = errors_thrown()->value(); |
| 581 set_errors_thrown(Smi::FromInt(previous_value + 1)); | 585 set_errors_thrown(Smi::FromInt(previous_value + 1)); |
| 582 } | 586 } |
| 583 | 587 |
| 584 | 588 |
| 585 int Context::GetErrorsThrown() { return errors_thrown()->value(); } | 589 int Context::GetErrorsThrown() { return errors_thrown()->value(); } |
| 586 | 590 |
| 587 } // namespace internal | 591 } // namespace internal |
| 588 } // namespace v8 | 592 } // namespace v8 |
| OLD | NEW |