From 3d3b02b9c09e363a80b781e130a96d569efcf370 Mon Sep 17 00:00:00 2001 From: Luke Wilde Date: Thu, 23 Apr 2026 19:19:01 +0100 Subject: [PATCH] LibJS: Use the real globalThis value Previously it used `realm.[[GlobalObject]]` instead of `realm.[[GlobalEnv]].[[GlobalThisValue]]`. In LibWeb, that corresponds to Window and WindowProxy respectively. --- Libraries/LibJS/Runtime/GlobalObject.cpp | 2 +- .../HTML/globalThis-is-WindowProxy.txt | 9 ++++++++ .../input/HTML/globalThis-is-WindowProxy.html | 22 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/HTML/globalThis-is-WindowProxy.txt create mode 100644 Tests/LibWeb/Text/input/HTML/globalThis-is-WindowProxy.html diff --git a/Libraries/LibJS/Runtime/GlobalObject.cpp b/Libraries/LibJS/Runtime/GlobalObject.cpp index bb630dab6ab..3d6bb1a5a79 100644 --- a/Libraries/LibJS/Runtime/GlobalObject.cpp +++ b/Libraries/LibJS/Runtime/GlobalObject.cpp @@ -114,7 +114,7 @@ void set_default_global_bindings(Realm& realm) global.define_direct_property(vm.names.encodeURIComponent, realm.intrinsics().encode_uri_component_function(), attr); // 19.1 Value Properties of the Global Object, https://tc39.es/ecma262/#sec-value-properties-of-the-global-object - global.define_direct_property(vm.names.globalThis, &global, attr); + global.define_direct_property(vm.names.globalThis, &realm.global_environment().global_this_value(), attr); global.define_direct_property(vm.names.Infinity, js_infinity(), 0); global.define_direct_property(vm.names.NaN, js_nan(), 0); global.define_direct_property(vm.names.undefined, js_undefined(), 0); diff --git a/Tests/LibWeb/Text/expected/HTML/globalThis-is-WindowProxy.txt b/Tests/LibWeb/Text/expected/HTML/globalThis-is-WindowProxy.txt new file mode 100644 index 00000000000..fb08cbda07f --- /dev/null +++ b/Tests/LibWeb/Text/expected/HTML/globalThis-is-WindowProxy.txt @@ -0,0 +1,9 @@ +globalThis === window: true +globalThis === self: true +globalThis === frames: true +globalThis === this: true +iframe contentWindow === iframe globalThis: true +iframe globalThis === iframe self: true +iframe realm globalThis === window: true +globalThis !== iframe globalThis: true +Object.getPrototypeOf(globalThis) === Object.getPrototypeOf(window): true diff --git a/Tests/LibWeb/Text/input/HTML/globalThis-is-WindowProxy.html b/Tests/LibWeb/Text/input/HTML/globalThis-is-WindowProxy.html new file mode 100644 index 00000000000..af6188853f5 --- /dev/null +++ b/Tests/LibWeb/Text/input/HTML/globalThis-is-WindowProxy.html @@ -0,0 +1,22 @@ + + + +