Commit 3775e3a2 authored by tzik's avatar tzik Committed by Commit Bot

Expose v8::Context::DetachGlobal to d8

This expose v8::Context::DetachGlobal() as Realm.detachGlobal() in d8,
so that we can test API behaviors on Blink's detached iframes.

Change-Id: I4de1dd1a20d5862aba709e36d1d6afa9b221df6c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1554322Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Taiju Tsuiki <tzik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60649}
parent ad44c258
......@@ -1121,6 +1121,23 @@ void Shell::RealmNavigate(const v8::FunctionCallbackInfo<v8::Value>& args) {
CreateRealm(args, index, global_object);
}
// Realm.detachGlobal(i) detaches the global objects of realm i from realm i.
void Shell::RealmDetachGlobal(const v8::FunctionCallbackInfo<v8::Value>& args) {
Isolate* isolate = args.GetIsolate();
PerIsolateData* data = PerIsolateData::Get(isolate);
int index = data->RealmIndexOrThrow(args, 0);
if (index == -1) return;
if (index == 0 || index == data->realm_current_ ||
index == data->realm_switch_) {
Throw(args.GetIsolate(), "Invalid realm index");
return;
}
HandleScope scope(isolate);
Local<Context> realm = Local<Context>::New(isolate, data->realms_[index]);
realm->DetachGlobal();
}
// Realm.dispose(i) disposes the reference to the realm i.
void Shell::RealmDispose(const v8::FunctionCallbackInfo<v8::Value>& args) {
Isolate* isolate = args.GetIsolate();
......@@ -1807,6 +1824,10 @@ Local<ObjectTemplate> Shell::CreateGlobalTemplate(Isolate* isolate) {
String::NewFromUtf8(isolate, "navigate", NewStringType::kNormal)
.ToLocalChecked(),
FunctionTemplate::New(isolate, RealmNavigate));
realm_template->Set(
String::NewFromUtf8(isolate, "detachGlobal", NewStringType::kNormal)
.ToLocalChecked(),
FunctionTemplate::New(isolate, RealmDetachGlobal));
realm_template->Set(
String::NewFromUtf8(isolate, "dispose", NewStringType::kNormal)
.ToLocalChecked(),
......
......@@ -428,6 +428,8 @@ class Shell : public i::AllStatic {
static void RealmNavigate(const v8::FunctionCallbackInfo<v8::Value>& args);
static void RealmCreateAllowCrossRealmAccess(
const v8::FunctionCallbackInfo<v8::Value>& args);
static void RealmDetachGlobal(
const v8::FunctionCallbackInfo<v8::Value>& args);
static void RealmDispose(const v8::FunctionCallbackInfo<v8::Value>& args);
static void RealmSwitch(const v8::FunctionCallbackInfo<v8::Value>& args);
static void RealmEval(const v8::FunctionCallbackInfo<v8::Value>& args);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment