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 |
121 Context* Context::script_context() { | 126 Context* Context::script_context() { |
122 Context* current = this; | 127 Context* current = this; |
123 while (!current->IsScriptContext()) { | 128 while (!current->IsScriptContext()) { |
124 current = current->previous(); | 129 current = current->previous(); |
125 } | 130 } |
126 return current; | 131 return current; |
127 } | 132 } |
128 | 133 |
129 | 134 |
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 | |
141 JSObject* Context::global_proxy() { | 135 JSObject* Context::global_proxy() { |
142 return native_context()->global_proxy_object(); | 136 return native_context()->global_proxy_object(); |
143 } | 137 } |
144 | 138 |
145 | 139 |
146 void Context::set_global_proxy(JSObject* object) { | 140 void Context::set_global_proxy(JSObject* object) { |
147 native_context()->set_global_proxy_object(object); | 141 native_context()->set_global_proxy_object(object); |
148 } | 142 } |
149 | 143 |
150 | 144 |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 Handle<JSFunction> function) { | 544 Handle<JSFunction> function) { |
551 #define COMPARE_FUNCTION(index, type, name) \ | 545 #define COMPARE_FUNCTION(index, type, name) \ |
552 if (*function == native_context->get(index)) return true; | 546 if (*function == native_context->get(index)) return true; |
553 NATIVE_CONTEXT_JS_BUILTINS(COMPARE_FUNCTION); | 547 NATIVE_CONTEXT_JS_BUILTINS(COMPARE_FUNCTION); |
554 #undef COMPARE_FUNCTION | 548 #undef COMPARE_FUNCTION |
555 return false; | 549 return false; |
556 } | 550 } |
557 | 551 |
558 | 552 |
559 #ifdef DEBUG | 553 #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 |
560 bool Context::IsBootstrappingOrValidParentContext( | 563 bool Context::IsBootstrappingOrValidParentContext( |
561 Object* object, Context* child) { | 564 Object* object, Context* child) { |
562 // During bootstrapping we allow all objects to pass as | 565 // During bootstrapping we allow all objects to pass as |
563 // contexts. This is necessary to fix circular dependencies. | 566 // contexts. This is necessary to fix circular dependencies. |
564 if (child->GetIsolate()->bootstrapper()->IsActive()) return true; | 567 if (child->GetIsolate()->bootstrapper()->IsActive()) return true; |
565 if (!object->IsContext()) return false; | 568 if (!object->IsContext()) return false; |
566 Context* context = Context::cast(object); | 569 Context* context = Context::cast(object); |
567 return context->IsNativeContext() || context->IsScriptContext() || | 570 return context->IsNativeContext() || context->IsScriptContext() || |
568 context->IsModuleContext() || !child->IsModuleContext(); | 571 context->IsModuleContext() || !child->IsModuleContext(); |
569 } | 572 } |
570 | 573 |
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 } | |
578 #endif | 574 #endif |
579 | 575 |
580 | 576 |
581 void Context::IncrementErrorsThrown() { | 577 void Context::IncrementErrorsThrown() { |
582 DCHECK(IsNativeContext()); | 578 DCHECK(IsNativeContext()); |
583 | 579 |
584 int previous_value = errors_thrown()->value(); | 580 int previous_value = errors_thrown()->value(); |
585 set_errors_thrown(Smi::FromInt(previous_value + 1)); | 581 set_errors_thrown(Smi::FromInt(previous_value + 1)); |
586 } | 582 } |
587 | 583 |
588 | 584 |
589 int Context::GetErrorsThrown() { return errors_thrown()->value(); } | 585 int Context::GetErrorsThrown() { return errors_thrown()->value(); } |
590 | 586 |
591 } // namespace internal | 587 } // namespace internal |
592 } // namespace v8 | 588 } // namespace v8 |
OLD | NEW |