OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 i::Object** HandleScope::CreateHandle(i::HeapObject* value) { | 743 i::Object** HandleScope::CreateHandle(i::HeapObject* value) { |
744 ASSERT(value->IsHeapObject()); | 744 ASSERT(value->IsHeapObject()); |
745 return reinterpret_cast<i::Object**>( | 745 return reinterpret_cast<i::Object**>( |
746 i::HandleScope::CreateHandle(value->GetIsolate(), value)); | 746 i::HandleScope::CreateHandle(value->GetIsolate(), value)); |
747 } | 747 } |
748 | 748 |
749 | 749 |
750 void Context::Enter() { | 750 void Context::Enter() { |
751 i::Handle<i::Context> env = Utils::OpenHandle(this); | 751 i::Handle<i::Context> env = Utils::OpenHandle(this); |
752 i::Isolate* isolate = env->GetIsolate(); | 752 i::Isolate* isolate = env->GetIsolate(); |
753 if (IsDeadCheck(isolate, "v8::Context::Enter()")) return; | |
754 ENTER_V8(isolate); | 753 ENTER_V8(isolate); |
755 | |
756 isolate->handle_scope_implementer()->EnterContext(env); | 754 isolate->handle_scope_implementer()->EnterContext(env); |
757 | |
758 isolate->handle_scope_implementer()->SaveContext(isolate->context()); | 755 isolate->handle_scope_implementer()->SaveContext(isolate->context()); |
759 isolate->set_context(*env); | 756 isolate->set_context(*env); |
760 } | 757 } |
761 | 758 |
762 | 759 |
763 void Context::Exit() { | 760 void Context::Exit() { |
764 // Exit is essentially a static function and doesn't use the | 761 i::Handle<i::Context> context = Utils::OpenHandle(this); |
765 // receiver, so we have to get the current isolate from the thread | 762 i::Isolate* isolate = context->GetIsolate(); |
766 // local. | 763 ENTER_V8(isolate); |
767 i::Isolate* isolate = i::Isolate::Current(); | 764 if (!ApiCheck(isolate->handle_scope_implementer()->LeaveContext(context), |
768 if (!isolate->IsInitialized()) return; | |
769 | |
770 if (!ApiCheck(isolate->handle_scope_implementer()->LeaveLastContext(), | |
771 "v8::Context::Exit()", | 765 "v8::Context::Exit()", |
772 "Cannot exit non-entered context")) { | 766 "Cannot exit non-entered context")) { |
773 return; | 767 return; |
774 } | 768 } |
775 | |
776 // Content of 'last_context' could be NULL. | 769 // Content of 'last_context' could be NULL. |
777 i::Context* last_context = | 770 i::Context* last_context = |
778 isolate->handle_scope_implementer()->RestoreContext(); | 771 isolate->handle_scope_implementer()->RestoreContext(); |
779 isolate->set_context(last_context); | 772 isolate->set_context(last_context); |
780 } | 773 } |
781 | 774 |
782 | 775 |
783 static void* DecodeSmiToAligned(i::Object* value, const char* location) { | 776 static void* DecodeSmiToAligned(i::Object* value, const char* location) { |
784 ApiCheck(value->IsSmi(), location, "Not a Smi"); | 777 ApiCheck(value->IsSmi(), location, "Not a Smi"); |
785 return reinterpret_cast<void*>(value); | 778 return reinterpret_cast<void*>(value); |
(...skipping 4701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5487 i::Handle<i::Context> env = Utils::OpenHandle(this); | 5480 i::Handle<i::Context> env = Utils::OpenHandle(this); |
5488 return reinterpret_cast<Isolate*>(env->GetIsolate()); | 5481 return reinterpret_cast<Isolate*>(env->GetIsolate()); |
5489 } | 5482 } |
5490 | 5483 |
5491 | 5484 |
5492 v8::Local<v8::Context> Context::GetEntered() { | 5485 v8::Local<v8::Context> Context::GetEntered() { |
5493 i::Isolate* isolate = i::Isolate::Current(); | 5486 i::Isolate* isolate = i::Isolate::Current(); |
5494 if (!EnsureInitializedForIsolate(isolate, "v8::Context::GetEntered()")) { | 5487 if (!EnsureInitializedForIsolate(isolate, "v8::Context::GetEntered()")) { |
5495 return Local<Context>(); | 5488 return Local<Context>(); |
5496 } | 5489 } |
5497 i::Handle<i::Object> last = | 5490 return reinterpret_cast<Isolate*>(isolate)->GetEnteredContext(); |
5498 isolate->handle_scope_implementer()->LastEnteredContext(); | |
5499 if (last.is_null()) return Local<Context>(); | |
5500 i::Handle<i::Context> context = i::Handle<i::Context>::cast(last); | |
5501 return Utils::ToLocal(context); | |
5502 } | 5491 } |
5503 | 5492 |
5504 | 5493 |
5505 v8::Local<v8::Context> Context::GetCurrent() { | 5494 v8::Local<v8::Context> Context::GetCurrent() { |
5506 i::Isolate* isolate = i::Isolate::Current(); | 5495 i::Isolate* isolate = i::Isolate::Current(); |
5507 if (IsDeadCheck(isolate, "v8::Context::GetCurrent()")) { | 5496 if (IsDeadCheck(isolate, "v8::Context::GetCurrent()")) { |
5508 return Local<Context>(); | 5497 return Local<Context>(); |
5509 } | 5498 } |
5510 return reinterpret_cast<Isolate*>(isolate)->GetCurrentContext(); | 5499 return reinterpret_cast<Isolate*>(isolate)->GetCurrentContext(); |
5511 } | 5500 } |
5512 | 5501 |
5513 | 5502 |
5514 v8::Local<v8::Context> Context::GetCalling() { | 5503 v8::Local<v8::Context> Context::GetCalling() { |
5515 i::Isolate* isolate = i::Isolate::Current(); | 5504 i::Isolate* isolate = i::Isolate::Current(); |
5516 if (IsDeadCheck(isolate, "v8::Context::GetCalling()")) { | 5505 if (IsDeadCheck(isolate, "v8::Context::GetCalling()")) { |
5517 return Local<Context>(); | 5506 return Local<Context>(); |
5518 } | 5507 } |
5519 i::Handle<i::Object> calling = | 5508 return reinterpret_cast<Isolate*>(isolate)->GetCallingContext(); |
5520 isolate->GetCallingNativeContext(); | |
5521 if (calling.is_null()) return Local<Context>(); | |
5522 i::Handle<i::Context> context = i::Handle<i::Context>::cast(calling); | |
5523 return Utils::ToLocal(context); | |
5524 } | 5509 } |
5525 | 5510 |
5526 | 5511 |
5527 v8::Local<v8::Object> Context::Global() { | 5512 v8::Local<v8::Object> Context::Global() { |
5528 i::Isolate* isolate = i::Isolate::Current(); | 5513 i::Handle<i::Context> context = Utils::OpenHandle(this); |
5529 if (IsDeadCheck(isolate, "v8::Context::Global()")) { | 5514 i::Isolate* isolate = context->GetIsolate(); |
5530 return Local<v8::Object>(); | |
5531 } | |
5532 i::Object** ctx = reinterpret_cast<i::Object**>(this); | |
5533 i::Handle<i::Context> context = | |
5534 i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); | |
5535 i::Handle<i::Object> global(context->global_proxy(), isolate); | 5515 i::Handle<i::Object> global(context->global_proxy(), isolate); |
5536 return Utils::ToLocal(i::Handle<i::JSObject>::cast(global)); | 5516 return Utils::ToLocal(i::Handle<i::JSObject>::cast(global)); |
5537 } | 5517 } |
5538 | 5518 |
5539 | 5519 |
5540 void Context::DetachGlobal() { | 5520 void Context::DetachGlobal() { |
5541 i::Isolate* isolate = i::Isolate::Current(); | 5521 i::Handle<i::Context> context = Utils::OpenHandle(this); |
5542 if (IsDeadCheck(isolate, "v8::Context::DetachGlobal()")) return; | 5522 i::Isolate* isolate = context->GetIsolate(); |
5543 ENTER_V8(isolate); | 5523 ENTER_V8(isolate); |
5544 i::Object** ctx = reinterpret_cast<i::Object**>(this); | |
5545 i::Handle<i::Context> context = | |
5546 i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); | |
5547 isolate->bootstrapper()->DetachGlobal(context); | 5524 isolate->bootstrapper()->DetachGlobal(context); |
5548 } | 5525 } |
5549 | 5526 |
5550 | 5527 |
5551 void Context::ReattachGlobal(Handle<Object> global_object) { | 5528 void Context::ReattachGlobal(Handle<Object> global_object) { |
5552 i::Isolate* isolate = i::Isolate::Current(); | 5529 i::Handle<i::Context> context = Utils::OpenHandle(this); |
5553 if (IsDeadCheck(isolate, "v8::Context::ReattachGlobal()")) return; | 5530 i::Isolate* isolate = context->GetIsolate(); |
5554 ENTER_V8(isolate); | 5531 ENTER_V8(isolate); |
5555 i::Object** ctx = reinterpret_cast<i::Object**>(this); | |
5556 i::Handle<i::Context> context = | |
5557 i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); | |
5558 i::Handle<i::JSGlobalProxy> global_proxy = | 5532 i::Handle<i::JSGlobalProxy> global_proxy = |
5559 i::Handle<i::JSGlobalProxy>::cast(Utils::OpenHandle(*global_object)); | 5533 i::Handle<i::JSGlobalProxy>::cast(Utils::OpenHandle(*global_object)); |
5560 isolate->bootstrapper()->ReattachGlobal(context, global_proxy); | 5534 isolate->bootstrapper()->ReattachGlobal(context, global_proxy); |
5561 } | 5535 } |
5562 | 5536 |
5563 | 5537 |
5564 void Context::AllowCodeGenerationFromStrings(bool allow) { | 5538 void Context::AllowCodeGenerationFromStrings(bool allow) { |
5565 i::Isolate* isolate = i::Isolate::Current(); | 5539 i::Handle<i::Context> context = Utils::OpenHandle(this); |
5566 if (IsDeadCheck(isolate, "v8::Context::AllowCodeGenerationFromStrings()")) { | 5540 i::Isolate* isolate = context->GetIsolate(); |
5567 return; | |
5568 } | |
5569 ENTER_V8(isolate); | 5541 ENTER_V8(isolate); |
5570 i::Object** ctx = reinterpret_cast<i::Object**>(this); | |
5571 i::Handle<i::Context> context = | |
5572 i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); | |
5573 context->set_allow_code_gen_from_strings( | 5542 context->set_allow_code_gen_from_strings( |
5574 allow ? isolate->heap()->true_value() : isolate->heap()->false_value()); | 5543 allow ? isolate->heap()->true_value() : isolate->heap()->false_value()); |
5575 } | 5544 } |
5576 | 5545 |
5577 | 5546 |
5578 bool Context::IsCodeGenerationFromStringsAllowed() { | 5547 bool Context::IsCodeGenerationFromStringsAllowed() { |
5579 i::Isolate* isolate = i::Isolate::Current(); | 5548 i::Handle<i::Context> context = Utils::OpenHandle(this); |
5580 if (IsDeadCheck(isolate, | |
5581 "v8::Context::IsCodeGenerationFromStringsAllowed()")) { | |
5582 return false; | |
5583 } | |
5584 ENTER_V8(isolate); | |
5585 i::Object** ctx = reinterpret_cast<i::Object**>(this); | |
5586 i::Handle<i::Context> context = | |
5587 i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); | |
5588 return !context->allow_code_gen_from_strings()->IsFalse(); | 5549 return !context->allow_code_gen_from_strings()->IsFalse(); |
5589 } | 5550 } |
5590 | 5551 |
5591 | 5552 |
5592 void Context::SetErrorMessageForCodeGenerationFromStrings( | 5553 void Context::SetErrorMessageForCodeGenerationFromStrings( |
5593 Handle<String> error) { | 5554 Handle<String> error) { |
5594 i::Isolate* isolate = i::Isolate::Current(); | 5555 i::Handle<i::Context> context = Utils::OpenHandle(this); |
5595 if (IsDeadCheck(isolate, | |
5596 "v8::Context::SetErrorMessageForCodeGenerationFromStrings()")) { | |
5597 return; | |
5598 } | |
5599 ENTER_V8(isolate); | |
5600 i::Object** ctx = reinterpret_cast<i::Object**>(this); | |
5601 i::Handle<i::Context> context = | |
5602 i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); | |
5603 i::Handle<i::String> error_handle = Utils::OpenHandle(*error); | 5556 i::Handle<i::String> error_handle = Utils::OpenHandle(*error); |
5604 context->set_error_message_for_code_gen_from_strings(*error_handle); | 5557 context->set_error_message_for_code_gen_from_strings(*error_handle); |
5605 } | 5558 } |
5606 | 5559 |
5607 | 5560 |
5608 Local<v8::Object> ObjectTemplate::NewInstance() { | 5561 Local<v8::Object> ObjectTemplate::NewInstance() { |
5609 i::Isolate* isolate = i::Isolate::Current(); | 5562 i::Isolate* isolate = i::Isolate::Current(); |
5610 ON_BAILOUT(isolate, "v8::ObjectTemplate::NewInstance()", | 5563 ON_BAILOUT(isolate, "v8::ObjectTemplate::NewInstance()", |
5611 return Local<v8::Object>()); | 5564 return Local<v8::Object>()); |
5612 LOG_API(isolate, "ObjectTemplate::NewInstance"); | 5565 LOG_API(isolate, "ObjectTemplate::NewInstance"); |
(...skipping 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6640 } | 6593 } |
6641 | 6594 |
6642 | 6595 |
6643 CpuProfiler* Isolate::GetCpuProfiler() { | 6596 CpuProfiler* Isolate::GetCpuProfiler() { |
6644 i::CpuProfiler* cpu_profiler = | 6597 i::CpuProfiler* cpu_profiler = |
6645 reinterpret_cast<i::Isolate*>(this)->cpu_profiler(); | 6598 reinterpret_cast<i::Isolate*>(this)->cpu_profiler(); |
6646 return reinterpret_cast<CpuProfiler*>(cpu_profiler); | 6599 return reinterpret_cast<CpuProfiler*>(cpu_profiler); |
6647 } | 6600 } |
6648 | 6601 |
6649 | 6602 |
| 6603 bool Isolate::InContext() { |
| 6604 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6605 return isolate->context() != NULL; |
| 6606 } |
| 6607 |
| 6608 |
6650 v8::Local<v8::Context> Isolate::GetCurrentContext() { | 6609 v8::Local<v8::Context> Isolate::GetCurrentContext() { |
6651 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(this); | 6610 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
6652 i::Context* context = internal_isolate->context(); | 6611 i::Context* context = isolate->context(); |
6653 if (context == NULL) return Local<Context>(); | 6612 if (context == NULL) return Local<Context>(); |
6654 i::Context* native_context = context->global_object()->native_context(); | 6613 i::Context* native_context = context->global_object()->native_context(); |
6655 if (native_context == NULL) return Local<Context>(); | 6614 if (native_context == NULL) return Local<Context>(); |
6656 return Utils::ToLocal(i::Handle<i::Context>(native_context)); | 6615 return Utils::ToLocal(i::Handle<i::Context>(native_context)); |
6657 } | 6616 } |
6658 | 6617 |
6659 | 6618 |
| 6619 v8::Local<v8::Context> Isolate::GetCallingContext() { |
| 6620 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6621 i::Handle<i::Object> calling = isolate->GetCallingNativeContext(); |
| 6622 if (calling.is_null()) return Local<Context>(); |
| 6623 return Utils::ToLocal(i::Handle<i::Context>::cast(calling)); |
| 6624 } |
| 6625 |
| 6626 |
| 6627 v8::Local<v8::Context> Isolate::GetEnteredContext() { |
| 6628 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6629 i::Handle<i::Object> last = |
| 6630 isolate->handle_scope_implementer()->LastEnteredContext(); |
| 6631 if (last.is_null()) return Local<Context>(); |
| 6632 return Utils::ToLocal(i::Handle<i::Context>::cast(last)); |
| 6633 } |
| 6634 |
| 6635 |
6660 void Isolate::SetObjectGroupId(const Persistent<Value>& object, | 6636 void Isolate::SetObjectGroupId(const Persistent<Value>& object, |
6661 UniqueId id) { | 6637 UniqueId id) { |
6662 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(this); | 6638 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(this); |
6663 internal_isolate->global_handles()->SetObjectGroupId( | 6639 internal_isolate->global_handles()->SetObjectGroupId( |
6664 Utils::OpenPersistent(object).location(), | 6640 Utils::OpenPersistent(object).location(), |
6665 id); | 6641 id); |
6666 } | 6642 } |
6667 | 6643 |
6668 | 6644 |
6669 void Isolate::SetReferenceFromGroup(UniqueId id, | 6645 void Isolate::SetReferenceFromGroup(UniqueId id, |
(...skipping 1222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7892 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7868 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
7893 Address callback_address = | 7869 Address callback_address = |
7894 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7870 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
7895 VMState<EXTERNAL> state(isolate); | 7871 VMState<EXTERNAL> state(isolate); |
7896 ExternalCallbackScope call_scope(isolate, callback_address); | 7872 ExternalCallbackScope call_scope(isolate, callback_address); |
7897 callback(info); | 7873 callback(info); |
7898 } | 7874 } |
7899 | 7875 |
7900 | 7876 |
7901 } } // namespace v8::internal | 7877 } } // namespace v8::internal |
OLD | NEW |