Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
refactor(webapi): declare receivers for shared values and event targets
ldm0c2d4387b829b
diff --git a/moli-renderer-v8/src/context_bootstrap/broadcast_channel.rs b/moli-renderer-v8/src/context_bootstrap/broadcast_channel.rsindex 1dd6f1787..896f6642e 100644--- a/moli-renderer-v8/src/context_bootstrap/broadcast_channel.rs+++ b/moli-renderer-v8/src/context_bootstrap/broadcast_channel.rs@@ -26,7 +26,7 @@ const BROADCAST_CHANNEL_ONMESSAGE_SLOT: &str = "__lmBroadcastChannelOnmessage";const BROADCAST_CHANNEL_ONMESSAGEERROR_SLOT: &str = "__lmBroadcastChannelOnmessageerror";#[derive(WebApiObject)]-#[webapi(interface = web_api_interfaces::BroadcastChannel)]+#[webapi(interface = web_api_interfaces::BroadcastChannel, receiver)]struct BroadcastChannelObjectDeclaration<'scope> {#[webapi(slot = BROADCAST_CHANNEL_ID_SLOT)]channel_id: v8::Local<'scope, v8::Value>,@@ -49,27 +49,27 @@ struct BroadcastChannelObjectDeclaration<'scope> {#[webapi(method,enumerable,- callback = broadcast_channel_event_target_add_event_listener_callback+ callback = simple_event_target_add_event_listener_callback)]add_event_listener: (),#[webapi(method,enumerable,- callback = broadcast_channel_event_target_remove_event_listener_callback+ callback = simple_event_target_remove_event_listener_callback)]remove_event_listener: (),#[webapi(method,enumerable,- callback = broadcast_channel_event_target_dispatch_event_callback+ callback = simple_event_target_dispatch_event_callback)]dispatch_event: (),}#[derive(WebApiFunctionTemplate)]-#[webapi(interface = web_api_interfaces::BroadcastChannel, enumerable)]+#[webapi(interface = web_api_interfaces::BroadcastChannel, enumerable, receiver)]struct BroadcastChannelPrototypeDeclaration {#[webapi(accessor_property,@@ -326,49 +326,6 @@ fn broadcast_channel_is_closed<'s>(.is_some_and(|value| value.boolean_value(scope))}-fn broadcast_channel_receiver_branded<'s>(- scope: &mut v8::PinScope<'s, '_>,- receiver: v8::Local<'s, v8::Object>,-) -> bool {- web_api_interfaces::BroadcastChannel::is_instance(scope, receiver)-}--fn broadcast_channel_event_target_add_event_listener_callback<'s>(- scope: &mut v8::PinScope<'s, '_>,- args: v8::FunctionCallbackArguments<'s>,- rv: v8::ReturnValue<'s, v8::Value>,-) {- if !broadcast_channel_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }- simple_event_target_add_event_listener_callback(scope, args, rv);-}--fn broadcast_channel_event_target_remove_event_listener_callback<'s>(- scope: &mut v8::PinScope<'s, '_>,- args: v8::FunctionCallbackArguments<'s>,- rv: v8::ReturnValue<'s, v8::Value>,-) {- if !broadcast_channel_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }- simple_event_target_remove_event_listener_callback(scope, args, rv);-}--fn broadcast_channel_event_target_dispatch_event_callback<'s>(- scope: &mut v8::PinScope<'s, '_>,- args: v8::FunctionCallbackArguments<'s>,- rv: v8::ReturnValue<'s, v8::Value>,-) {- if !broadcast_channel_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }- simple_event_target_dispatch_event_callback(scope, args, rv);-}-fn close_broadcast_channel_object<'s>(scope: &mut v8::PinScope<'s, '_>,channel: v8::Local<'s, v8::Object>,@@ -462,10 +419,6 @@ fn broadcast_channel_name_getter_callback<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {- if !broadcast_channel_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }let value = get_private_value(scope, args.this(), BROADCAST_CHANNEL_NAME_SLOT).unwrap_or_else(|| v8str(scope, "").into());rv.set(value);@@ -476,10 +429,6 @@ fn broadcast_channel_event_handler_getter_callback<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {- if !broadcast_channel_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }let Some(handler) = callback_data_item(scope,&args,@@ -503,10 +452,6 @@ fn broadcast_channel_event_handler_setter_callback<'s>(args: v8::FunctionCallbackArguments<'s>,_rv: v8::ReturnValue<'_, v8::Value>,) {- if !broadcast_channel_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }let Some(handler) = callback_data_item(scope,&args,@@ -529,10 +474,6 @@ fn broadcast_channel_post_message_callback<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {- if !broadcast_channel_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }if broadcast_channel_is_closed(scope, args.this()) {throw_broadcast_channel_invalid_state(scope);return;@@ -585,10 +526,6 @@ fn broadcast_channel_close_callback<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {- if !broadcast_channel_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }close_broadcast_channel_object(scope, args.this());rv.set_undefined();}diff --git a/moli-renderer-v8/src/context_bootstrap/constructors/text_codecs.rs b/moli-renderer-v8/src/context_bootstrap/constructors/text_codecs.rsindex 093c8858a..68eb022a0 100644--- a/moli-renderer-v8/src/context_bootstrap/constructors/text_codecs.rs+++ b/moli-renderer-v8/src/context_bootstrap/constructors/text_codecs.rs@@ -24,7 +24,7 @@ struct TextEncoderObjectDeclaration {}#[derive(WebApiFunctionTemplate)]-#[webapi(interface = web_api_interfaces::TextEncoder, enumerable)]+#[webapi(interface = web_api_interfaces::TextEncoder, enumerable, receiver)]struct TextEncoderPrototypeDeclaration {#[webapi(method, length = 0, callback = text_encoder_encode_callback)]encode: (),@@ -51,7 +51,7 @@ struct TextDecoderObjectDeclaration {}#[derive(WebApiFunctionTemplate)]-#[webapi(interface = web_api_interfaces::TextDecoder, enumerable)]+#[webapi(interface = web_api_interfaces::TextDecoder, enumerable, receiver)]struct TextDecoderPrototypeDeclaration {#[webapi(method, length = 0, callback = text_decoder_decode_callback)]decode: (),@@ -164,10 +164,6 @@ fn text_codec_string_attribute_getter_callback<'s>(rv.set_empty_string();return;};- if !text_codec_receiver_branded_for_slot(scope, args.this(), slot) {- throw_type_error(scope, "Illegal invocation");- return;- }let value = get_private_value(scope, args.this(), slot).and_then(|value| value.to_string(scope)).map(|value| value.to_rust_string_lossy(scope))@@ -188,10 +184,6 @@ fn text_codec_bool_attribute_getter_callback<'s>(rv.set_bool(false);return;};- if !text_codec_receiver_branded_for_slot(scope, args.this(), slot) {- throw_type_error(scope, "Illegal invocation");- return;- }rv.set_bool(get_private_value(scope, args.this(), slot).is_some_and(|value| value.is_boolean() && value.boolean_value(scope)),@@ -225,10 +217,6 @@ fn text_encoder_encode_callback<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'s, v8::Value>,) {- if !text_encoder_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }let Some(parsed) = webidl::parse_args::<TextEncoderEncodeArgs>(scope, &args) else {rv.set_undefined();return;@@ -246,10 +234,6 @@ fn text_encoder_encode_into_callback<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'s, v8::Value>,) {- if !text_encoder_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }let Some(parsed) = webidl::parse_args::<TextEncoderEncodeIntoArgs>(scope, &args) else {rv.set_undefined();return;@@ -343,10 +327,6 @@ fn text_decoder_decode_callback<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'s, v8::Value>,) {- if !text_decoder_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }let Some(parsed) = webidl::parse_args::<TextDecoderDecodeArgs>(scope, &args) else {rv.set_undefined();return;@@ -380,34 +360,6 @@ fn text_decoder_decode_callback<'s>(}}-fn text_codec_receiver_branded_for_slot<'s>(- scope: &mut v8::PinScope<'s, '_>,- receiver: v8::Local<'s, v8::Object>,- slot: &str,-) -> bool {- match slot {- TEXT_ENCODER_ENCODING_SLOT => text_encoder_receiver_branded(scope, receiver),- TEXT_DECODER_ENCODING_SLOT | TEXT_DECODER_FATAL_SLOT | TEXT_DECODER_IGNORE_BOM_SLOT => {- text_decoder_receiver_branded(scope, receiver)- }- _ => false,- }-}--fn text_encoder_receiver_branded<'s>(- scope: &mut v8::PinScope<'s, '_>,- receiver: v8::Local<'s, v8::Object>,-) -> bool {- web_api_interfaces::TextEncoder::is_instance(scope, receiver)-}--fn text_decoder_receiver_branded<'s>(- scope: &mut v8::PinScope<'s, '_>,- receiver: v8::Local<'s, v8::Object>,-) -> bool {- web_api_interfaces::TextDecoder::is_instance(scope, receiver)-}-fn init_text_decoder_state(scope: &mut v8::PinScope<'_, '_>,decoder: v8::Local<'_, v8::Object>,diff --git a/moli-renderer-v8/src/context_bootstrap/css_runtime/typed_om/values.rs b/moli-renderer-v8/src/context_bootstrap/css_runtime/typed_om/values.rsindex a318edd50..d9835b84b 100644--- a/moli-renderer-v8/src/context_bootstrap/css_runtime/typed_om/values.rs+++ b/moli-renderer-v8/src/context_bootstrap/css_runtime/typed_om/values.rs@@ -47,7 +47,7 @@ struct CssKeywordValuePrototypeDeclaration {}#[derive(WebApiFunctionTemplate)]-#[webapi(interface = web_api_interfaces::CSSStyleValue, enumerable)]+#[webapi(interface = web_api_interfaces::CSSStyleValue, enumerable, receiver)]struct CssStyleValuePrototypeDeclaration {#[webapi(method = "toString", callback = css_style_value_to_string_callback, length = 0)]to_string: (),@@ -217,10 +217,6 @@ fn css_style_value_to_string_callback<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {- if !css_style_value_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }if let Some(unit) = css_unit_value_unit(scope, args.this()) {let value = css_unit_value_number(scope, args.this()).unwrap_or(0.0);let number = v8::Number::new(scope, value)@@ -353,13 +349,6 @@ fn css_unit_value_unit_getter_callback<'s>(}}-fn css_style_value_receiver_branded<'s>(- scope: &mut v8::PinScope<'s, '_>,- receiver: v8::Local<'s, v8::Object>,-) -> bool {- web_api_interfaces::CSSStyleValue::is_instance(scope, receiver)-}-fn css_unit_value_number<'s>(scope: &mut v8::PinScope<'s, '_>,receiver: v8::Local<'s, v8::Object>,diff --git a/moli-renderer-v8/src/context_bootstrap/geometry_runtime.rs b/moli-renderer-v8/src/context_bootstrap/geometry_runtime.rsindex caade8b62..d626ec5c6 100644--- a/moli-renderer-v8/src/context_bootstrap/geometry_runtime.rs+++ b/moli-renderer-v8/src/context_bootstrap/geometry_runtime.rs@@ -157,7 +157,7 @@ struct DomMatrixJsonDeclaration {}#[derive(WebApiFunctionTemplate)]-#[webapi(interface = web_api_interfaces::DOMPoint)]+#[webapi(interface = web_api_interfaces::DOMPoint, receiver)]struct DomPointPrototypeAccessorsDeclaration {#[webapi(accessor_property,@@ -194,7 +194,7 @@ struct DomPointPrototypeAccessorsDeclaration {}#[derive(WebApiFunctionTemplate)]-#[webapi(interface = web_api_interfaces::DOMPoint)]+#[webapi(interface = web_api_interfaces::DOMPoint, receiver)]struct DomPointPrototypeMethodsDeclaration {#[webapi(method = "toJSON", enumerable, callback = dom_point_to_json_callback)]to_json: (),@@ -579,7 +579,7 @@ pub(super) fn dom_point_clone_data<'s>(scope: &mut v8::PinScope<'s, '_>,object: v8::Local<'s, v8::Object>,) -> Option<(bool, [f64; 4])> {- if !dom_point_receiver_branded(scope, object) {+ if !web_api_interfaces::DOMPoint::is_instance(scope, object) {return None;}let mutable = web_api_interfaces::DOMPoint::is_instance(scope, object);@@ -692,10 +692,6 @@ fn dom_point_getter_callback<'s>(rv.set_undefined();return;};- if !dom_point_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }rv.set(get_private_value(scope, args.this(), slot).unwrap_or_else(|| v8::undefined(scope).into()),);@@ -711,10 +707,6 @@ fn dom_point_setter_callback<'s>(rv.set_undefined();return;};- if !dom_point_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }if get_private_value(scope, args.this(), DOM_POINT_READ_ONLY_SLOT).is_some_and(|value| value.boolean_value(scope)){@@ -926,10 +918,6 @@ fn dom_point_to_json_callback<'s>(mut rv: v8::ReturnValue<'_, v8::Value>,) {let this = args.this();- if !dom_point_receiver_branded(scope, this) {- throw_type_error(scope, "Illegal invocation");- return;- }let declaration = DomPointJsonDeclaration {x: dom_point_slot(scope, this, DOM_POINT_X_SLOT, 0.0),y: dom_point_slot(scope, this, DOM_POINT_Y_SLOT, 0.0),@@ -953,13 +941,6 @@ fn dom_point_slot<'s>(.unwrap_or(default)}-fn dom_point_receiver_branded<'s>(- scope: &mut v8::PinScope<'s, '_>,- receiver: v8::Local<'s, v8::Object>,-) -> bool {- web_api_interfaces::DOMPoint::is_instance(scope, receiver)-}-fn dom_matrix_require_readonly_receiver<'s>(scope: &mut v8::PinScope<'s, '_>,receiver: v8::Local<'s, v8::Object>,diff --git a/moli-renderer-v8/src/context_bootstrap/notification_runtime.rs b/moli-renderer-v8/src/context_bootstrap/notification_runtime.rsindex 0b6878f9f..3fd03928d 100644--- a/moli-renderer-v8/src/context_bootstrap/notification_runtime.rs+++ b/moli-renderer-v8/src/context_bootstrap/notification_runtime.rs@@ -48,7 +48,7 @@ pub(crate) struct NotificationOptionsPayload {}#[derive(WebApiObject)]-#[webapi(interface = web_api_interfaces::Notification)]+#[webapi(interface = web_api_interfaces::Notification, receiver)]struct NotificationObjectDeclaration<'scope> {#[webapi(slot = NOTIFICATION_TITLE_SLOT)]title: String,@@ -101,21 +101,21 @@ struct NotificationObjectDeclaration<'scope> {#[webapi(method,enumerable,- callback = notification_event_target_add_event_listener_callback+ callback = simple_event_target_add_event_listener_callback)]add_event_listener: (),#[webapi(method,enumerable,- callback = notification_event_target_remove_event_listener_callback+ callback = simple_event_target_remove_event_listener_callback)]remove_event_listener: (),#[webapi(method,enumerable,- callback = notification_event_target_dispatch_event_callback+ callback = simple_event_target_dispatch_event_callback)]dispatch_event: (),@@ -124,7 +124,7 @@ struct NotificationObjectDeclaration<'scope> {}#[derive(WebApiFunctionTemplate)]-#[webapi(interface = web_api_interfaces::Notification)]+#[webapi(interface = web_api_interfaces::Notification, receiver)]struct NotificationPrototypeDeclaration {#[webapi(accessor_property = "onclick",@@ -132,8 +132,7 @@ struct NotificationPrototypeDeclaration {setter = simple_event_target_handler_setter_callback,data = v8str(scope, "onclick"),setter_data = v8str(scope, "onclick"),- enumerable,- receiver = web_api_interfaces::Notification::is_instance+ enumerable)]onclick: (),#[webapi(@@ -142,8 +141,7 @@ struct NotificationPrototypeDeclaration {setter = simple_event_target_handler_setter_callback,data = v8str(scope, "onerror"),setter_data = v8str(scope, "onerror"),- enumerable,- receiver = web_api_interfaces::Notification::is_instance+ enumerable)]onerror: (),#[webapi(@@ -152,8 +150,7 @@ struct NotificationPrototypeDeclaration {setter = simple_event_target_handler_setter_callback,data = v8str(scope, "onshow"),setter_data = v8str(scope, "onshow"),- enumerable,- receiver = web_api_interfaces::Notification::is_instance+ enumerable)]onshow: (),#[webapi(@@ -162,8 +159,7 @@ struct NotificationPrototypeDeclaration {setter = simple_event_target_handler_setter_callback,data = v8str(scope, "onclose"),setter_data = v8str(scope, "onclose"),- enumerable,- receiver = web_api_interfaces::Notification::is_instance+ enumerable)]onclose: (),@@ -1089,10 +1085,6 @@ fn notification_title_getter_callback<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'s, v8::Value>,) {- if !notification_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }rv.set(get_private_value(scope, args.this(), NOTIFICATION_TITLE_SLOT).unwrap_or_else(|| v8str(scope, "").into()),@@ -1104,10 +1096,6 @@ fn notification_data_getter_callback<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'s, v8::Value>,) {- if !notification_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }rv.set(get_private_value(scope, args.this(), NOTIFICATION_DATA_SLOT).unwrap_or_else(|| v8::null(scope).into()),@@ -1175,10 +1163,6 @@ fn notification_vibrate_getter_callback<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'s, v8::Value>,) {- if !notification_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }rv.set(get_private_value(scope, args.this(), NOTIFICATION_VIBRATE_SLOT).unwrap_or_else(|| v8::Array::new(scope, 0).into()),@@ -1190,10 +1174,6 @@ fn notification_timestamp_getter_callback<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'s, v8::Value>,) {- if !notification_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }rv.set(get_private_value(scope, args.this(), NOTIFICATION_TIMESTAMP_SLOT).unwrap_or_else(|| v8::Number::new(scope, 0.0).into()),@@ -1213,10 +1193,6 @@ fn notification_silent_getter_callback<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'s, v8::Value>,) {- if !notification_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }rv.set(get_private_value(scope, args.this(), NOTIFICATION_SILENT_SLOT).unwrap_or_else(|| v8::null(scope).into()),@@ -1238,10 +1214,6 @@ fn notification_string_slot_getter<'s>(slot: &'static str,default_value: &'static str,) {- if !notification_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }rv.set(get_private_value(scope, args.this(), slot).unwrap_or_else(|| v8str(scope, default_value).into()),@@ -1254,10 +1226,6 @@ fn notification_bool_slot_getter<'s>(rv: &mut v8::ReturnValue<'s, v8::Value>,slot: &'static str,) {- if !notification_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }rv.set(get_private_value(scope, args.this(), slot).unwrap_or_else(|| v8::Boolean::new(scope, false).into()),@@ -1269,10 +1237,6 @@ fn notification_actions_getter_callback<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'s, v8::Value>,) {- if !notification_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }rv.set(get_private_value(scope, args.this(), NOTIFICATION_ACTIONS_SLOT).unwrap_or_else(|| v8::Array::new(scope, 0).into()),@@ -1285,10 +1249,6 @@ fn notification_close_callback<'s>(_rv: v8::ReturnValue<'s, v8::Value>,) {let this = args.this();- if !notification_receiver_branded(scope, this) {- throw_type_error(scope, "Illegal invocation");- return;- }let Some(record_id) = notification_private_u64(scope, this, NOTIFICATION_RECORD_ID_SLOT) else {return;};@@ -1319,49 +1279,6 @@ fn notification_close_callback<'s>(}}-fn notification_receiver_branded<'s>(- scope: &mut v8::PinScope<'s, '_>,- receiver: v8::Local<'s, v8::Object>,-) -> bool {- web_api_interfaces::Notification::is_instance(scope, receiver)-}--fn notification_event_target_add_event_listener_callback<'s>(- scope: &mut v8::PinScope<'s, '_>,- args: v8::FunctionCallbackArguments<'s>,- rv: v8::ReturnValue<'s, v8::Value>,-) {- if !notification_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }- simple_event_target_add_event_listener_callback(scope, args, rv);-}--fn notification_event_target_remove_event_listener_callback<'s>(- scope: &mut v8::PinScope<'s, '_>,- args: v8::FunctionCallbackArguments<'s>,- rv: v8::ReturnValue<'s, v8::Value>,-) {- if !notification_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }- simple_event_target_remove_event_listener_callback(scope, args, rv);-}--fn notification_event_target_dispatch_event_callback<'s>(- scope: &mut v8::PinScope<'s, '_>,- args: v8::FunctionCallbackArguments<'s>,- rv: v8::ReturnValue<'s, v8::Value>,-) {- if !notification_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }- simple_event_target_dispatch_event_callback(scope, args, rv);-}-fn notification_private_u64<'s>(scope: &mut v8::PinScope<'s, '_>,notification: v8::Local<'s, v8::Object>,diff --git a/moli-renderer-v8/src/script_vm/tests/declarative_receivers.rs b/moli-renderer-v8/src/script_vm/tests/declarative_receivers.rsindex 67421ddec..98b924c08 100644--- a/moli-renderer-v8/src/script_vm/tests/declarative_receivers.rs+++ b/moli-renderer-v8/src/script_vm/tests/declarative_receivers.rs@@ -134,3 +134,68 @@ fn canvas_declarations_check_setters_before_conversion_and_keep_foreign_backing_assert_eq!(vm.eval("receiverSetup").unwrap(), "ok");finish_receiver_checks(&mut vm);}++#[test]+fn shared_value_and_event_declarations_keep_native_brands_across_realms() {+ let mut vm = receiver_test_vm();+ vm.eval(r#"(() => {+ const {child, assert, check, getters} = receiverChecks;+ for (const realm of [window, child]) {+ const other = realm === window ? child : window;+ const channel = new other.BroadcastChannel('receiver-check');+ getters(realm, 'BroadcastChannel', channel, ['name', 'onmessage', 'onmessageerror']);+ for (const name of ['postMessage', 'close']) check(realm, channel, realm.BroadcastChannel.prototype[name]);+ const localChannel = new realm.BroadcastChannel('receiver-check');+ for (const name of ['addEventListener', 'removeEventListener', 'dispatchEvent']) check(realm, channel, localChannel[name]);+ for (const name of ['onmessage', 'onmessageerror']) {+ const setter = Object.getOwnPropertyDescriptor(realm.BroadcastChannel.prototype, name).set;+ check(realm, channel, setter);+ const handler = () => {};+ setter.call(channel, handler);+ assert(channel[name] === handler, 'foreign channel handler identity');+ }+ let events = 0;+ const listener = () => events++;+ localChannel.addEventListener.call(channel, 'probe', listener);+ localChannel.dispatchEvent.call(channel, new other.Event('probe'));+ localChannel.removeEventListener.call(channel, 'probe', listener);+ assert(events === 1, 'foreign channel listener state');+ channel.close(); localChannel.close();+ const notification = new other.Notification('foreign');+ getters(realm, 'Notification', notification, ['title', 'data', 'tag', 'dir', 'lang', 'body', 'icon',+ 'image', 'badge', 'vibrate', 'timestamp', 'renotify', 'silent', 'requireInteraction', 'actions']);+ getters(realm, 'Notification', notification, ['onclick', 'onerror', 'onshow', 'onclose']);+ for (const name of ['onclick', 'onerror', 'onshow', 'onclose']) {+ const setter = Object.getOwnPropertyDescriptor(realm.Notification.prototype, name).set;+ check(realm, notification, setter);+ const handler = () => {};+ setter.call(notification, handler);+ assert(notification[name] === handler, 'foreign notification handler identity');+ }+ const localNotification = new realm.Notification('local');+ for (const name of ['addEventListener', 'removeEventListener', 'dispatchEvent', 'close']) check(realm, notification, localNotification[name]);+ const encoder = new other.TextEncoder();+ const decoder = new other.TextDecoder();+ getters(realm, 'TextEncoder', encoder, ['encoding']);+ getters(realm, 'TextDecoder', decoder, ['encoding', 'fatal', 'ignoreBOM']);+ for (const name of ['encode', 'encodeInto']) check(realm, encoder, realm.TextEncoder.prototype[name]);+ check(realm, decoder, realm.TextDecoder.prototype.decode);+ const encoded = realm.TextEncoder.prototype.encode.call(encoder, 'foreign');+ assert(realm.TextDecoder.prototype.decode.call(decoder, encoded) === 'foreign', 'foreign codec backing state');+ const point = new other.DOMPoint(1, 2, 3, 4);+ getters(realm, 'DOMPoint', point, ['x', 'y', 'z', 'w']);+ for (const name of ['x', 'y', 'z', 'w']) check(realm, point, Object.getOwnPropertyDescriptor(realm.DOMPoint.prototype, name).set);+ check(realm, point, realm.DOMPoint.prototype.toJSON);+ const setter = Object.getOwnPropertyDescriptor(realm.DOMPoint.prototype, 'x').set;+ Object.setPrototypeOf(point, null);+ setter.call(point, 9);+ assert(realm.DOMPoint.prototype.toJSON.call(point).x === 9, 'native brand survives prototype mutation');+ class Encoder extends other.TextEncoder {}+ assert(realm.TextEncoder.prototype.encode.call(new Encoder(), 'subclass').length === 8, 'native subclass receiver');+ const keyword = new other.CSSKeywordValue('auto');+ check(realm, keyword, realm.CSSStyleValue.prototype.toString);+ assert(realm.CSSStyleValue.prototype.toString.call(keyword) === 'auto', 'foreign Typed OM value');+ }+ })()"#).unwrap();+ finish_receiver_checks(&mut vm);+}