Commit d8c6aa70 authored by Mythri A's avatar Mythri A Committed by V8 LUCI CQ

[d8] Fix d8 to always return a global proxy for Realm.Global

Bug: chromium:1197053, chromium:324812
Change-Id: I2cccabf838e3a3acbb3adfed33aa59400ec91b11
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2821547Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Mythri Alle <mythria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74740}
parent 0bbddafd
......@@ -6210,7 +6210,7 @@ v8::Local<v8::Object> Context::Global() {
i::Handle<i::Context> context = Utils::OpenHandle(this);
i::Isolate* isolate = context->GetIsolate();
i::Handle<i::Object> global(context->global_proxy(), isolate);
// TODO(dcarney): This should always return the global proxy
// TODO(chromium:324812): This should always return the global proxy
// but can't presently as calls to GetProtoype will return the wrong result.
if (i::Handle<i::JSGlobalProxy>::cast(global)->IsDetachedFrom(
context->global_object())) {
......
......@@ -1604,8 +1604,22 @@ void Shell::RealmGlobal(const v8::FunctionCallbackInfo<v8::Value>& args) {
PerIsolateData* data = PerIsolateData::Get(args.GetIsolate());
int index = data->RealmIndexOrThrow(args, 0);
if (index == -1) return;
args.GetReturnValue().Set(
Local<Context>::New(args.GetIsolate(), data->realms_[index])->Global());
// TODO(chromium:324812): Ideally Context::Global should never return raw
// global objects but return a global proxy. Currently it returns global
// object when the global proxy is detached from the global object. The
// following is a workaround till we fix Context::Global so we don't leak
// global objects.
Local<Object> global =
Local<Context>::New(args.GetIsolate(), data->realms_[index])->Global();
i::Handle<i::Object> i_global = Utils::OpenHandle(*global);
if (i_global->IsJSGlobalObject()) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate());
i::Handle<i::JSObject> i_global_proxy =
handle(i::Handle<i::JSGlobalObject>::cast(i_global)->global_proxy(),
i_isolate);
global = Utils::ToLocal(i_global_proxy);
}
args.GetReturnValue().Set(global);
}
MaybeLocal<Context> Shell::CreateRealm(
......
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Flags: --allow-natives-syntax
Realm.createAllowCrossRealmAccess();
Realm.detachGlobal(1);
const global_var = Realm.global(1);
function f() {
return global_var.__proto__;
};
%EnsureFeedbackVectorForFunction(f);
assertThrows(f);
assertThrows(f);
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