OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/api.h" | 5 #include "src/api.h" |
6 | 6 |
7 #include <string.h> // For memcpy, strlen. | 7 #include <string.h> // For memcpy, strlen. |
8 #ifdef V8_USE_ADDRESS_SANITIZER | 8 #ifdef V8_USE_ADDRESS_SANITIZER |
9 #include <sanitizer/asan_interface.h> | 9 #include <sanitizer/asan_interface.h> |
10 #endif // V8_USE_ADDRESS_SANITIZER | 10 #endif // V8_USE_ADDRESS_SANITIZER |
(...skipping 5601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5612 void v8::V8::InitializeExternalStartupData(const char* natives_blob, | 5612 void v8::V8::InitializeExternalStartupData(const char* natives_blob, |
5613 const char* snapshot_blob) { | 5613 const char* snapshot_blob) { |
5614 i::InitializeExternalStartupData(natives_blob, snapshot_blob); | 5614 i::InitializeExternalStartupData(natives_blob, snapshot_blob); |
5615 } | 5615 } |
5616 | 5616 |
5617 | 5617 |
5618 const char* v8::V8::GetVersion() { | 5618 const char* v8::V8::GetVersion() { |
5619 return i::Version::GetVersion(); | 5619 return i::Version::GetVersion(); |
5620 } | 5620 } |
5621 | 5621 |
5622 static i::Handle<i::Context> CreateEnvironment( | 5622 template <typename ObjectType> |
| 5623 struct InvokeBootstrapper; |
| 5624 |
| 5625 template <> |
| 5626 struct InvokeBootstrapper<i::Context> { |
| 5627 i::Handle<i::Context> Invoke( |
| 5628 i::Isolate* isolate, i::MaybeHandle<i::JSGlobalProxy> maybe_global_proxy, |
| 5629 v8::Local<v8::ObjectTemplate> global_object_template, |
| 5630 v8::ExtensionConfiguration* extensions, size_t context_snapshot_index) { |
| 5631 return isolate->bootstrapper()->CreateEnvironment( |
| 5632 maybe_global_proxy, global_object_template, extensions, |
| 5633 context_snapshot_index); |
| 5634 } |
| 5635 }; |
| 5636 |
| 5637 template <> |
| 5638 struct InvokeBootstrapper<i::JSGlobalProxy> { |
| 5639 i::Handle<i::JSGlobalProxy> Invoke( |
| 5640 i::Isolate* isolate, i::MaybeHandle<i::JSGlobalProxy> maybe_global_proxy, |
| 5641 v8::Local<v8::ObjectTemplate> global_object_template, |
| 5642 v8::ExtensionConfiguration* extensions, size_t context_snapshot_index) { |
| 5643 USE(maybe_global_proxy); |
| 5644 USE(extensions); |
| 5645 USE(context_snapshot_index); |
| 5646 return isolate->bootstrapper()->NewDetachedGlobal(global_object_template); |
| 5647 } |
| 5648 }; |
| 5649 |
| 5650 template <typename ObjectType> |
| 5651 static i::Handle<ObjectType> CreateEnvironment( |
5623 i::Isolate* isolate, v8::ExtensionConfiguration* extensions, | 5652 i::Isolate* isolate, v8::ExtensionConfiguration* extensions, |
5624 v8::Local<ObjectTemplate> global_template, | 5653 v8::Local<ObjectTemplate> global_template, |
5625 v8::Local<Value> maybe_global_proxy, size_t context_snapshot_index) { | 5654 v8::Local<Value> maybe_global_proxy, size_t context_snapshot_index) { |
5626 i::Handle<i::Context> env; | 5655 i::Handle<ObjectType> result; |
5627 | 5656 |
5628 // Enter V8 via an ENTER_V8 scope. | 5657 // Enter V8 via an ENTER_V8 scope. |
5629 { | 5658 { |
5630 ENTER_V8(isolate); | 5659 ENTER_V8(isolate); |
5631 v8::Local<ObjectTemplate> proxy_template = global_template; | 5660 v8::Local<ObjectTemplate> proxy_template = global_template; |
5632 i::Handle<i::FunctionTemplateInfo> proxy_constructor; | 5661 i::Handle<i::FunctionTemplateInfo> proxy_constructor; |
5633 i::Handle<i::FunctionTemplateInfo> global_constructor; | 5662 i::Handle<i::FunctionTemplateInfo> global_constructor; |
5634 | 5663 |
5635 if (!global_template.IsEmpty()) { | 5664 if (!global_template.IsEmpty()) { |
5636 // Make sure that the global_template has a constructor. | 5665 // Make sure that the global_template has a constructor. |
(...skipping 22 matching lines...) Expand all Loading... |
5659 isolate->heap()->undefined_value()); | 5688 isolate->heap()->undefined_value()); |
5660 } | 5689 } |
5661 } | 5690 } |
5662 | 5691 |
5663 i::Handle<i::Object> proxy = Utils::OpenHandle(*maybe_global_proxy, true); | 5692 i::Handle<i::Object> proxy = Utils::OpenHandle(*maybe_global_proxy, true); |
5664 i::MaybeHandle<i::JSGlobalProxy> maybe_proxy; | 5693 i::MaybeHandle<i::JSGlobalProxy> maybe_proxy; |
5665 if (!proxy.is_null()) { | 5694 if (!proxy.is_null()) { |
5666 maybe_proxy = i::Handle<i::JSGlobalProxy>::cast(proxy); | 5695 maybe_proxy = i::Handle<i::JSGlobalProxy>::cast(proxy); |
5667 } | 5696 } |
5668 // Create the environment. | 5697 // Create the environment. |
5669 env = isolate->bootstrapper()->CreateEnvironment( | 5698 InvokeBootstrapper<ObjectType> invoke; |
5670 maybe_proxy, proxy_template, extensions, context_snapshot_index); | 5699 result = invoke.Invoke(isolate, maybe_proxy, proxy_template, extensions, |
| 5700 context_snapshot_index); |
5671 | 5701 |
5672 // Restore the access check info on the global template. | 5702 // Restore the access check info on the global template. |
5673 if (!global_template.IsEmpty()) { | 5703 if (!global_template.IsEmpty()) { |
5674 DCHECK(!global_constructor.is_null()); | 5704 DCHECK(!global_constructor.is_null()); |
5675 DCHECK(!proxy_constructor.is_null()); | 5705 DCHECK(!proxy_constructor.is_null()); |
5676 global_constructor->set_access_check_info( | 5706 global_constructor->set_access_check_info( |
5677 proxy_constructor->access_check_info()); | 5707 proxy_constructor->access_check_info()); |
5678 global_constructor->set_needs_access_check( | 5708 global_constructor->set_needs_access_check( |
5679 proxy_constructor->needs_access_check()); | 5709 proxy_constructor->needs_access_check()); |
5680 } | 5710 } |
5681 } | 5711 } |
5682 // Leave V8. | 5712 // Leave V8. |
5683 | 5713 |
5684 return env; | 5714 return result; |
5685 } | 5715 } |
5686 | 5716 |
5687 Local<Context> v8::Context::New(v8::Isolate* external_isolate, | 5717 Local<Context> v8::Context::New(v8::Isolate* external_isolate, |
5688 v8::ExtensionConfiguration* extensions, | 5718 v8::ExtensionConfiguration* extensions, |
5689 v8::Local<ObjectTemplate> global_template, | 5719 v8::Local<ObjectTemplate> global_template, |
5690 v8::Local<Value> global_object, | 5720 v8::Local<Value> global_object, |
5691 size_t context_snapshot_index) { | 5721 size_t context_snapshot_index) { |
5692 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate); | 5722 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate); |
5693 LOG_API(isolate, Context, New); | 5723 LOG_API(isolate, Context, New); |
5694 i::HandleScope scope(isolate); | 5724 i::HandleScope scope(isolate); |
5695 ExtensionConfiguration no_extensions; | 5725 ExtensionConfiguration no_extensions; |
5696 if (extensions == NULL) extensions = &no_extensions; | 5726 if (extensions == NULL) extensions = &no_extensions; |
5697 i::Handle<i::Context> env = | 5727 i::Handle<i::Context> env = |
5698 CreateEnvironment(isolate, extensions, global_template, global_object, | 5728 CreateEnvironment<i::Context>(isolate, extensions, global_template, |
5699 context_snapshot_index); | 5729 global_object, context_snapshot_index); |
5700 if (env.is_null()) { | 5730 if (env.is_null()) { |
5701 if (isolate->has_pending_exception()) { | 5731 if (isolate->has_pending_exception()) { |
5702 isolate->OptionalRescheduleException(true); | 5732 isolate->OptionalRescheduleException(true); |
5703 } | 5733 } |
5704 return Local<Context>(); | 5734 return Local<Context>(); |
5705 } | 5735 } |
5706 return Utils::ToLocal(scope.CloseAndEscape(env)); | 5736 return Utils::ToLocal(scope.CloseAndEscape(env)); |
5707 } | 5737 } |
5708 | 5738 |
| 5739 Local<Object> v8::Context::NewDetachedGlobal( |
| 5740 v8::Isolate* external_isolate, v8::Local<ObjectTemplate> global_template) { |
| 5741 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate); |
| 5742 LOG_API(isolate, Context, NewDetachedGlobal); |
| 5743 i::HandleScope scope(isolate); |
| 5744 i::Handle<i::FunctionTemplateInfo> global_constructor = |
| 5745 EnsureConstructor(isolate, *global_template); |
| 5746 Utils::ApiCheck(global_constructor->needs_access_check(), |
| 5747 "v8::Context::NewDetachedGlobal", |
| 5748 "Global template needs to have access checks enabled."); |
| 5749 i::Handle<i::AccessCheckInfo> access_check_info = i::handle( |
| 5750 i::AccessCheckInfo::cast(global_constructor->access_check_info()), |
| 5751 isolate); |
| 5752 Utils::ApiCheck(access_check_info->named_interceptor() != nullptr, |
| 5753 "v8::Context::NewDetachedGlobal", |
| 5754 "Global template needs to have access check handlers."); |
| 5755 i::Handle<i::JSGlobalProxy> global_proxy = |
| 5756 CreateEnvironment<i::JSGlobalProxy>(isolate, nullptr, global_template, |
| 5757 v8::Local<v8::Value>(), 0); |
| 5758 if (global_proxy.is_null()) { |
| 5759 if (isolate->has_pending_exception()) { |
| 5760 isolate->OptionalRescheduleException(true); |
| 5761 } |
| 5762 return Local<Object>(); |
| 5763 } |
| 5764 return Utils::ToLocal( |
| 5765 scope.CloseAndEscape(i::Handle<i::JSObject>::cast(global_proxy))); |
| 5766 } |
5709 | 5767 |
5710 void v8::Context::SetSecurityToken(Local<Value> token) { | 5768 void v8::Context::SetSecurityToken(Local<Value> token) { |
5711 i::Handle<i::Context> env = Utils::OpenHandle(this); | 5769 i::Handle<i::Context> env = Utils::OpenHandle(this); |
5712 i::Handle<i::Object> token_handle = Utils::OpenHandle(*token); | 5770 i::Handle<i::Object> token_handle = Utils::OpenHandle(*token); |
5713 env->set_security_token(*token_handle); | 5771 env->set_security_token(*token_handle); |
5714 } | 5772 } |
5715 | 5773 |
5716 | 5774 |
5717 void v8::Context::UseDefaultSecurityToken() { | 5775 void v8::Context::UseDefaultSecurityToken() { |
5718 i::Handle<i::Context> env = Utils::OpenHandle(this); | 5776 i::Handle<i::Context> env = Utils::OpenHandle(this); |
(...skipping 3180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8899 Address callback_address = | 8957 Address callback_address = |
8900 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8958 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8901 VMState<EXTERNAL> state(isolate); | 8959 VMState<EXTERNAL> state(isolate); |
8902 ExternalCallbackScope call_scope(isolate, callback_address); | 8960 ExternalCallbackScope call_scope(isolate, callback_address); |
8903 callback(info); | 8961 callback(info); |
8904 } | 8962 } |
8905 | 8963 |
8906 | 8964 |
8907 } // namespace internal | 8965 } // namespace internal |
8908 } // namespace v8 | 8966 } // namespace v8 |
OLD | NEW |