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(dom): derive shared scroll options with legacy cancellation
ldm059dad22e88d4
diff --git a/moli-renderer-v8/src/lib.rs b/moli-renderer-v8/src/lib.rsindex 534ca67ef..8f685d661 100644--- a/moli-renderer-v8/src/lib.rs+++ b/moli-renderer-v8/src/lib.rs@@ -102,6 +102,7 @@ mod script_execution;mod script_execution_control;mod script_provenance;mod script_vm;+mod scroll_options;mod service_worker_runtime;mod shared_worker_runtime;mod structured_clone;diff --git a/moli-renderer-v8/src/native_bridge/element/geometry/metrics.rs b/moli-renderer-v8/src/native_bridge/element/geometry/metrics.rsindex 82143c2ba..fab54c8d6 100644--- a/moli-renderer-v8/src/native_bridge/element/geometry/metrics.rs+++ b/moli-renderer-v8/src/native_bridge/element/geometry/metrics.rs@@ -1,4 +1,4 @@-use crate::{document_runtime::DomHandle, native_bridge::JsContextHost, util::v8str};+use crate::{document_runtime::DomHandle, native_bridge::JsContextHost, scroll_options};use super::super::super::{document,@@ -13,9 +13,7 @@ use super::provider::read_element_metrics;use super::scroll::{apply_observable_window_scroll, node_scroll_position, set_node_scroll_position,};-use super::scroll_into_view::{- ScrollIntoViewAlignment, scroll_node_into_view, scroll_node_into_view_if_needed,-};+use super::scroll_into_view::{scroll_node_into_view, scroll_node_into_view_if_needed};fn node_scroll_position_value<'s>(scope: &mut v8::PinScope<'s, '_>,@@ -121,102 +119,19 @@ fn node_scroll_position_setter_for_object<'s>(Ok(())}-fn parse_scroll_coordinates(- scope: &mut v8::PinScope<'_, '_>,- args: &v8::FunctionCallbackArguments<'_>,- fallback_x: f64,- fallback_y: f64,-) -> (f64, f64) {- if args.length() > 0- && args.get(0).is_object()- && !args.get(0).is_function()- && let Some(options) = args.get(0).to_object(scope)- {- let x = options- .get(scope, v8str(scope, "left").into())- .or_else(|| options.get(scope, v8str(scope, "x").into()))- .and_then(|value| value.number_value(scope).filter(|value| !value.is_nan()))- .unwrap_or(fallback_x);- let y = options- .get(scope, v8str(scope, "top").into())- .or_else(|| options.get(scope, v8str(scope, "y").into()))- .and_then(|value| value.number_value(scope).filter(|value| !value.is_nan()))- .unwrap_or(fallback_y);- return (x, y);- }-- let x = args- .get(0)- .number_value(scope)- .filter(|value| !value.is_nan())- .unwrap_or(fallback_x);- let y = args- .get(1)- .number_value(scope)- .filter(|value| !value.is_nan())- .unwrap_or(fallback_y);- (x, y)-}--fn scroll_alignment_option(- scope: &mut v8::PinScope<'_, '_>,- options: v8::Local<'_, v8::Object>,- name: &'static str,- fallback: ScrollIntoViewAlignment,-) -> ScrollIntoViewAlignment {- let Some(value) = options.get(scope, v8str(scope, name).into()) else {- return fallback;- };- match value.to_rust_string_lossy(scope).as_str() {- "start" => ScrollIntoViewAlignment::Start,- "center" => ScrollIntoViewAlignment::Center,- "end" => ScrollIntoViewAlignment::End,- "nearest" => ScrollIntoViewAlignment::Nearest,- _ => fallback,- }-}--fn element_scroll_into_view_alignments(- scope: &mut v8::PinScope<'_, '_>,- args: &v8::FunctionCallbackArguments<'_>,-) -> (ScrollIntoViewAlignment, ScrollIntoViewAlignment) {- if args.length() == 0 {- return (- ScrollIntoViewAlignment::Nearest,- ScrollIntoViewAlignment::Start,- );- }- let value = args.get(0);- if value.is_boolean() {- return if value.boolean_value(scope) {- (- ScrollIntoViewAlignment::Nearest,- ScrollIntoViewAlignment::Start,- )- } else {- (- ScrollIntoViewAlignment::Nearest,- ScrollIntoViewAlignment::End,- )- };- }- let Some(options) = value.to_object(scope) else {- return (- ScrollIntoViewAlignment::Nearest,- ScrollIntoViewAlignment::Start,- );- };- (- scroll_alignment_option(scope, options, "inline", ScrollIntoViewAlignment::Nearest),- scroll_alignment_option(scope, options, "block", ScrollIntoViewAlignment::Start),- )-}-fn scroll_node_to<'s>(scope: &mut v8::PinScope<'s, '_>,args: v8::FunctionCallbackArguments<'s>,relative: bool,) -> Result<(), moli_layout::LayoutError> {+ if node_runtime_and_handle_from_object_or_detached(scope, args.this()).is_err() {+ return Ok(());+ }+ let Some(coordinates) = scroll_options::coordinates(scope, &args) else {+ return Ok(());+ };+ // Conversion may detach or replace the receiver's document. Resolve its+ // native owner again before reading state or requesting layout.let Ok((runtime_ptr, handle)) =node_runtime_and_handle_from_object_or_detached(scope, args.this())else {@@ -228,12 +143,7 @@ fn scroll_node_to<'s>(return Ok(());}let (current_left, current_top) = node_scroll_position(unsafe { &*runtime_ptr }, handle);- let (left, top) = if relative {- let (delta_left, delta_top) = parse_scroll_coordinates(scope, &args, 0.0, 0.0);- (current_left + delta_left, current_top + delta_top)- } else {- parse_scroll_coordinates(scope, &args, current_left, current_top)- };+ let (left, top) = coordinates.resolve(current_left, current_top, relative);let metrics = read_element_metrics(unsafe { &*runtime_ptr }, handle)?;let Some(metrics) = metrics else {return Ok(());@@ -572,18 +482,22 @@ pub(in crate::native_bridge) fn node_scroll_into_view_if_needed_callback(rv.set_undefined();}-pub(in crate::native_bridge) fn node_scroll_into_view_callback(- scope: &mut v8::PinScope<'_, '_>,- args: v8::FunctionCallbackArguments<'_>,+pub(in crate::native_bridge) fn node_scroll_into_view_callback<'s>(+ scope: &mut v8::PinScope<'s, '_>,+ args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {- if let Ok((runtime_ptr, handle)) = node_runtime_and_handle_from_object(scope, args.this()) {- let (horizontal, vertical) = element_scroll_into_view_alignments(scope, &args);- if let Err(error) =+ if node_runtime_and_handle_from_object_or_detached(scope, args.this()).is_err() {+ return;+ }+ let Some((horizontal, vertical)) = scroll_options::into_view_alignments(scope, &args) else {+ return;+ };+ if let Ok((runtime_ptr, handle)) = node_runtime_and_handle_from_object(scope, args.this())+ && let Err(error) =scroll_node_into_view(scope, runtime_ptr, handle, None, horizontal, vertical)- {- throw_scroll_layout_error(scope, "scrollIntoView", error);- }+ {+ throw_scroll_layout_error(scope, "scrollIntoView", error);}reveal_lazy_images_for_scroll(scope, args.this());rv.set_undefined();diff --git a/moli-renderer-v8/src/native_bridge/element/geometry/scroll_into_view.rs b/moli-renderer-v8/src/native_bridge/element/geometry/scroll_into_view.rsindex 478f566db..d34c68ea0 100644--- a/moli-renderer-v8/src/native_bridge/element/geometry/scroll_into_view.rs+++ b/moli-renderer-v8/src/native_bridge/element/geometry/scroll_into_view.rs@@ -1,6 +1,9 @@use moli_page_types::DomScrollIntoViewRect;-use crate::{document_runtime::DomHandle, native_bridge::JsContextHost};+use crate::{+ document_runtime::DomHandle, native_bridge::JsContextHost,+ scroll_options::ScrollLogicalPosition as ScrollIntoViewAlignment,+};use super::provider::{read_box_model, read_scroll_into_view_geometry};use super::scroll::{@@ -9,14 +12,6 @@ use super::scroll::{const CHILD_FRAME_DEPTH_LIMIT: usize = 16;-#[derive(Clone, Copy)]-pub(super) enum ScrollIntoViewAlignment {- Start,- Center,- End,- Nearest,-}-#[derive(Clone, Copy)]struct ScrollIntoViewParams {horizontal: ScrollIntoViewAlignment,diff --git a/moli-renderer-v8/src/script_vm/tests/browser_api/mod.rs b/moli-renderer-v8/src/script_vm/tests/browser_api/mod.rsindex 7959e74a8..8486a9364 100644--- a/moli-renderer-v8/src/script_vm/tests/browser_api/mod.rs+++ b/moli-renderer-v8/src/script_vm/tests/browser_api/mod.rs@@ -60,6 +60,7 @@ mod request_init;mod rtc_dictionary_init;mod rtc_error;mod rtc_peer_dictionary;+mod scroll_dictionary;mod security_policy;mod security_policy_event_init;mod service_worker_drain;diff --git a/moli-renderer-v8/src/script_vm/tests/browser_api/scroll_dictionary.rs b/moli-renderer-v8/src/script_vm/tests/browser_api/scroll_dictionary.rsnew file mode 100644index 000000000..433e9f49f--- /dev/null+++ b/moli-renderer-v8/src/script_vm/tests/browser_api/scroll_dictionary.rs@@ -0,0 +1,33 @@+use super::*;++#[test]+fn scroll_dictionaries_preserve_conversion_order_and_silent_cancellation() {+ for policy in [+ moli_page_types::LayoutPolicy::Mock,+ moli_page_types::LayoutPolicy::OnDemand,+ ] {+ let mut vm = new_storage_html_test_vm("https://scroll-dictionary.test/");+ vm.set_layout_policy(policy);+ assert_eq!(+ vm.eval(include_str!(+ "../../../../tests/fixtures/scroll-options-dictionary.js"+ ))+ .unwrap(),+ "true"+ );+ }+}++#[test]+fn native_scroll_uses_state_after_conversion_without_partial_updates() {+ let mut vm = new_storage_html_test_vm("https://scroll-native-conversion.test/");+ vm.set_layout_policy(moli_page_types::LayoutPolicy::OnDemand);+ assert_eq!(+ eval_with_layout_publications(+ &mut vm,+ include_str!("../../../../tests/fixtures/scroll-native-geometry.js"),+ )+ .unwrap(),+ "true"+ );+}diff --git a/moli-renderer-v8/src/scroll_options.rs b/moli-renderer-v8/src/scroll_options.rsnew file mode 100644index 000000000..dc71eec56--- /dev/null+++ b/moli-renderer-v8/src/scroll_options.rs@@ -0,0 +1,157 @@+use crate::webidl;++#[derive(webidl::WebIdlEnum)]+#[webidl(name = "ScrollBehavior", rename_all = "kebab-case")]+enum ScrollBehavior {+ Auto,+ Instant,+ Smooth,+}++#[derive(webidl::WebIdlDictionary)]+#[webidl(prefix = "ScrollOptions")]+struct ScrollOptions {+ // The native scroll algorithm retains its existing immediate-scroll policy.+ #[webidl(name = "behavior", converter = "enum", default = ScrollBehavior::Auto)]+ _behavior: ScrollBehavior,+}++#[derive(webidl::WebIdlDictionary)]+#[webidl(prefix = "ScrollToOptions")]+struct ScrollToOptions {+ #[webidl(inherit)]+ _base: ScrollOptions,+ #[webidl(converter = "unrestricted_double")]+ left: Option<f64>,+ #[webidl(converter = "unrestricted_double")]+ top: Option<f64>,+}++#[derive(webidl::WebIdlArgs)]+#[webidl(prefix = "scroll")]+struct ScrollToArgs {+ #[webidl(dictionary)]+ options: ScrollToOptions,+}++#[derive(webidl::WebIdlArgs)]+#[webidl(prefix = "scroll")]+struct ScrollNumericArgs {+ #[webidl(required, converter = "unrestricted_double")]+ x: f64,+ #[webidl(required, converter = "unrestricted_double")]+ y: f64,+}++pub(crate) struct ScrollCoordinates {+ left: Option<f64>,+ top: Option<f64>,+}++impl ScrollCoordinates {+ pub(crate) fn resolve(self, current_x: f64, current_y: f64, relative: bool) -> (f64, f64) {+ let normalize = |value: f64| if value.is_finite() { value } else { 0.0 };+ let left = self.left.map(normalize);+ let top = self.top.map(normalize);+ if relative {+ (+ current_x + left.unwrap_or(0.0),+ current_y + top.unwrap_or(0.0),+ )+ } else {+ (left.unwrap_or(current_x), top.unwrap_or(current_y))+ }+ }+}++pub(crate) fn coordinates<'s>(+ scope: &mut v8::PinScope<'s, '_>,+ args: &v8::FunctionCallbackArguments<'s>,+) -> Option<ScrollCoordinates> {+ // The legacy scroll bindings silently cancel failed argument conversion.+ // Keep the catch here so native layout failures remain visible to callers.+ let try_catch = std::pin::pin!(v8::TryCatch::new(scope));+ let mut scope = try_catch.init();+ let parsed = if args.length() >= 2 {+ webidl::try_parse_args::<ScrollNumericArgs>(&mut scope, args).map(|args| {+ ScrollCoordinates {+ left: Some(args.x),+ top: Some(args.y),+ }+ })+ } else {+ webidl::try_parse_args::<ScrollToArgs>(&mut scope, args).map(|args| ScrollCoordinates {+ left: args.options.left,+ top: args.options.top,+ })+ };+ if scope.has_caught() {+ scope.reset();+ return None;+ }+ parsed.ok()+}++#[derive(Clone, Copy, webidl::WebIdlEnum)]+#[webidl(name = "ScrollLogicalPosition", rename_all = "kebab-case")]+pub(crate) enum ScrollLogicalPosition {+ Start,+ Center,+ End,+ Nearest,+}++#[derive(webidl::WebIdlEnum)]+#[webidl(name = "ScrollIntoViewContainer", rename_all = "kebab-case")]+enum ScrollIntoViewContainer {+ All,+ Nearest,+}++#[derive(webidl::WebIdlDictionary)]+#[webidl(prefix = "ScrollIntoViewOptions")]+struct ScrollIntoViewOptions {+ #[webidl(inherit)]+ _base: ScrollOptions,+ #[webidl(converter = "enum", default = ScrollLogicalPosition::Start)]+ block: ScrollLogicalPosition,+ // The native bubbling algorithm retains its existing all-containers policy.+ #[webidl(name = "container", converter = "enum", default = ScrollIntoViewContainer::All)]+ _container: ScrollIntoViewContainer,+ #[webidl(converter = "enum", default = ScrollLogicalPosition::Nearest)]+ inline: ScrollLogicalPosition,+}++#[derive(webidl::WebIdlArgs)]+#[webidl(prefix = "Element.scrollIntoView")]+struct ScrollIntoViewArgs {+ #[webidl(dictionary)]+ options: ScrollIntoViewOptions,+}++pub(crate) fn into_view_alignments<'s>(+ scope: &mut v8::PinScope<'s, '_>,+ args: &v8::FunctionCallbackArguments<'s>,+) -> Option<(ScrollLogicalPosition, ScrollLogicalPosition)> {+ let value = args.get(0);+ if !value.is_null_or_undefined() && !value.is_object() {+ return Some((+ ScrollLogicalPosition::Nearest,+ if value.boolean_value(scope) {+ ScrollLogicalPosition::Start+ } else {+ ScrollLogicalPosition::End+ },+ ));+ }+ let try_catch = std::pin::pin!(v8::TryCatch::new(scope));+ let mut scope = try_catch.init();+ let parsed = webidl::try_parse_args::<ScrollIntoViewArgs>(&mut scope, args);+ if scope.has_caught() {+ scope.reset();+ return None;+ }+ parsed+ .ok()+ .map(|args| (args.options.inline, args.options.block))+}diff --git a/moli-renderer-v8/src/window_host.rs b/moli-renderer-v8/src/window_host.rsindex 86a0da2f0..4a929b58e 100644--- a/moli-renderer-v8/src/window_host.rs+++ b/moli-renderer-v8/src/window_host.rs@@ -978,11 +978,14 @@ pub(crate) fn target_origin_matches(.unwrap_or(true)}-pub(super) fn window_scroll_to_callback(- scope: &mut v8::PinScope<'_, '_>,- args: v8::FunctionCallbackArguments<'_>,+pub(super) fn window_scroll_to_callback<'s>(+ scope: &mut v8::PinScope<'s, '_>,+ args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {+ let Some(coordinates) = crate::scroll_options::coordinates(scope, &args) else {+ return;+ };let Some(host_ptr) = context_host_ptr_from_global_bridge(scope) else {rv.set_undefined();return;@@ -990,16 +993,19 @@ pub(super) fn window_scroll_to_callback(let global = scope.get_current_context().global(scope);let current_x = scroll_x(scope, global);let current_y = scroll_y(scope, global);- let (x, y) = parse_scroll_coordinates(scope, &args, current_x, current_y);+ let (x, y) = coordinates.resolve(current_x, current_y, false);scroll_window_to(scope, host_ptr, x, y);rv.set_undefined();}-pub(super) fn window_scroll_by_callback(- scope: &mut v8::PinScope<'_, '_>,- args: v8::FunctionCallbackArguments<'_>,+pub(super) fn window_scroll_by_callback<'s>(+ scope: &mut v8::PinScope<'s, '_>,+ args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {+ let Some(coordinates) = crate::scroll_options::coordinates(scope, &args) else {+ return;+ };let Some(host_ptr) = context_host_ptr_from_global_bridge(scope) else {rv.set_undefined();return;@@ -1007,8 +1013,8 @@ pub(super) fn window_scroll_by_callback(let global = scope.get_current_context().global(scope);let current_x = scroll_x(scope, global);let current_y = scroll_y(scope, global);- let (dx, dy) = parse_scroll_coordinates(scope, &args, 0.0, 0.0);- scroll_window_to(scope, host_ptr, current_x + dx, current_y + dy);+ let (x, y) = coordinates.resolve(current_x, current_y, true);+ scroll_window_to(scope, host_ptr, x, y);rv.set_undefined();}@@ -1725,35 +1731,6 @@ fn collect_timer_extra_args(.collect()}-fn parse_scroll_coordinates(- scope: &mut v8::PinScope<'_, '_>,- args: &v8::FunctionCallbackArguments<'_>,- fallback_x: f64,- fallback_y: f64,-) -> (f64, f64) {- if args.length() > 0- && args.get(0).is_object()- && !args.get(0).is_function()- && let Some(options) = args.get(0).to_object(scope)- {- let x = options- .get(scope, v8str(scope, "left").into())- .or_else(|| options.get(scope, v8str(scope, "x").into()))- .and_then(|value| value.number_value(scope))- .unwrap_or(fallback_x);- let y = options- .get(scope, v8str(scope, "top").into())- .or_else(|| options.get(scope, v8str(scope, "y").into()))- .and_then(|value| value.number_value(scope))- .unwrap_or(fallback_y);- return (x, y);- }-- let x = args.get(0).number_value(scope).unwrap_or(fallback_x);- let y = args.get(1).number_value(scope).unwrap_or(fallback_y);- (x, y)-}-fn scroll_x<'s>(scope: &mut v8::PinScope<'s, '_>, global: v8::Local<'s, v8::Object>) -> f64 {get_private_value(scope, global, WINDOW_SCROLL_X_SLOT).and_then(|value| value.number_value(scope))diff --git a/moli-renderer-v8/tests/fixtures/scroll-native-geometry.js b/moli-renderer-v8/tests/fixtures/scroll-native-geometry.jsnew file mode 100644index 000000000..5c7ee32de--- /dev/null+++ b/moli-renderer-v8/tests/fixtures/scroll-native-geometry.js@@ -0,0 +1,28 @@+(function* () {+ const assert=(value,label)=>{if(!value)throw Error(label);};+ document.body.style.cssText='margin:0;width:5000px;height:5000px';+ const box=document.createElement('div');box.style.cssText='width:100px;height:100px;overflow:auto';+ box.innerHTML='<div style="width:1000px;height:900px"></div><div id="scroll-target" style="height:20px"></div><div style="height:1000px"></div>';+ document.body.append(box);const target=box.querySelector('#scroll-target');+ yield;+ for(const object of [window,box]) {+ const position=()=>object===window?[scrollX,scrollY]:[object.scrollLeft,object.scrollTop];+ object.scrollTo(10,20);+ object.scrollTo({get behavior(){object.scrollTo(30,40);return 'instant';}});+ assert(position().join()==='30,40','absolute fallback must use state after conversion');+ object.scrollBy({get behavior(){object.scrollTo(50,60);return 'instant';},left:5,top:7});+ assert(position().join()==='55,67','relative scroll must use state after conversion');+ object.scrollTo({left:99,get top(){throw 7;}});+ assert(position().join()==='55,67','failed later member cannot partially scroll');+ object.scrollTo(Infinity,NaN);+ assert(position().join()==='0,0','native nonfinite normalization');+ }+ const positions=[];+ for(const value of [false,true,0,1,'','x',undefined,null]) {+ box.scrollTo(0,0);target.scrollIntoView(value);positions.push(box.scrollTop);+ }+ assert(positions[0]===positions[2] && positions[0]===positions[4],'false, zero, empty string align to end');+ assert(positions[1]===positions[3] && positions[1]===positions[5] && positions[1]===positions[6] && positions[1]===positions[7],'true and nullish align to start');+ assert(positions[0]<positions[1],'boolean union must select different alignments');+ box.remove();return true;+})()diff --git a/moli-renderer-v8/tests/fixtures/scroll-options-dictionary.js b/moli-renderer-v8/tests/fixtures/scroll-options-dictionary.jsnew file mode 100644index 000000000..0e678f4b3--- /dev/null+++ b/moli-renderer-v8/tests/fixtures/scroll-options-dictionary.js@@ -0,0 +1,60 @@+(() => {+ const assert=(value,label)=>{if(!value)throw Error(label);};+ document.body.style.cssText='width:5000px;height:5000px;margin:0';+ const box=document.createElement('div');box.style.cssText='width:100px;height:100px;overflow:auto';+ box.innerHTML='<div style="width:2000px;height:2000px"></div>';document.body.append(box);+ const cases=[];+ for(const object of [window,box]) for(const method of ['scroll','scrollTo','scrollBy'])+ cases.push([object,method,['behavior','left','top']]);+ cases.push([box,'scrollIntoView',['behavior','block','container','inline']]);+ for(const [object,method,members] of cases) {+ for(const key of members) for(const sentinel of [{},null,undefined,7]) {+ const reads=[];let caught=false;+ try {object[method](new Proxy({}, {get(_,name) {+ reads.push(name); if(name===key) throw sentinel;return undefined;+ }, has() {throw Error('Get required');}}));} catch(e) {caught=true;}+ assert(!caught, method+' silently cancels conversion failure');+ assert(reads.join()===members.slice(0,members.indexOf(key)+1).join(),method+' conversion order/short circuit: '+reads);+ }+ const reads=[];+ object[method](new Proxy({}, {get(_,name) {reads.push(name);return 'invalid';}}));+ assert(reads.join()==='behavior',method+' invalid enum must stop conversion');+ }+ window.scrollTo(10,20);+ for(const init of [1,true,'init',1n,Symbol(),{behavior:'invalid',left:99,top:99}]) {+ window.scrollTo(init);+ assert(scrollX===10 && scrollY===20,'failed one-argument dictionary must not change position');+ }+ let later=0;+ window.scrollTo({get left(){throw 7;},get top(){later++;return 99;}});+ assert(later===0 && scrollX===10 && scrollY===20,'abrupt conversion cannot partially scroll');+ for(const object of [window,box]) for(const method of ['scrollTo','scrollBy']) {+ const reads=[];const options=function(){};+ for(const name of ['behavior','left','top']) Object.defineProperty(options,name,{get(){reads.push(name);return undefined;}});+ object[method](options);+ assert(reads.join()==='behavior,left,top',method+' callable dictionary branch');+ let first=0,second=0;+ object[method]({valueOf(){first++;throw 7;}},{valueOf(){second++;return 2;}});+ assert(first===1 && second===0,method+' numeric overload stops at first error');+ }+ window.scrollTo(10,20);+ window.scrollTo({get behavior(){window.scrollTo(30,40);return 'instant';}});+ assert(scrollX===30 && scrollY===40,'fallback position read after dictionary conversion');+ window.scrollTo(NaN,Infinity);+ assert(scrollX===0 && scrollY===0,'nonfinite coordinates normalize to zero');+ window.scrollTo(10,20);window.scrollBy(NaN,-Infinity);+ assert(scrollX===10 && scrollY===20,'nonfinite deltas normalize to zero');+ for(const method of ['scroll','scrollTo','scrollBy','scrollIntoView']) {+ const detached=document.createElement('div'),reads=[];+ detached[method](new Proxy({}, {get(_,name){reads.push(name);return undefined;}}));+ const expected=method==='scrollIntoView'?'behavior,block,container,inline':'behavior,left,top';+ assert(reads.join()===expected,method+' converts detached receiver options');+ }+ let prototypeReads=0;+ try {+ for(const name of ['behavior','left','top']) Object.defineProperty(Object.prototype,name,{configurable:true,get(){prototypeReads++;throw Error('nullish prototype');}});+ window.scrollTo();window.scrollTo(null);window.scrollBy(undefined);+ assert(prototypeReads===0,'nullish dictionary must not consult Object.prototype');+ } finally {for(const name of ['behavior','left','top']) delete Object.prototype[name];}+ box.remove();return true;+})()