Truly independent web browser
LibWeb: Read a binding's receiver realm after its brand check
Shannon Booth4480919a01ab
diff --git a/Libraries/LibWeb/Bindings/Wrappable.cpp b/Libraries/LibWeb/Bindings/Wrappable.cppindex c51b5f26558..521b1890ee6 100644--- a/Libraries/LibWeb/Bindings/Wrappable.cpp+++ b/Libraries/LibWeb/Bindings/Wrappable.cpp@@ -200,28 +200,6 @@ GC::Ptr<JS::HostObject> wrap(WrapperWorld& wrapper_world, JS::Realm& preferred_rreturn wrap(wrapper_world, preferred_realm, GC::Ref { *wrappable });}-JS::Realm& this_value_realm(JS::Realm& fallback_realm, JS::Value this_value)-{- // Generated native-function prologues normally validate and unwrap their- // receiver before asking for its realm. Keep this helper total for callers- // that pass an arbitrary JS::Value; the fallback is their explicit realm.- if (!this_value.is_object())- return fallback_realm;-- auto& object = this_value.as_object();- if (auto* window_proxy = HTML::WindowProxy::from_object(object)) {- // NB: A Window hosted by another process has no realm in this one, so the caller's realm stands in.- if (window_proxy->remote_window())- return fallback_realm;-- auto& proxy_realm = object.shape().realm();- if (!proxy_realm.host_defined())- return fallback_realm;- }-- return object.shape().realm();-}-JS::ThrowCompletionOr<void> set_prototype_of_cached_main_world_wrapper(Wrappable& wrappable, JS::Object& prototype){if (auto wrapper = wrappable.m_main_world_wrapper.ptr()) {diff --git a/Libraries/LibWeb/Bindings/Wrappable.h b/Libraries/LibWeb/Bindings/Wrappable.hindex 20617f707a5..4ffbe0b381c 100644--- a/Libraries/LibWeb/Bindings/Wrappable.h+++ b/Libraries/LibWeb/Bindings/Wrappable.h@@ -63,7 +63,6 @@ WEB_API GC::Ref<JS::HostObject> create_wrapper_for_wrappable(JS::Realm& wrapper_WEB_API JS::Realm& wrapper_realm_for_wrappable(WrapperWorld const& wrapper_world, JS::Realm& preferred_realm, GC::Ref<Wrappable>);WEB_API JS::Realm& wrapper_realm_for_node(WrapperWorld const& wrapper_world, JS::Realm& preferred_realm, DOM::Node&);WEB_API GC::Ref<JS::HostObject> wrap(WrapperWorld& wrapper_world, JS::Realm& preferred_realm, GC::Ref<Wrappable>);-WEB_API JS::Realm& this_value_realm(JS::Realm& fallback_realm, JS::Value);WEB_API JS::ThrowCompletionOr<void> set_prototype_of_cached_main_world_wrapper(Wrappable&, JS::Object&);WEB_API void preserve_wrapper(Wrappable&, JS::HostObject&);WEB_API bool wrapper_is_preserved(JS::HostObject const&);diff --git a/Libraries/LibWeb/DOM/EventTarget.cpp b/Libraries/LibWeb/DOM/EventTarget.cppindex 6456e296af4..ba981439966 100644--- a/Libraries/LibWeb/DOM/EventTarget.cpp+++ b/Libraries/LibWeb/DOM/EventTarget.cpp@@ -162,7 +162,7 @@ DOM::EventTarget* current_target_global(WebIDL::CallbackType& callback, DOM::Eveauto wrapper = current_target_wrapper(callback_realm, event);if (!wrapper)return nullptr;- return HTML::window_from_global_object(this_value_realm(callback_realm, wrapper).global_object());+ return HTML::window_from_global_object(wrapper->shape().realm().global_object());}void report_exception_for_callback(WebIDL::CallbackType& callback, JS::Value exception)@@ -175,7 +175,7 @@ JS::Completion invoke_event_listener(WebIDL::CallbackType& callback, DOM::Event&{auto& callback_realm = callback.associated_realm();auto this_value = current_target_wrapper(callback_realm, event);- auto& event_realm = this_value ? this_value_realm(callback_realm, this_value) : callback_realm;+ auto& event_realm = this_value ? this_value->shape().realm() : callback_realm;auto wrapped_event = Bindings::event(event_realm, GC::Ref { event });static Utf16FlyString const& handle_event = *new Utf16FlyString("handleEvent"_utf16_fly_string);@@ -201,7 +201,7 @@ JS::Completion invoke_event_handler(WebIDL::CallbackType& callback, DOM::Event&auto& callback_realm = callback.associated_realm();auto this_value = current_target_wrapper(callback_realm, event);- auto& event_realm = this_value ? this_value_realm(callback_realm, this_value) : callback_realm;+ auto& event_realm = this_value ? this_value->shape().realm() : callback_realm;auto wrapped_event = Bindings::event(event_realm, GC::Ref { event });return WebIDL::invoke_callback(callback, this_value.ptr(), { { wrapped_event } });diff --git a/Libraries/LibWeb/HTML/WindowProxy.h b/Libraries/LibWeb/HTML/WindowProxy.hindex b8972a2119c..c4cd5966eed 100644--- a/Libraries/LibWeb/HTML/WindowProxy.h+++ b/Libraries/LibWeb/HTML/WindowProxy.h@@ -39,7 +39,7 @@ public:static WindowProxy* from_object(JS::Object const& object){// Every platform object is a JS::HostObject, so its host class is read here without a virtual call. Every- // generated binding reaches this through Bindings::this_value_realm().+ // generated EventTarget and Window binding reaches this through impl_from().if (!object.is_platform_object())return nullptr;auto const& host_object = static_cast<JS::HostObject const&>(object);diff --git a/Meta/Generators/libweb_bindings/REALM_POLICY.md b/Meta/Generators/libweb_bindings/REALM_POLICY.mdindex fa36836459f..5c90139fa76 100644--- a/Meta/Generators/libweb_bindings/REALM_POLICY.md+++ b/Meta/Generators/libweb_bindings/REALM_POLICY.md@@ -55,6 +55,6 @@ Current `[NeedsCallerRealm]` opt-out categories:- Explicit WPT/spec carve-outs kept as caller-realm behavior, including`SourceBuffer.buffered` and `AbortSignal.abort()`/`timeout()`.-For `WindowProxy` receivers, `this_object_realm` is provided by-`Bindings::this_value_realm()`: main-world proxies resolve to the active-`[[Window]]` realm, while non-main-world proxies stay in their own realm.+For `WindowProxy` receivers, `this_object_realm` is the proxy's own realm:+main-world proxies follow their `[[Window]]` realm, while non-main-world+proxies stay in their own realm.diff --git a/Meta/Generators/libweb_bindings/attributes.py b/Meta/Generators/libweb_bindings/attributes.pyindex 6909ecf9c12..e31f5a767fe 100644--- a/Meta/Generators/libweb_bindings/attributes.py+++ b/Meta/Generators/libweb_bindings/attributes.py@@ -614,7 +614,7 @@ def write_attribute_getter()out.write(f""" idl_object = TRY(impl_from(vm, js_value));- [[maybe_unused]] auto& this_object_realm = this_value_realm(realm, js_value);+ [[maybe_unused]] auto& this_object_realm = js_value.as_object().shape().realm();{getter_steps}return R;@@ -655,12 +655,14 @@ def write_attribute_getter(""")impl_from_js_value = "TRY(impl_from(vm, js_value))"+ this_object_realm = "js_value.as_object().shape().realm()"if window_member_is_cross_origin_accessible(interface, attribute.name, "getter"):out.write(f" {the_remote_window(includes, 'js_value')}\n")impl_from_js_value = f"remote_window ? nullptr : {impl_from_js_value}"+ this_object_realm = f"remote_window ? realm : {this_object_realm}"out.write(f""" idl_object = {impl_from_js_value};- [[maybe_unused]] auto& this_object_realm = this_value_realm(realm, js_value);+ [[maybe_unused]] auto& this_object_realm = {this_object_realm};{getter_prelude}{getter_steps}@@ -709,7 +711,6 @@ def write_attribute_setter(auto js_value = vm.this_value();if (js_value.is_nullish())js_value = &realm.global_object();- [[maybe_unused]] auto& this_object_realm = this_value_realm(realm, js_value);""")@@ -794,6 +795,7 @@ def write_attribute_setter()return+ out.write(" [[maybe_unused]] auto& this_object_realm = js_value.as_object().shape().realm();\n\n")setter_realm_argument = member_realm_expr(attribute, interface=interface)setter_steps = f"TRY(WebIDL::throw_dom_exception_if_needed(vm, {setter_realm_argument}, [&] {{ return {implementation_attribute_setter_call(context, interface, attribute, setter_realm_argument)}; }}));\n return {{}};"is_reflected = "Reflect" in attribute.extended_attributesdiff --git a/Meta/Generators/libweb_bindings/iterables.py b/Meta/Generators/libweb_bindings/iterables.pyindex 5be0c0b96df..c8d283225f2 100644--- a/Meta/Generators/libweb_bindings/iterables.py+++ b/Meta/Generators/libweb_bindings/iterables.py@@ -185,12 +185,14 @@ def write_pair_iterable_declaration_functions({{auto& realm = *vm.current_realm();auto this_value = vm.this_value();- [[maybe_unused]] auto& this_object_realm = this_value_realm(realm, this_value);+ if (this_value.is_nullish())+ this_value = &realm.global_object();// 1. Let jsValue be ? ToObject(this value).// 2. If jsValue is a platform object, then perform a security check, passing jsValue, "%Symbol.iterator%", and "method".// 3. If jsValue does not implement definition, then throw a TypeError.- auto* this_impl = TRY(impl_from(vm));+ auto* this_impl = TRY(impl_from(vm, this_value));+ [[maybe_unused]] auto& this_object_realm = this_value.as_object().shape().realm();// 4. Return a newly created default iterator object for definition, with jsValue as its target, "key+value" as its kind, and index set to 0.return TRY(WebIDL::throw_dom_exception_if_needed(vm, this_object_realm, [&] {{ return {fully_qualified_name_for_interface(interface)}Iterator::create(this_object_realm, *this_impl, JS::Object::PropertyKind::KeyAndValue); }}));@@ -200,12 +202,14 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::keys){{auto& realm = *vm.current_realm();auto this_value = vm.this_value();- [[maybe_unused]] auto& this_object_realm = this_value_realm(realm, this_value);+ if (this_value.is_nullish())+ this_value = &realm.global_object();// 1. Let jsValue be ? ToObject(this value).// 2. If jsValue is a platform object, then perform a security check, passing jsValue, "keys", and "method".// 3. If jsValue does not implement definition, then throw a TypeError.- auto* this_impl = TRY(impl_from(vm));+ auto* this_impl = TRY(impl_from(vm, this_value));+ [[maybe_unused]] auto& this_object_realm = this_value.as_object().shape().realm();// 4. Return a newly created default iterator object for definition, with jsValue as its target, "key" as its kind, and index set to 0.return TRY(WebIDL::throw_dom_exception_if_needed(vm, this_object_realm, [&] {{ return {fully_qualified_name_for_interface(interface)}Iterator::create(this_object_realm, *this_impl, JS::Object::PropertyKind::Key); }}));@@ -215,12 +219,14 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::values){{auto& realm = *vm.current_realm();auto this_value = vm.this_value();- [[maybe_unused]] auto& this_object_realm = this_value_realm(realm, this_value);+ if (this_value.is_nullish())+ this_value = &realm.global_object();// 1. Let jsValue be ? ToObject(this value).// 2. If jsValue is a platform object, then perform a security check, passing jsValue, "values", and "method".// 3. If jsValue does not implement definition, then throw a TypeError.- auto* this_impl = TRY(impl_from(vm));+ auto* this_impl = TRY(impl_from(vm, this_value));+ [[maybe_unused]] auto& this_object_realm = this_value.as_object().shape().realm();// 4. Return a newly created default iterator object for definition, with jsValue as its target, "value" as its kind, and index set to 0.return TRY(WebIDL::throw_dom_exception_if_needed(vm, this_object_realm, [&] {{ return {fully_qualified_name_for_interface(interface)}Iterator::create(this_object_realm, *this_impl, JS::Object::PropertyKind::Value); }}));@@ -232,8 +238,8 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::for_each)auto this_value = vm.this_value();if (this_value.is_nullish())this_value = &realm.global_object();- [[maybe_unused]] auto& this_object_realm = this_value_realm(realm, this_value);auto* this_impl = TRY(impl_from(vm, this_value));+ [[maybe_unused]] auto& this_object_realm = this_value.as_object().shape().realm();auto callback = vm.argument(0);if (!callback.is_function())@@ -293,10 +299,9 @@ static JS::ThrowCompletionOr<{fully_qualified_name_for_interface(interface)}IterJS_DEFINE_NATIVE_FUNCTION({interface.name}IteratorPrototype::next){{- auto& realm = *vm.current_realm();auto this_value = vm.this_value();- [[maybe_unused]] auto& this_object_realm = this_value_realm(realm, this_value);auto* impl = TRY({make_name_acceptable_cpp(title_case_to_snake_case(iterator_interface_name))}_impl_from(vm));+ [[maybe_unused]] auto& this_object_realm = this_value.as_object().shape().realm();return TRY(WebIDL::throw_dom_exception_if_needed(vm, this_object_realm, [&] {{ return impl->next(this_object_realm); }}));}}@@ -326,8 +331,10 @@ def write_async_iterable_declaration_functions({{[[maybe_unused]] auto& realm = *vm.current_realm();auto this_value = vm.this_value();- [[maybe_unused]] auto& this_object_realm = this_value_realm(realm, this_value);- auto* impl = TRY(impl_from(vm));+ if (this_value.is_nullish())+ this_value = &realm.global_object();+ auto* impl = TRY(impl_from(vm, this_value));+ [[maybe_unused]] auto& this_object_realm = this_value.as_object().shape().realm();""")@@ -378,11 +385,9 @@ def write_async_iterator_prototype_implementation(JS_DEFINE_NATIVE_FUNCTION({interface.name}AsyncIteratorPrototype::next){{auto& realm = *vm.current_realm();- auto this_value = vm.this_value();- [[maybe_unused]] auto& this_object_realm = this_value_realm(realm, this_value);- return TRY(WebIDL::throw_dom_exception_if_needed(vm, this_object_realm, [&] {{- return WebIDL::AsyncIterator::next<{fully_qualified_name_for_interface(interface)}AsyncIterator>(this_object_realm, "{interface.name}AsyncIterator"sv);+ return TRY(WebIDL::throw_dom_exception_if_needed(vm, realm, [&] {{+ return WebIDL::AsyncIterator::next<{fully_qualified_name_for_interface(interface)}AsyncIterator>(realm, "{interface.name}AsyncIterator"sv);}}));}}"""@@ -393,13 +398,11 @@ JS_DEFINE_NATIVE_FUNCTION({interface.name}AsyncIteratorPrototype::next)JS_DEFINE_NATIVE_FUNCTION({interface.name}AsyncIteratorPrototype::return_){{auto& realm = *vm.current_realm();- auto this_value = vm.this_value();- [[maybe_unused]] auto& this_object_realm = this_value_realm(realm, this_value);auto value = vm.argument(0);- return TRY(WebIDL::throw_dom_exception_if_needed(vm, this_object_realm, [&] {{- return WebIDL::AsyncIterator::return_<{fully_qualified_name_for_interface(interface)}AsyncIterator>(this_object_realm, "{interface.name}AsyncIterator"sv, value);+ return TRY(WebIDL::throw_dom_exception_if_needed(vm, realm, [&] {{+ return WebIDL::AsyncIterator::return_<{fully_qualified_name_for_interface(interface)}AsyncIterator>(realm, "{interface.name}AsyncIterator"sv, value);}}));}}""")@@ -432,10 +435,10 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::get_size)auto this_value = vm.this_value();if (this_value.is_nullish())this_value = &realm.global_object();- [[maybe_unused]] auto& this_object_realm = this_value_realm(realm, this_value);// 1. Let O be the this value, implementation-checked against A with identifier "size" and type "getter".auto* this_impl = TRY(impl_from(vm, this_value));+ [[maybe_unused]] auto& this_object_realm = this_value.as_object().shape().realm();// 2. Let map be the map entries of the IDL value that represents a reference to O.GC::Ref<JS::Map> map = map_entries(this_object_realm, *this_impl);@@ -451,10 +454,10 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::entries)auto this_value = vm.this_value();if (this_value.is_nullish())this_value = &realm.global_object();- auto& this_object_realm = this_value_realm(realm, this_value);// 1. Let O be the this value, implementation-checked against A with identifier "entries" and type "method".auto* this_impl = TRY(impl_from(vm, this_value));+ auto& this_object_realm = this_value.as_object().shape().realm();// 2. Let map be the map entries of the IDL value that represents a reference to O.GC::Ref<JS::Map> map = map_entries(this_object_realm, *this_impl);@@ -470,10 +473,10 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::keys)auto this_value = vm.this_value();if (this_value.is_nullish())this_value = &realm.global_object();- auto& this_object_realm = this_value_realm(realm, this_value);// 1. Let O be the this value, implementation-checked against A with identifier "keys" and type "method".auto* this_impl = TRY(impl_from(vm, this_value));+ auto& this_object_realm = this_value.as_object().shape().realm();// 2. Let map be the map entries of the IDL value that represents a reference to O.GC::Ref<JS::Map> map = map_entries(this_object_realm, *this_impl);@@ -489,10 +492,10 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::values)auto this_value = vm.this_value();if (this_value.is_nullish())this_value = &realm.global_object();- auto& this_object_realm = this_value_realm(realm, this_value);// 1. Let O be the this value, implementation-checked against A with identifier "values" and type "method".auto* this_impl = TRY(impl_from(vm, this_value));+ auto& this_object_realm = this_value.as_object().shape().realm();// 2. Let map be the map entries of the IDL value that represents a reference to O.GC::Ref<JS::Map> map = map_entries(this_object_realm, *this_impl);@@ -508,10 +511,10 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::for_each)auto this_value = vm.this_value();if (this_value.is_nullish())this_value = &realm.global_object();- auto& this_object_realm = this_value_realm(realm, this_value);// 1. Let O be the this value, implementation-checked against A with identifier "forEach" and type "method".auto* this_impl = TRY(impl_from(vm, this_value));+ auto& this_object_realm = this_value.as_object().shape().realm();// 2. Let map be the map entries of the IDL value that represents a reference to O.GC::Ref<JS::Map> map = map_entries(this_object_realm, *this_impl);@@ -545,10 +548,10 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::get)auto this_value = vm.this_value();if (this_value.is_nullish())this_value = &realm.global_object();- auto& this_object_realm = this_value_realm(realm, this_value);// 1. Let O be the this value, implementation-checked against A with identifier "get" and type "method".auto* this_impl = TRY(impl_from(vm, this_value));+ auto& this_object_realm = this_value.as_object().shape().realm();// 3. Let keyType be the key type specified in the maplike declaration.// 4. Let keyArg be the first argument passed to this function, or undefined if not supplied.@@ -597,10 +600,10 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::set)auto this_value = vm.this_value();if (this_value.is_nullish())this_value = &realm.global_object();- auto& this_object_realm = this_value_realm(realm, this_value);// 1. Let O be the this value, implementation-checked against A with identifier "set" and type "method".auto* this_impl = TRY(impl_from(vm, this_value));+ auto& this_object_realm = this_value.as_object().shape().realm();// 3. Let keyType be the key type specified in the maplike declaration, and valueType be the value type.// 4. Let keyArg be the first argument passed to this function, or undefined if not supplied.@@ -706,11 +709,11 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::get_size)auto this_value = vm.this_value();if (this_value.is_nullish())this_value = &realm.global_object();- auto& this_object_realm = this_value_realm(realm, this_value);- auto& wrapper_world = host_defined_wrapper_world(this_object_realm);// 1. Let O be the this value, implementation-checked against A with identifier "size" and type "getter".auto* this_impl = TRY(impl_from(vm, this_value));+ auto& this_object_realm = this_value.as_object().shape().realm();+ auto& wrapper_world = host_defined_wrapper_world(this_object_realm);// 2. Let set be the set entries of the IDL value that represents a reference to O.GC::Ref<JS::Set> set = setlike_entries(this_object_realm, wrapper_world, *this_impl);@@ -726,11 +729,11 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::entries)auto this_value = vm.this_value();if (this_value.is_nullish())this_value = &realm.global_object();- auto& this_object_realm = this_value_realm(realm, this_value);- auto& wrapper_world = host_defined_wrapper_world(this_object_realm);// 1. Let O be the this value, implementation-checked against A with identifier "entries" and type "method".auto* this_impl = TRY(impl_from(vm, this_value));+ auto& this_object_realm = this_value.as_object().shape().realm();+ auto& wrapper_world = host_defined_wrapper_world(this_object_realm);// 2. Let set be the set entries of the IDL value that represents a reference to O.GC::Ref<JS::Set> set = setlike_entries(this_object_realm, wrapper_world, *this_impl);@@ -746,11 +749,11 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::values)auto this_value = vm.this_value();if (this_value.is_nullish())this_value = &realm.global_object();- auto& this_object_realm = this_value_realm(realm, this_value);- auto& wrapper_world = host_defined_wrapper_world(this_object_realm);// 1. Let O be the this value, implementation-checked against A with identifier "values" and type "method".auto* this_impl = TRY(impl_from(vm, this_value));+ auto& this_object_realm = this_value.as_object().shape().realm();+ auto& wrapper_world = host_defined_wrapper_world(this_object_realm);// 2. Let set be the set entries of the IDL value that represents a reference to O.GC::Ref<JS::Set> set = setlike_entries(this_object_realm, wrapper_world, *this_impl);@@ -766,11 +769,11 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::for_each)auto this_value = vm.this_value();if (this_value.is_nullish())this_value = &realm.global_object();- auto& this_object_realm = this_value_realm(realm, this_value);- auto& wrapper_world = host_defined_wrapper_world(this_object_realm);// 1. Let O be the this value, implementation-checked against A with identifier "forEach" and type "method".auto* this_impl = TRY(impl_from(vm, this_value));+ auto& this_object_realm = this_value.as_object().shape().realm();+ auto& wrapper_world = host_defined_wrapper_world(this_object_realm);// 2. Let set be the set entries of the IDL value that represents a reference to O.GC::Ref<JS::Set> set = setlike_entries(this_object_realm, wrapper_world, *this_impl);diff --git a/Meta/Generators/libweb_bindings/named_and_indexed_properties.py b/Meta/Generators/libweb_bindings/named_and_indexed_properties.pyindex 6799f5b0e01..afee34dad75 100644--- a/Meta/Generators/libweb_bindings/named_and_indexed_properties.py+++ b/Meta/Generators/libweb_bindings/named_and_indexed_properties.py@@ -799,10 +799,10 @@ def write_indexed_property_getter(out.write(f"""JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::{idl_identifier_cpp_name(operation)}){{- auto& realm = *vm.current_realm();+ [[maybe_unused]] auto& realm = *vm.current_realm();auto this_value = vm.this_value();[[maybe_unused]] auto* idl_object = TRY(impl_from(vm, this_value));- auto& this_object_realm = this_value_realm(realm, this_value);+ auto& this_object_realm = this_value.as_object().shape().realm();if (vm.argument_count() < 1)return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "{operation.name}");@@ -847,10 +847,10 @@ def write_named_property_getter(out.write(f"""JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::{idl_identifier_cpp_name(operation)}){{- auto& realm = *vm.current_realm();+ [[maybe_unused]] auto& realm = *vm.current_realm();auto this_value = vm.this_value();[[maybe_unused]] auto* idl_object = TRY(impl_from(vm, this_value));- auto& this_object_realm = this_value_realm(realm, this_value);+ auto& this_object_realm = this_value.as_object().shape().realm();if (vm.argument_count() < 1)return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "{operation.name}");@@ -920,10 +920,10 @@ def write_named_property_operation(out.write(f"""JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::{idl_identifier_cpp_name(operation)}){{- auto& realm = *vm.current_realm();+ [[maybe_unused]] auto& realm = *vm.current_realm();auto this_value = vm.this_value();[[maybe_unused]] auto* idl_object = TRY(impl_from(vm, this_value));- [[maybe_unused]] auto& this_object_realm = this_value_realm(realm, this_value);+ [[maybe_unused]] auto& this_object_realm = this_value.as_object().shape().realm();""")if len(operation.parameters) == 1:diff --git a/Meta/Generators/libweb_bindings/operations.py b/Meta/Generators/libweb_bindings/operations.pyindex 40c843638c0..edd1c4b9b47 100644--- a/Meta/Generators/libweb_bindings/operations.py+++ b/Meta/Generators/libweb_bindings/operations.py@@ -409,7 +409,7 @@ def write_stringifier()out.write(f""" auto* idl_object = TRY(impl_from(vm, this_value));- auto& this_object_realm = this_value_realm(realm, this_value);+ auto& this_object_realm = this_value.as_object().shape().realm();auto R = TRY(WebIDL::throw_dom_exception_if_needed(vm, this_object_realm, [&] {{ return {stringifier_call}; }}));return {to_javascript_value(stringifier_type, "R", includes, context, "this_object_realm")};}}@@ -486,12 +486,14 @@ def write_operation(""")impl_from_this_value = "TRY(impl_from(vm, this_value))"+ this_object_realm = "this_value.as_object().shape().realm()"if on_remote_window:out.write(f" {the_remote_window(includes, 'this_value')}\n")impl_from_this_value = f"remote_window ? nullptr : {impl_from_this_value}"+ this_object_realm = f"remote_window ? realm : {this_object_realm}"out.write(f""" [[maybe_unused]] {fully_qualified_name_for_interface(interface)}* idl_object = {impl_from_this_value};- [[maybe_unused]] auto& this_object_realm = this_value_realm(realm, this_value);+ [[maybe_unused]] auto& this_object_realm = {this_object_realm};""")@@ -792,7 +794,7 @@ def write_default_to_json_operation(if (this_value.is_nullish())this_value = &realm.global_object();[[maybe_unused]] auto* idl_object = TRY(impl_from(vm, this_value));- [[maybe_unused]] auto& this_object_realm = this_value_realm(realm, this_value);+ [[maybe_unused]] auto& this_object_realm = this_value.as_object().shape().realm();// 4. Let result be OrdinaryObjectCreate(%Object.prototype%).auto result = JS::Object::create(realm, realm.intrinsics().object_prototype());diff --git a/Tests/LibWeb/TestWindowProxyWorld.cpp b/Tests/LibWeb/TestWindowProxyWorld.cppindex 662ce06219d..a85f4095fd3 100644--- a/Tests/LibWeb/TestWindowProxyWorld.cpp+++ b/Tests/LibWeb/TestWindowProxyWorld.cpp@@ -131,7 +131,7 @@ TEST_CASE(per_world_windowproxy_and_window_wrapper)EXPECT(extension_proxy == browsing_context->window_proxy_for(*extension_world, extension_realm));EXPECT(extension_proxy->window().ptr() == window.ptr());EXPECT(extension_proxy->object().shape().prototype() == nullptr);- EXPECT(&Web::Bindings::this_value_realm(extension_realm, &extension_proxy->object()) == &extension_realm);+ EXPECT(&extension_proxy->realm() == &extension_realm);auto& extension_wrapper = Web::Bindings::platform_object_for_window(*window, extension_realm);EXPECT(&extension_wrapper != &main_wrapper);