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(navigator): use declarative native receiver checks
ldm0c9f37666b3f3
diff --git a/moli-renderer-v8/src/context_bootstrap/assets/prototype_bindings.rs b/moli-renderer-v8/src/context_bootstrap/assets/prototype_bindings.rsindex 747afd416..77212be94 100644--- a/moli-renderer-v8/src/context_bootstrap/assets/prototype_bindings.rs+++ b/moli-renderer-v8/src/context_bootstrap/assets/prototype_bindings.rs@@ -354,16 +354,17 @@ struct StorageBucketManagerTemplateMethodsDeclaration {#[derive(WebApiFunctionTemplate)]#[webapi(interface = web_api_interfaces::StorageBucket, enumerable)]struct StorageBucketTemplateMethodsDeclaration {- #[webapi(accessor_property, getter = storage_bucket_name_getter_callback)]+ #[webapi(accessor_property, receiver = web_api_interfaces::StorageBucket::is_instance, getter = storage_bucket_name_getter_callback)]name: (),#[webapi(accessor_property = "indexedDB",+ receiver = web_api_interfaces::StorageBucket::is_instance,getter = storage_bucket_indexed_db_getter_callback)]indexed_db: (),- #[webapi(accessor_property, getter = storage_bucket_caches_getter_callback)]+ #[webapi(accessor_property, receiver = web_api_interfaces::StorageBucket::is_instance, getter = storage_bucket_caches_getter_callback)]caches: (),#[webapi(method = "persist", length = 0, callback = storage_bucket_persist_callback)]diff --git a/moli-renderer-v8/src/context_bootstrap/navigator_runtime.rs b/moli-renderer-v8/src/context_bootstrap/navigator_runtime.rsindex 85ed62a9f..945219547 100644--- a/moli-renderer-v8/src/context_bootstrap/navigator_runtime.rs+++ b/moli-renderer-v8/src/context_bootstrap/navigator_runtime.rs@@ -23,7 +23,7 @@ pub(in crate::context_bootstrap) use self::navigator::{STORAGE_MANAGER_POPUP_ID_SLOT, build_storage_manager_worker_template,current_protocol_user_gesture_activation, finalize_navigator_credentials_realm_bindings,install_storage_manager_constructor_template_bindings, navigator_identity_profile,- navigator_receiver_branded, service_worker_owner_token_value, set_navigator_identity_profile,+ service_worker_owner_token_value, set_navigator_identity_profile,};#[cfg(test)]pub(crate) use self::navigator::{diff --git a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/clipboard.rs b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/clipboard.rsindex 931242f81..21d27823f 100644--- a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/clipboard.rs+++ b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/clipboard.rs@@ -22,18 +22,18 @@ struct ClipboardObjectDeclaration {}#[derive(Default, WebApiFunctionTemplate)]-#[webapi(interface = web_api_interfaces::Clipboard, enumerable)]+#[webapi(interface = web_api_interfaces::Clipboard, enumerable, receiver)]struct ClipboardPrototypeDeclaration {- #[webapi(method, length = 0, callback = clipboard_read_callback)]+ #[webapi(method, length = 0, callback = clipboard_read_callback, returns_promise)]read: (),- #[webapi(method, length = 0, callback = clipboard_read_text_callback)]+ #[webapi(method, length = 0, callback = clipboard_read_text_callback, returns_promise)]read_text: (),- #[webapi(method, length = 1, callback = clipboard_write_callback)]+ #[webapi(method, length = 1, callback = clipboard_write_callback, returns_promise)]write: (),- #[webapi(method, length = 1, callback = clipboard_write_text_callback)]+ #[webapi(method, length = 1, callback = clipboard_write_text_callback, returns_promise)]write_text: (),}@@ -54,7 +54,7 @@ struct ClipboardItemObjectDeclaration<'scope> {}#[derive(Default, WebApiFunctionTemplate)]-#[webapi(interface = web_api_interfaces::ClipboardItem, enumerable)]+#[webapi(interface = web_api_interfaces::ClipboardItem, enumerable, receiver)]struct ClipboardItemPrototypeDeclaration {#[webapi(accessor_property, getter = clipboard_item_presentation_style_getter)]presentation_style: (),@@ -62,7 +62,7 @@ struct ClipboardItemPrototypeDeclaration {#[webapi(accessor_property, getter = clipboard_item_types_getter)]types: (),- #[webapi(method, length = 1, callback = clipboard_item_get_type_callback)]+ #[webapi(method, length = 1, callback = clipboard_item_get_type_callback, returns_promise)]get_type: (),}@@ -282,29 +282,11 @@ fn clipboard_item_data_to_blob_callback<'s>(}}-fn clipboard_item_receiver_branded<'s>(- scope: &mut v8::PinScope<'s, '_>,- receiver: v8::Local<'s, v8::Object>,-) -> bool {- web_api_interfaces::ClipboardItem::is_instance(scope, receiver)-}--fn clipboard_receiver_branded<'s>(- scope: &mut v8::PinScope<'s, '_>,- receiver: v8::Local<'s, v8::Object>,-) -> bool {- web_api_interfaces::Clipboard::is_instance(scope, receiver)-}-fn clipboard_item_presentation_style_getter<'s>(scope: &mut v8::PinScope<'s, '_>,args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {- if !clipboard_item_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }if let Some(value) =get_private_value(scope, args.this(), CLIPBOARD_ITEM_PRESENTATION_STYLE_SLOT){@@ -317,10 +299,6 @@ fn clipboard_item_types_getter<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {- if !clipboard_item_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }if let Some(value) = get_private_value(scope, args.this(), CLIPBOARD_ITEM_TYPES_SLOT) {rv.set(value);}@@ -331,11 +309,6 @@ fn clipboard_item_get_type_callback<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {- if !clipboard_item_receiver_branded(scope, args.this()) {- let reason = type_error_value(scope, "Illegal invocation");- set_rejected_promise(scope, &mut rv, reason);- return;- }let parsed = match try_parse_promise_args::<ClipboardItemGetTypeArgs>(scope, &args) {Ok(parsed) => parsed,Err(reason) => {@@ -423,11 +396,6 @@ fn clipboard_read_callback<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {- if !clipboard_receiver_branded(scope, args.this()) {- let reason = type_error_value(scope, "Illegal invocation");- set_rejected_promise(scope, &mut rv, reason);- return;- }let parsed = match try_parse_promise_args::<ClipboardReadArgs>(scope, &args) {Ok(parsed) => parsed,Err(reason) => {@@ -466,11 +434,6 @@ fn clipboard_read_text_callback<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {- if !clipboard_receiver_branded(scope, args.this()) {- let reason = type_error_value(scope, "Illegal invocation");- set_rejected_promise(scope, &mut rv, reason);- return;- }let Some(runtime) = clipboard_browser_context(scope, args.this()) else {return;};@@ -490,11 +453,6 @@ fn clipboard_write_callback<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {- if !clipboard_receiver_branded(scope, args.this()) {- let reason = type_error_value(scope, "Illegal invocation");- set_rejected_promise(scope, &mut rv, reason);- return;- }let parsed = match try_parse_promise_args::<ClipboardWriteArgs<'s>>(scope, &args) {Ok(parsed) => parsed,Err(reason) => {@@ -562,11 +520,6 @@ fn clipboard_write_text_callback<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {- if !clipboard_receiver_branded(scope, args.this()) {- let reason = type_error_value(scope, "Illegal invocation");- set_rejected_promise(scope, &mut rv, reason);- return;- }let parsed = match try_parse_promise_args::<ClipboardWriteTextArgs>(scope, &args) {Ok(parsed) => parsed,Err(reason) => {diff --git a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/gamepad.rs b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/gamepad.rsindex 2e0d14f78..91ef17829 100644--- a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/gamepad.rs+++ b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/gamepad.rs@@ -4,8 +4,7 @@//! results; Event payloads are implemented by the shared value-event bindings.use super::super::context_host_ptr_from_global_bridge;-use super::navigator::navigator_receiver_branded;-use crate::{util::throw_type_error, web_api_interfaces, webidl};+use crate::{web_api_interfaces, webidl};use moli_webapi_declare::WebApiFunctionTemplate;#[derive(WebApiFunctionTemplate)]@@ -87,14 +86,9 @@ fn device_backend_unavailable<'s>(pub(super) fn navigator_get_gamepads_callback<'s>(scope: &mut v8::PinScope<'s, '_>,- args: v8::FunctionCallbackArguments<'s>,+ _args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'s, v8::Value>,) {- if !navigator_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }-// The Gamepad algorithm uses the current global's document, including// when a method from one Window is borrowed by another Navigator.let context = scope.get_current_context();diff --git a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/geolocation.rs b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/geolocation.rsindex 3db26ffe7..8038e1c16 100644--- a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/geolocation.rs+++ b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/geolocation.rs@@ -34,7 +34,7 @@ struct GeolocationObjectDeclaration {}#[derive(Default, WebApiFunctionTemplate)]-#[webapi(interface = web_api_interfaces::Geolocation, enumerable)]+#[webapi(interface = web_api_interfaces::Geolocation, enumerable, receiver)]struct GeolocationPrototypeMethodsDeclaration {#[webapi(method, length = 1, callback = geolocation_get_current_position_callback)]get_current_position: (),@@ -178,10 +178,6 @@ fn geolocation_get_current_position_callback<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {- if !geolocation_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }let Some(parsed) = webidl::parse_args::<GetCurrentPositionArgs>(scope, &args) else {return;};@@ -205,10 +201,6 @@ fn geolocation_watch_position_callback<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {- if !geolocation_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }let Some(parsed) = webidl::parse_args::<WatchPositionArgs>(scope, &args) else {return;};@@ -233,10 +225,6 @@ fn geolocation_clear_watch_callback<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {- if !geolocation_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }let Some(parsed) = webidl::parse_args::<ClearWatchArgs>(scope, &args) else {return;};@@ -273,13 +261,6 @@ fn clamp_unsigned_long(value: f64) -> u32 {value.round_ties_even() as u32}-fn geolocation_receiver_branded<'s>(- scope: &mut v8::PinScope<'s, '_>,- receiver: v8::Local<'s, v8::Object>,-) -> bool {- web_api_interfaces::Geolocation::is_instance(scope, receiver)-}-fn take_next_watch_id<'s>(scope: &mut v8::PinScope<'s, '_>,geolocation: v8::Local<'s, v8::Object>,diff --git a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/media_capabilities.rs b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/media_capabilities.rsindex 20d808aec..9c32b5d56 100644--- a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/media_capabilities.rs+++ b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/media_capabilities.rs@@ -17,12 +17,12 @@ struct MediaCapabilitiesObjectDeclaration {}#[derive(Default, WebApiFunctionTemplate)]-#[webapi(interface = web_api_interfaces::MediaCapabilities, enumerable)]+#[webapi(interface = web_api_interfaces::MediaCapabilities, enumerable, receiver)]struct MediaCapabilitiesPrototypeDeclaration {- #[webapi(method, length = 1, callback = media_capabilities_decoding_info_callback)]+ #[webapi(method, length = 1, callback = media_capabilities_decoding_info_callback, returns_promise)]decoding_info: (),- #[webapi(method, length = 1, callback = media_capabilities_encoding_info_callback)]+ #[webapi(method, length = 1, callback = media_capabilities_encoding_info_callback, returns_promise)]encoding_info: (),}@@ -300,11 +300,6 @@ fn media_capabilities_decoding_info_callback<'s>(mut rv: v8::ReturnValue<'_, v8::Value>,) {let receiver = args.this();- if !media_capabilities_receiver_branded(scope, receiver) {- let reason = type_error_value(scope, "Illegal invocation");- set_rejected_promise(scope, &mut rv, reason);- return;- }let parsed = match try_parse_promise_args::<DecodingInfoArgs>(scope, &args) {Ok(parsed) => parsed,Err(reason) => {@@ -380,11 +375,6 @@ fn media_capabilities_encoding_info_callback<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {- if !media_capabilities_receiver_branded(scope, args.this()) {- let reason = type_error_value(scope, "Illegal invocation");- set_rejected_promise(scope, &mut rv, reason);- return;- }let parsed = match try_parse_promise_args::<EncodingInfoArgs>(scope, &args) {Ok(parsed) => parsed,Err(reason) => {@@ -471,13 +461,6 @@ fn set_resolved_promise<'s>(rv.set(promise.into());}-fn media_capabilities_receiver_branded<'s>(- scope: &mut v8::PinScope<'s, '_>,- receiver: v8::Local<'s, v8::Object>,-) -> bool {- web_api_interfaces::MediaCapabilities::is_instance(scope, receiver)-}-fn media_capabilities_is_secure_context<'s>(scope: &mut v8::PinScope<'s, '_>,receiver: v8::Local<'s, v8::Object>,diff --git a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/media_devices.rs b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/media_devices.rsindex a1dd24fcc..c44bae2b1 100644--- a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/media_devices.rs+++ b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/media_devices.rs@@ -24,7 +24,7 @@ struct MediaDevicesPrototypeDeclaration {#[webapi(method, length = 0, callback = enumerate_devices_callback)]enumerate_devices: (),- #[webapi(method, length = 1, callback = navigator_media_devices_get_user_media_callback)]+ #[webapi(method, length = 1, callback = navigator_media_devices_get_user_media_callback, receiver = web_api_interfaces::MediaDevices::is_instance, returns_promise)]get_user_media: (),#[webapi(accessor_property, getter = ondevicechange_getter, setter = ondevicechange_setter)]diff --git a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/navigator.rs b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/navigator.rsindex c300746ee..b06983adc 100644--- a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/navigator.rs+++ b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/navigator.rs@@ -111,9 +111,9 @@ pub(in crate::context_bootstrap) const SERVICE_WORKER_OWNER_TOKEN_SLOT: &str =struct PermissionsObjectDeclaration {}#[derive(Default, WebApiFunctionTemplate)]-#[webapi(interface = web_api_interfaces::Permissions, enumerable)]+#[webapi(interface = web_api_interfaces::Permissions, enumerable, receiver)]struct PermissionsPrototypeMethodsDeclaration {- #[webapi(method, length = 1, callback = navigator_permissions_query_callback)]+ #[webapi(method, length = 1, callback = navigator_permissions_query_callback, returns_promise)]query: (),}@@ -193,7 +193,7 @@ struct NavigatorRuntimeDataPrototypeDeclaration {geolocation: (),#[webapi(accessor_property, getter = navigator_runtime_data_getter_callback, data = callback_data_index_value(scope, 32))]media_capabilities: (),- #[webapi(accessor_property, getter = navigator_cookie_enabled_getter_callback)]+ #[webapi(accessor_property, getter = navigator_cookie_enabled_getter_callback, receiver = web_api_interfaces::Navigator::is_instance)]cookie_enabled: (),}@@ -205,7 +205,7 @@ struct NavigatorCredentialsPrototypeDeclaration {}#[derive(Default, WebApiFunctionTemplate)]-#[webapi(interface = web_api_interfaces::Navigator)]+#[webapi(interface = web_api_interfaces::Navigator, receiver)]struct NavigatorPrototypeMethodsDeclaration {#[webapi(method, enumerable, length = 0, callback = navigator_get_gamepads_callback)]get_gamepads: (),@@ -216,7 +216,7 @@ struct NavigatorPrototypeMethodsDeclaration {#[webapi(method, enumerable, length = 1, callback = navigator_send_beacon_callback)]send_beacon: (),- #[webapi(method, enumerable, length = 0, callback = navigator_get_battery_callback)]+ #[webapi(method, enumerable, length = 0, callback = navigator_get_battery_callback, returns_promise)]get_battery: (),#[webapi(method, enumerable, length = 1, callback = navigator_vibrate_callback)]@@ -290,7 +290,8 @@ struct PermissionStatusPrototypeDeclaration {#[derive(Default, WebApiObject)]#[webapi(interface = web_api_interfaces::NetworkInformation,- prototype = "Object"+ prototype = "Object",+ receiver)]struct NavigatorConnectionDeclaration {#[webapi(data_property, name = "type", enumerable, value = DEFAULT_CONNECTION_TYPE)]@@ -390,12 +391,12 @@ pub(in crate::context_bootstrap) fn install_storage_manager_constructor_templatestruct StorageBucketManagerObjectDeclaration {}#[derive(Default, WebApiFunctionTemplate)]-#[webapi(interface = web_api_interfaces::NavigatorUAData, enumerable)]+#[webapi(interface = web_api_interfaces::NavigatorUAData, enumerable, receiver)]struct NavigatorUaDataPrototypeMethodsDeclaration {#[webapi(method, name = "toJSON", length = 0, callback = navigator_ua_data_to_json_callback)]to_json: (),- #[webapi(method, length = 1, callback = navigator_ua_data_get_high_entropy_values_callback)]+ #[webapi(method, length = 1, callback = navigator_ua_data_get_high_entropy_values_callback, returns_promise)]get_high_entropy_values: (),}@@ -768,25 +769,14 @@ fn navigator_query_overrides(fn navigator_cookie_enabled_getter_callback<'s>(scope: &mut v8::PinScope<'s, '_>,- args: v8::FunctionCallbackArguments<'s>,+ _args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'s, v8::Value>,) {- if !navigator_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }let enabled = context_host_ptr_from_global_bridge(scope).is_some_and(|host_ptr| unsafe { (&*host_ptr).browser_cookie_enabled() });rv.set(v8::Boolean::new(scope, enabled).into());}-pub(in crate::context_bootstrap) fn navigator_receiver_branded<'s>(- scope: &mut v8::PinScope<'s, '_>,- navigator: v8::Local<'s, v8::Object>,-) -> bool {- web_api_interfaces::Navigator::is_instance(scope, navigator)-}-pub(crate) fn current_protocol_user_gesture_activation(scope: &mut v8::PinScope<'_, '_>) -> bool {context_host_ptr_from_global_bridge(scope).is_some_and(|host_ptr| unsafe { (&*host_ptr).protocol_user_gesture_activation() })@@ -807,13 +797,9 @@ fn navigator_user_activation_state_getter_callback<'s>(fn navigator_connection_save_data_getter_callback<'s>(scope: &mut v8::PinScope<'s, '_>,- args: v8::FunctionCallbackArguments<'s>,+ _args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {- if !navigator_connection_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }rv.set_bool(navigator_query_overrides(scope).data_saver@@ -822,13 +808,10 @@ fn navigator_connection_save_data_getter_callback<'s>(}fn navigator_connection_event_target_noop_callback<'s>(- scope: &mut v8::PinScope<'s, '_>,- args: v8::FunctionCallbackArguments<'s>,+ _scope: &mut v8::PinScope<'s, '_>,+ _args: v8::FunctionCallbackArguments<'s>,_rv: v8::ReturnValue<'_, v8::Value>,) {- if !navigator_connection_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- }}fn navigator_get_autoplay_policy_callback<'s>(@@ -836,10 +819,6 @@ fn navigator_get_autoplay_policy_callback<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {- if !navigator_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }if args.length() == 0 {throw_type_error(scope,@@ -884,13 +863,6 @@ fn navigator_get_autoplay_policy_callback<'s>(}}-fn navigator_connection_receiver_branded<'s>(- scope: &mut v8::PinScope<'s, '_>,- receiver: v8::Local<'s, v8::Object>,-) -> bool {- web_api_interfaces::NetworkInformation::is_instance(scope, receiver)-}-pub(in crate::context_bootstrap) fn install_navigator_template_bindings<'s>(scope: &mut v8::PinScope<'s, '_, ()>,template: v8::Local<'s, v8::FunctionTemplate>,diff --git a/moli-renderer-v8/src/context_bootstrap/window_runtime/navigator.rs b/moli-renderer-v8/src/context_bootstrap/window_runtime/navigator.rsindex 6b65b706d..d9bb1cd61 100644--- a/moli-renderer-v8/src/context_bootstrap/window_runtime/navigator.rs+++ b/moli-renderer-v8/src/context_bootstrap/window_runtime/navigator.rs@@ -7,7 +7,7 @@ use crate::context_bootstrap::navigator_runtime::{STORAGE_BUCKET_MANAGER_CHILD_HANDLE_SLOT, STORAGE_BUCKET_MANAGER_POPUP_ID_SLOT,STORAGE_MANAGER_CHILD_HANDLE_SLOT, STORAGE_MANAGER_POPUP_ID_SLOT,current_protocol_user_gesture_activation, navigator_identity_profile,- navigator_receiver_branded, set_navigator_identity_profile,+ set_navigator_identity_profile,};use crate::context_bootstrap::storage_buckets::{IMPLICIT_DEFAULT_BUCKET_INTERNAL_NAME, StorageBucketCacheId, StorageBucketCacheMatch,@@ -286,7 +286,7 @@ struct StorageUsageDetailsObjectDeclaration {}#[derive(WebApiObject)]-#[webapi(prototype = "Object", interface = web_api_interfaces::BatteryManager, data_properties)]+#[webapi(prototype = "Object", interface = web_api_interfaces::BatteryManager, data_properties, receiver)]struct NavigatorBatteryStatusObjectDeclaration {#[webapi(data_property, enumerable)]charging: bool,@@ -464,22 +464,14 @@ pub(in crate::context_bootstrap) fn navigator_send_beacon_callback<'s>(args: v8::FunctionCallbackArguments<'s>,rv: v8::ReturnValue<'_, v8::Value>,) {- if !navigator_receiver_branded(scope, args.this()) {- crate::util::throw_type_error(scope, "Illegal invocation");- return;- }crate::network_host::navigator_send_beacon_callback(scope, args, rv);}pub(in crate::context_bootstrap) fn navigator_java_enabled_callback<'s>(scope: &mut v8::PinScope<'s, '_>,- args: v8::FunctionCallbackArguments<'s>,+ _args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {- if !navigator_receiver_branded(scope, args.this()) {- crate::util::throw_type_error(scope, "Illegal invocation");- return;- }rv.set(v8::Boolean::new(scope, false).into());}@@ -518,10 +510,6 @@ pub(in crate::context_bootstrap) fn navigator_vibrate_callback<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {- if !navigator_receiver_branded(scope, args.this()) {- crate::util::throw_type_error(scope, "Illegal invocation");- return;- }let Some(mut parsed) = webidl::parse_args::<NavigatorVibrateArgs>(scope, &args) else {return;};@@ -537,17 +525,12 @@ pub(in crate::context_bootstrap) fn navigator_vibrate_callback<'s>(pub(in crate::context_bootstrap) fn navigator_get_battery_callback<'s>(scope: &mut v8::PinScope<'s, '_>,- args: v8::FunctionCallbackArguments<'s>,+ _args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {let Some(resolver) = v8::PromiseResolver::new(scope) else {return;};- if !navigator_receiver_branded(scope, args.this()) {- reject_type_error(scope, resolver, "Illegal invocation");- rv.set(resolver.get_promise(scope).into());- return;- }let battery = NavigatorBatteryStatusObjectDeclaration::new(true, 0.0, f64::INFINITY, 1.0).bind(scope).expect("Navigator battery status declaration should bind");@@ -556,34 +539,20 @@ pub(in crate::context_bootstrap) fn navigator_get_battery_callback<'s>(}fn battery_event_target_noop_callback<'s>(- scope: &mut v8::PinScope<'s, '_>,- args: v8::FunctionCallbackArguments<'s>,+ _scope: &mut v8::PinScope<'s, '_>,+ _args: v8::FunctionCallbackArguments<'s>,_rv: v8::ReturnValue<'_, v8::Value>,) {- if !battery_status_receiver_branded(scope, args.this()) {- crate::util::throw_type_error(scope, "Illegal invocation");- }}fn battery_dispatch_event_callback<'s>(scope: &mut v8::PinScope<'s, '_>,- args: v8::FunctionCallbackArguments<'s>,+ _args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {- if !battery_status_receiver_branded(scope, args.this()) {- crate::util::throw_type_error(scope, "Illegal invocation");- return;- }rv.set(v8::Boolean::new(scope, true).into());}-fn battery_status_receiver_branded<'s>(- scope: &mut v8::PinScope<'s, '_>,- receiver: v8::Local<'s, v8::Object>,-) -> bool {- web_api_interfaces::BatteryManager::is_instance(scope, receiver)-}-pub(in crate::context_bootstrap) fn navigator_permissions_query_callback<'s>(scope: &mut v8::PinScope<'s, '_>,args: v8::FunctionCallbackArguments<'s>,@@ -595,11 +564,6 @@ pub(in crate::context_bootstrap) fn navigator_permissions_query_callback<'s>(let Some(resolver) = v8::PromiseResolver::new(scope) else {return;};- if !permissions_receiver_branded(scope, args.this()) {- reject_type_error(scope, resolver, "Illegal invocation");- rv.set(resolver.get_promise(scope).into());- return;- }let permission_name = match permission_query_name(scope, args.get(0)) {Ok(permission_name) => permission_name,Err(error) => {@@ -639,13 +603,6 @@ fn permission_query_name<'s>(Ok(descriptor.name)}-fn permissions_receiver_branded<'s>(- scope: &mut v8::PinScope<'s, '_>,- receiver: v8::Local<'s, v8::Object>,-) -> bool {- web_api_interfaces::Permissions::is_instance(scope, receiver)-}-fn build_permission_status_object<'s>(scope: &mut v8::PinScope<'s, '_>,name: &str,@@ -1217,10 +1174,6 @@ pub(in crate::context_bootstrap) fn storage_bucket_name_getter_callback<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {- if !storage_bucket_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }let value = get_private_value(scope, args.this(), STORAGE_BUCKET_NAME_SLOT).unwrap_or_else(|| v8str(scope, "").into());rv.set(value);@@ -1231,10 +1184,6 @@ pub(in crate::context_bootstrap) fn storage_bucket_indexed_db_getter_callback<'sargs: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {- if !storage_bucket_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }let Some(handle) = storage_bucket_handle(scope, args.this()) else {rv.set_undefined();return;@@ -1250,10 +1199,6 @@ pub(in crate::context_bootstrap) fn storage_bucket_caches_getter_callback<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {- if !storage_bucket_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }if let Some(value) = get_private_value(scope, args.this(), STORAGE_BUCKET_CACHES_OBJECT_SLOT) {rv.set(value);return;@@ -2445,13 +2390,6 @@ fn storage_bucket_resolver<'s>(Some(resolver)}-fn storage_bucket_receiver_branded<'s>(- scope: &mut v8::PinScope<'s, '_>,- receiver: v8::Local<'s, v8::Object>,-) -> bool {- web_api_interfaces::StorageBucket::is_instance(scope, receiver)-}-fn build_storage_bucket_object<'s>(scope: &mut v8::PinScope<'s, '_>,identity: StorageBucketIdentity,@@ -3361,10 +3299,6 @@ pub(in crate::context_bootstrap) fn navigator_ua_data_to_json_callback<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {- if !navigator_ua_data_receiver_branded(scope, args.this()) {- throw_type_error(scope, "Illegal invocation");- return;- }let identity = navigator_ua_data_identity(scope, args.this());rv.set(build_navigator_ua_data_snapshot(scope, &identity, None).into());}@@ -3377,11 +3311,6 @@ pub(in crate::context_bootstrap) fn navigator_ua_data_get_high_entropy_values_calet Some(resolver) = v8::PromiseResolver::new(scope) else {return;};- if !navigator_ua_data_receiver_branded(scope, args.this()) {- reject_type_error(scope, resolver, "Illegal invocation");- rv.set(resolver.get_promise(scope).into());- return;- }let requested = match navigator_ua_data_high_entropy_keys(scope, &args) {Ok(requested) => requested,Err(exception) => {@@ -3418,13 +3347,6 @@ fn navigator_ua_data_high_entropy_keys<'s>(}}-fn navigator_ua_data_receiver_branded<'s>(- scope: &mut v8::PinScope<'s, '_>,- receiver: v8::Local<'s, v8::Object>,-) -> bool {- web_api_interfaces::NavigatorUAData::is_instance(scope, receiver)-}-pub(in crate::context_bootstrap) fn build_navigator_ua_data_object<'s>(scope: &mut v8::PinScope<'s, '_>,identity: &BrowserIdentityProfile,@@ -3547,27 +3469,15 @@ fn build_storage_usage_details_object<'s>(pub(in crate::context_bootstrap) fn navigator_media_devices_get_user_media_callback<'s>(scope: &mut v8::PinScope<'s, '_>,- args: v8::FunctionCallbackArguments<'s>,+ _args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {let Some(resolver) = v8::PromiseResolver::new(scope) else {return;};- if !media_devices_receiver_branded(scope, args.this()) {- reject_type_error(scope, resolver, "Illegal invocation");- rv.set(resolver.get_promise(scope).into());- return;- }let message = v8_string(scope, "Requested media device not found").unwrap_or_else(|| v8_string(scope, "").unwrap());let error = v8::Exception::error(scope, message);let _ = resolver.reject(scope, error);rv.set(resolver.get_promise(scope).into());}--fn media_devices_receiver_branded<'s>(- scope: &mut v8::PinScope<'s, '_>,- receiver: v8::Local<'s, v8::Object>,-) -> bool {- web_api_interfaces::MediaDevices::is_instance(scope, receiver)-}diff --git a/moli-renderer-v8/src/script_vm/tests/declarative_receivers.rs b/moli-renderer-v8/src/script_vm/tests/declarative_receivers.rsindex f52e2cc39..b8aaf72a4 100644--- a/moli-renderer-v8/src/script_vm/tests/declarative_receivers.rs+++ b/moli-renderer-v8/src/script_vm/tests/declarative_receivers.rs@@ -51,3 +51,52 @@ fn webrtc_declarations_validate_foreign_receivers_before_converting_arguments()})()"#).unwrap();finish_receiver_checks(&mut vm);}++#[test]+fn navigator_declarations_preserve_receiver_checks_and_promise_identity_across_realms() {+ let mut vm = receiver_test_vm();+ vm.eval(r#"(async () => {+ const {child, assert, check, getters} = receiverChecks;+ for (const realm of [window, child]) {+ const other = realm === window ? child : window;+ const nav = other.navigator;+ for (const name of ['getGamepads', 'javaEnabled', 'sendBeacon', 'vibrate', 'getAutoplayPolicy']) {+ check(realm, nav, realm.Navigator.prototype[name]);+ }+ check(realm, nav, realm.Navigator.prototype.getBattery, true);+ getters(realm, 'Navigator', nav, ['cookieEnabled']);+ assert(realm.Navigator.prototype.javaEnabled.call(nav) === false, 'foreign Navigator method');+ const localConnection = realm.navigator.connection;+ const saveData = Object.getOwnPropertyDescriptor(localConnection, 'saveData').get;+ check(realm, nav.connection, saveData);+ assert(saveData.call(nav.connection) === nav.connection.saveData, 'foreign connection getter');+ for (const name of ['addEventListener', 'removeEventListener']) check(realm, nav.connection, localConnection[name]);+ const battery = await nav.getBattery();+ const localBattery = await realm.navigator.getBattery();+ for (const name of ['addEventListener', 'removeEventListener', 'dispatchEvent']) check(realm, battery, localBattery[name]);+ check(realm, nav.permissions, realm.Permissions.prototype.query, true);+ check(realm, nav.userAgentData, realm.NavigatorUAData.prototype.toJSON);+ check(realm, nav.userAgentData, realm.NavigatorUAData.prototype.getHighEntropyValues, true);+ assert(realm.NavigatorUAData.prototype.toJSON.call(nav.userAgentData).platform === nav.userAgentData.platform, 'foreign UAData method');+ for (const name of ['getCurrentPosition', 'watchPosition', 'clearWatch']) check(realm, nav.geolocation, realm.Geolocation.prototype[name]);+ realm.Geolocation.prototype.clearWatch.call(nav.geolocation, 0);+ for (const name of ['decodingInfo', 'encodingInfo']) check(realm, nav.mediaCapabilities, realm.MediaCapabilities.prototype[name], true);+ for (const name of ['read', 'readText', 'write', 'writeText']) check(realm, nav.clipboard, realm.Clipboard.prototype[name], true);+ check(realm, nav.mediaDevices, realm.MediaDevices.prototype.getUserMedia, true);+ const item = new other.ClipboardItem({'text/plain': new other.Blob(['foreign'])});+ getters(realm, 'ClipboardItem', item, ['types', 'presentationStyle']);+ check(realm, item, realm.ClipboardItem.prototype.getType, true);+ const originalPromise = other.ClipboardItem.prototype.getType.call(item, 'text/plain');+ assert(realm.ClipboardItem.prototype.getType.call(item, 'text/plain') === originalPromise, 'getType preserves stored Promise identity');+ assert(realm.ClipboardItem.supports.call({}, 'text/plain'), 'static method has no receiver guard');+ const bucket = await nav.storageBuckets.open('receiver-bucket');+ getters(realm, 'StorageBucket', bucket, ['name', 'caches']);+ const factoryGetter = Object.getOwnPropertyDescriptor(realm.StorageBucket.prototype, 'indexedDB').get;+ check(realm, bucket, factoryGetter);+ assert(typeof factoryGetter.call(bucket).open === 'function', 'foreign bucket factory getter');+ }+ return 'ok';+ })().then(result => {globalThis.receiverSetup = result;}, error => {globalThis.receiverSetup = String(error);})"#).unwrap();+ assert_eq!(vm.eval("receiverSetup").unwrap(), "ok");+ finish_receiver_checks(&mut vm);+}