| Index: src/api.cc
|
| diff --git a/src/api.cc b/src/api.cc
|
| index 86135fd83d2ab6460a8e96665a651f8a1af42f05..d9f85d6c5cca63246925aebb0b1f6fbde2649876 100644
|
| --- a/src/api.cc
|
| +++ b/src/api.cc
|
| @@ -5619,11 +5619,40 @@ const char* v8::V8::GetVersion() {
|
| return i::Version::GetVersion();
|
| }
|
|
|
| -static i::Handle<i::Context> CreateEnvironment(
|
| +template <typename ObjectType>
|
| +struct InvokeBootstrapper;
|
| +
|
| +template <>
|
| +struct InvokeBootstrapper<i::Context> {
|
| + i::Handle<i::Context> Invoke(
|
| + i::Isolate* isolate, i::MaybeHandle<i::JSGlobalProxy> maybe_global_proxy,
|
| + v8::Local<v8::ObjectTemplate> global_object_template,
|
| + v8::ExtensionConfiguration* extensions, size_t context_snapshot_index) {
|
| + return isolate->bootstrapper()->CreateEnvironment(
|
| + maybe_global_proxy, global_object_template, extensions,
|
| + context_snapshot_index);
|
| + }
|
| +};
|
| +
|
| +template <>
|
| +struct InvokeBootstrapper<i::JSGlobalProxy> {
|
| + i::Handle<i::JSGlobalProxy> Invoke(
|
| + i::Isolate* isolate, i::MaybeHandle<i::JSGlobalProxy> maybe_global_proxy,
|
| + v8::Local<v8::ObjectTemplate> global_object_template,
|
| + v8::ExtensionConfiguration* extensions, size_t context_snapshot_index) {
|
| + USE(maybe_global_proxy);
|
| + USE(extensions);
|
| + USE(context_snapshot_index);
|
| + return isolate->bootstrapper()->NewDetachedGlobal(global_object_template);
|
| + }
|
| +};
|
| +
|
| +template <typename ObjectType>
|
| +static i::Handle<ObjectType> CreateEnvironment(
|
| i::Isolate* isolate, v8::ExtensionConfiguration* extensions,
|
| v8::Local<ObjectTemplate> global_template,
|
| v8::Local<Value> maybe_global_proxy, size_t context_snapshot_index) {
|
| - i::Handle<i::Context> env;
|
| + i::Handle<ObjectType> result;
|
|
|
| // Enter V8 via an ENTER_V8 scope.
|
| {
|
| @@ -5666,8 +5695,9 @@ static i::Handle<i::Context> CreateEnvironment(
|
| maybe_proxy = i::Handle<i::JSGlobalProxy>::cast(proxy);
|
| }
|
| // Create the environment.
|
| - env = isolate->bootstrapper()->CreateEnvironment(
|
| - maybe_proxy, proxy_template, extensions, context_snapshot_index);
|
| + InvokeBootstrapper<ObjectType> invoke;
|
| + result = invoke.Invoke(isolate, maybe_proxy, proxy_template, extensions,
|
| + context_snapshot_index);
|
|
|
| // Restore the access check info on the global template.
|
| if (!global_template.IsEmpty()) {
|
| @@ -5681,7 +5711,7 @@ static i::Handle<i::Context> CreateEnvironment(
|
| }
|
| // Leave V8.
|
|
|
| - return env;
|
| + return result;
|
| }
|
|
|
| Local<Context> NewContext(v8::Isolate* external_isolate,
|
| @@ -5695,8 +5725,8 @@ Local<Context> NewContext(v8::Isolate* external_isolate,
|
| ExtensionConfiguration no_extensions;
|
| if (extensions == NULL) extensions = &no_extensions;
|
| i::Handle<i::Context> env =
|
| - CreateEnvironment(isolate, extensions, global_template, global_object,
|
| - context_snapshot_index);
|
| + CreateEnvironment<i::Context>(isolate, extensions, global_template,
|
| + global_object, context_snapshot_index);
|
| if (env.is_null()) {
|
| if (isolate->has_pending_exception()) {
|
| isolate->OptionalRescheduleException(true);
|
| @@ -5727,6 +5757,35 @@ MaybeLocal<Context> v8::Context::FromSnapshot(
|
| global_object, context_snapshot_index);
|
| }
|
|
|
| +Local<Object> v8::Context::NewDetachedGlobal(
|
| + v8::Isolate* external_isolate, v8::Local<ObjectTemplate> global_template) {
|
| + i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate);
|
| + LOG_API(isolate, Context, NewDetachedGlobal);
|
| + i::HandleScope scope(isolate);
|
| + i::Handle<i::FunctionTemplateInfo> global_constructor =
|
| + EnsureConstructor(isolate, *global_template);
|
| + Utils::ApiCheck(global_constructor->needs_access_check(),
|
| + "v8::Context::NewDetachedGlobal",
|
| + "Global template needs to have access checks enabled.");
|
| + i::Handle<i::AccessCheckInfo> access_check_info = i::handle(
|
| + i::AccessCheckInfo::cast(global_constructor->access_check_info()),
|
| + isolate);
|
| + Utils::ApiCheck(access_check_info->named_interceptor() != nullptr,
|
| + "v8::Context::NewDetachedGlobal",
|
| + "Global template needs to have access check handlers.");
|
| + i::Handle<i::JSGlobalProxy> global_proxy =
|
| + CreateEnvironment<i::JSGlobalProxy>(isolate, nullptr, global_template,
|
| + v8::Local<v8::Value>(), 0);
|
| + if (global_proxy.is_null()) {
|
| + if (isolate->has_pending_exception()) {
|
| + isolate->OptionalRescheduleException(true);
|
| + }
|
| + return Local<Object>();
|
| + }
|
| + return Utils::ToLocal(
|
| + scope.CloseAndEscape(i::Handle<i::JSObject>::cast(global_proxy)));
|
| +}
|
| +
|
| void v8::Context::SetSecurityToken(Local<Value> token) {
|
| i::Handle<i::Context> env = Utils::OpenHandle(this);
|
| i::Handle<i::Object> token_handle = Utils::OpenHandle(*token);
|
|
|