Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Unified Diff: src/api.cc

Issue 2107673003: Add an API to create a detached global object (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/v8.h ('k') | src/api-natives.h » ('j') | src/api-natives.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 79eb6198ca3f37cde9a0ee0121b56f4fabde7a99..2ef79e07b291a75c1655e27ccd6e131de407ce11 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> v8::Context::New(v8::Isolate* external_isolate,
@@ -5695,8 +5725,8 @@ Local<Context> v8::Context::New(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);
@@ -5706,6 +5736,34 @@ Local<Context> v8::Context::New(v8::Isolate* external_isolate,
return Utils::ToLocal(scope.CloseAndEscape(env));
}
+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);
« no previous file with comments | « include/v8.h ('k') | src/api-natives.h » ('j') | src/api-natives.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698