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(window): reuse native replaceable property getters
ldm0f6ba3a43b0c9
diff --git a/moli-renderer-v8/src/context_bootstrap/runtime_state.rs b/moli-renderer-v8/src/context_bootstrap/runtime_state.rsindex ca0c5235f..0573a0d1d 100644--- a/moli-renderer-v8/src/context_bootstrap/runtime_state.rs+++ b/moli-renderer-v8/src/context_bootstrap/runtime_state.rs@@ -17,7 +17,8 @@ use super::{install_storage_runtime_state, window_local_storage_getter, window_session_storage_getter,},window_accessors::{- WINDOW_DOCUMENT_SLOT, window_document_getter_template, window_length_getter,+ WINDOW_DOCUMENT_SLOT, window_document_getter_template, window_inner_width_getter,+ window_length_getter, window_outer_height_getter,},window_runtime::{build_legacy_storage_info_object, window_noop_callback},window_template::install_window_named_properties_object,@@ -344,7 +345,7 @@ struct WindowAdditionalReplaceableAccessorsDeclaration<'scope> {origin: (),#[webapi(accessor_property = "innerWidth",- getter = window_inner_width_replaceable_getter,+ getter = window_inner_width_getter,setter = window_surface_replaceable_setter,setter_data = self.inner_width_name)]@@ -358,14 +359,14 @@ struct WindowAdditionalReplaceableAccessorsDeclaration<'scope> {length: (),#[webapi(accessor_property,- getter = window_event_replaceable_getter,+ getter = window_event_getter,setter = window_surface_replaceable_setter,setter_data = self.event_name)]event: (),#[webapi(accessor_property = "outerHeight",- getter = window_outer_height_replaceable_getter,+ getter = window_outer_height_getter,setter = window_surface_replaceable_setter,setter_data = self.outer_height_name)]@@ -616,40 +617,6 @@ fn window_origin_replaceable_getter<'s>(rv.set(value);}-fn window_inner_width_replaceable_getter<'s>(- scope: &mut v8::PinScope<'s, '_>,- args: v8::FunctionCallbackArguments<'s>,- mut rv: v8::ReturnValue<'s, v8::Value>,-) {- let width = super::window_accessors::window_inner_surface_width(scope, args.this());- rv.set(v8::Number::new(scope, width).into());-}--fn window_outer_height_replaceable_getter<'s>(- scope: &mut v8::PinScope<'s, '_>,- args: v8::FunctionCallbackArguments<'s>,- mut rv: v8::ReturnValue<'s, v8::Value>,-) {- let value = super::window_accessors::window_host_ptr(scope, args.this())- .and_then(|host_ptr| unsafe { &*host_ptr }.viewport_surface())- .map_or(- moli_browser_profile::DEFAULT_WINDOW_SURFACE_PROFILE.inner_height,- |surface| f64::from(surface.outer_height),- );- rv.set(v8::Number::new(scope, value).into());-}--fn window_event_replaceable_getter<'s>(- scope: &mut v8::PinScope<'s, '_>,- args: v8::FunctionCallbackArguments<'s>,- mut rv: v8::ReturnValue<'s, v8::Value>,-) {- rv.set(- super::window_events::window_event_value_for_receiver(scope, args.this())- .unwrap_or_else(|| v8::undefined(scope).into()),- );-}-fn window_scroll_x_replaceable_getter<'s>(scope: &mut v8::PinScope<'s, '_>,args: v8::FunctionCallbackArguments<'s>,diff --git a/moli-renderer-v8/src/context_bootstrap/window_events.rs b/moli-renderer-v8/src/context_bootstrap/window_events.rsindex 813e18935..b926a8400 100644--- a/moli-renderer-v8/src/context_bootstrap/window_events.rs+++ b/moli-renderer-v8/src/context_bootstrap/window_events.rs@@ -89,10 +89,9 @@ pub(crate) use accessors::{};pub(super) use accessors::{window_console_getter, window_event_getter, window_event_setter,- window_event_value_for_receiver, window_onerror_getter_function,- window_onerror_setter_function, window_onrejectionhandled_getter_function,- window_onrejectionhandled_setter_function, window_onunhandledrejection_getter_function,- window_onunhandledrejection_setter_function,+ window_onerror_getter_function, window_onerror_setter_function,+ window_onrejectionhandled_getter_function, window_onrejectionhandled_setter_function,+ window_onunhandledrejection_getter_function, window_onunhandledrejection_setter_function,};pub(super) use console::{console_assert_callback, console_debug_callback, console_error_callback,diff --git a/moli-renderer-v8/src/context_bootstrap/window_events/accessors.rs b/moli-renderer-v8/src/context_bootstrap/window_events/accessors.rsindex 3220a333a..267dd94bd 100644--- a/moli-renderer-v8/src/context_bootstrap/window_events/accessors.rs+++ b/moli-renderer-v8/src/context_bootstrap/window_events/accessors.rs@@ -147,7 +147,7 @@ pub(in crate::context_bootstrap) fn window_event_getter<'s>(}}-pub(in crate::context_bootstrap) fn window_event_value_for_receiver<'s>(+fn window_event_value_for_receiver<'s>(scope: &mut v8::PinScope<'s, '_>,receiver: v8::Local<'s, v8::Object>,) -> Option<v8::Local<'s, v8::Value>> {diff --git a/moli-renderer-v8/src/script_vm/tests/mod.rs b/moli-renderer-v8/src/script_vm/tests/mod.rsindex 9bda52dbe..b316a3c29 100644--- a/moli-renderer-v8/src/script_vm/tests/mod.rs+++ b/moli-renderer-v8/src/script_vm/tests/mod.rs@@ -2183,6 +2183,7 @@ mod webidl_receivers;mod webidl_trusted_types;mod websocket;mod window_execution_context;+mod window_getter_consolidation;mod worklet_interfaces;mod string_timers;diff --git a/moli-renderer-v8/src/script_vm/tests/window_getter_consolidation.rs b/moli-renderer-v8/src/script_vm/tests/window_getter_consolidation.rsnew file mode 100644index 000000000..10fca2bf6--- /dev/null+++ b/moli-renderer-v8/src/script_vm/tests/window_getter_consolidation.rs@@ -0,0 +1,24 @@+use super::*;++#[test]+fn replaceable_window_getters_use_native_receiver_validation() {+ let mut vm = new_parsed_test_vm(+ "https://window_getter_consolidation.test/",+ "<!doctype html><body></body>",+ );+ assert_eq!(vm.eval(r#"(() => {+ const child=document.body.appendChild(document.createElement('iframe')).contentWindow;+ for(const realm of [window,child])for(const name of ['innerWidth','outerHeight','event']){+ const descriptor=Object.getOwnPropertyDescriptor(realm,name);+ for(const target of [window,child])if(descriptor.get.call(target)!==target[name])throw Error('receiver-owned value '+name);+ for(const target of [{},Object.create(realm),new Proxy(realm,{})]){+ let caught;try{descriptor.get.call(target);}catch(error){caught=error;}+ if(!(caught instanceof realm.TypeError))throw Error('invalid receiver '+name);+ }+ const before=descriptor.get.call(realm),replacement={};descriptor.set.call(realm,replacement);+ if(realm[name]!==replacement||descriptor.get.call(realm)!==before)throw Error('replaceable getter state');+ Object.defineProperty(realm,name,descriptor);+ }+ return 'ok';+})()"#).expect("native binding regression"), "ok");+}