Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
fix(events): derive complete value event dictionaries before state
ldm0d081dc12731e
diff --git a/moli-renderer-v8/src/context_bootstrap/events/subclasses.rs b/moli-renderer-v8/src/context_bootstrap/events/subclasses.rsindex a7bfaf77f..db40bc477 100644--- a/moli-renderer-v8/src/context_bootstrap/events/subclasses.rs+++ b/moli-renderer-v8/src/context_bootstrap/events/subclasses.rs@@ -13,6 +13,7 @@ mod error;mod keyboard;mod pointer;mod security_policy;+mod values;pub(in crate::context_bootstrap::events) use basic::initialize_text_event;pub(in crate::context_bootstrap) use constructor::build_event_subclass_template;diff --git a/moli-renderer-v8/src/context_bootstrap/events/subclasses/constructor.rs b/moli-renderer-v8/src/context_bootstrap/events/subclasses/constructor.rsindex a8b452809..2aa298af1 100644--- a/moli-renderer-v8/src/context_bootstrap/events/subclasses/constructor.rs+++ b/moli-renderer-v8/src/context_bootstrap/events/subclasses/constructor.rs@@ -71,6 +71,24 @@ fn event_subclass_constructor_callback<'s>(} else {None};+ let value_event_init = if matches!(+ kind,+ EventSubclassKind::ClipboardEvent+ | EventSubclassKind::CloseEvent+ | EventSubclassKind::CommandEvent+ | EventSubclassKind::ToggleEvent+ | EventSubclassKind::InterestEvent+ | EventSubclassKind::PopStateEvent+ | EventSubclassKind::HashChangeEvent+ | EventSubclassKind::PageTransitionEvent+ ) {+ let Some(init) = values::ValueEventInit::parse(scope, &args, kind) else {+ return;+ };+ Some(init)+ } else {+ None+ };let font_face_init = if kind == EventSubclassKind::FontFaceSetLoadEvent {let Some(init) = super::super::parse_event_dictionary::<crate::context_bootstrap::css_fontface_runtime::FontFaceSetLoadEventInit,@@ -152,6 +170,7 @@ fn event_subclass_constructor_callback<'s>(.map(pointer::PointerEventInitPayload::event_flags)}).or_else(|| font_face_init.as_ref().map(crate::context_bootstrap::css_fontface_runtime::FontFaceSetLoadEventInit::event_flags))+ .or_else(|| value_event_init.as_ref().map(values::ValueEventInit::event_flags)).or_else(|| read_event_init(scope, &args))else {return;@@ -185,9 +204,16 @@ fn event_subclass_constructor_callback<'s>(.expect("pointing event init is parsed").initialize(scope, event);}- EventSubclassKind::ClipboardEvent => {- data::initialize_clipboard_event(scope, event, init);- }+ EventSubclassKind::ClipboardEvent+ | EventSubclassKind::CloseEvent+ | EventSubclassKind::CommandEvent+ | EventSubclassKind::ToggleEvent+ | EventSubclassKind::InterestEvent+ | EventSubclassKind::PopStateEvent+ | EventSubclassKind::HashChangeEvent+ | EventSubclassKind::PageTransitionEvent => value_event_init+ .expect("value event init is parsed")+ .initialize(scope, event),EventSubclassKind::CapturedMouseEvent => {if !data::initialize_captured_mouse_event(scope, event, init) {return;@@ -239,7 +265,6 @@ fn event_subclass_constructor_callback<'s>(return;}}- EventSubclassKind::CloseEvent => data::initialize_close_event(scope, event, init),EventSubclassKind::SubmitEvent => {if !data::initialize_submit_event(scope, event, init) {return;@@ -250,22 +275,6 @@ fn event_subclass_constructor_callback<'s>(return;}}- EventSubclassKind::CommandEvent => data::initialize_command_event(scope, event, init),- EventSubclassKind::ToggleEvent => {- if !data::initialize_toggle_event(scope, event, init) {- return;- }- }- EventSubclassKind::InterestEvent => data::initialize_interest_event(scope, event, init),- EventSubclassKind::PopStateEvent => data::initialize_pop_state_event(scope, event, init),- EventSubclassKind::HashChangeEvent => {- if !data::initialize_hash_change_event(scope, event, init) {- return;- }- }- EventSubclassKind::PageTransitionEvent => {- data::initialize_page_transition_event(scope, event, init);- }EventSubclassKind::TrackEvent => data::initialize_track_event(scope, event, init),EventSubclassKind::FontFaceSetLoadEvent => {font_face_initdiff --git a/moli-renderer-v8/src/context_bootstrap/events/subclasses/data.rs b/moli-renderer-v8/src/context_bootstrap/events/subclasses/data.rsindex bb7f74ba9..264898c03 100644--- a/moli-renderer-v8/src/context_bootstrap/events/subclasses/data.rs+++ b/moli-renderer-v8/src/context_bootstrap/events/subclasses/data.rs@@ -130,12 +130,6 @@ struct NavigateEventMethodsDeclaration {scroll: (),}-#[derive(WebApiObject)]-#[webapi(plain, data_properties, enumerable)]-struct ClipboardEventInitDeclaration<'scope> {- clipboard_data: v8::Local<'scope, v8::Value>,-}-#[derive(WebApiObject)]#[webapi(plain, data_properties, enumerable)]struct CapturedMouseEventInitDeclaration {@@ -151,43 +145,6 @@ struct InputEventInitDeclaration<'scope> {is_composing: bool,}-#[derive(WebApiObject)]-#[webapi(plain, data_properties, enumerable)]-struct CommandEventInitDeclaration<'scope> {- source: v8::Local<'scope, v8::Value>,- command: String,-}--#[derive(WebApiObject)]-#[webapi(plain, data_properties, enumerable)]-struct InterestEventInitDeclaration<'scope> {- source: v8::Local<'scope, v8::Value>,-}--#[derive(WebApiObject)]-#[webapi(plain, data_properties, enumerable)]-struct PopStateEventInitDeclaration<'scope> {- state: v8::Local<'scope, v8::Value>,- #[webapi(data_property = "hasUAVisualTransition")]- has_ua_visual_transition: bool,-}--/// Members are declared in Web IDL lexicographic order.-#[derive(Default, webidl::WebIdlDictionary)]-#[webidl(prefix = "HashChangeEventInit", snapshot)]-struct HashChangeEventInitMembers {- #[webidl(name = "newURL", default = "", converter = "usv_string")]- new_url: String,- #[webidl(name = "oldURL", default = "", converter = "usv_string")]- old_url: String,-}--#[derive(WebApiObject)]-#[webapi(plain, data_properties, enumerable)]-struct PageTransitionEventOwnInitDeclaration {- persisted: bool,-}-#[derive(webidl::WebIdlDictionary)]#[webidl(prefix = "PromiseRejectionEventInit", snapshot)]struct PromiseRejectionEventInitMembers<'s> {@@ -221,20 +178,6 @@ struct NavigateEventInitDeclaration<'scope> {source_element: v8::Local<'scope, v8::Value>,}-#[derive(webidl::WebIdlDictionary)]-#[webidl(prefix = "ToggleEventInit", snapshot)]-struct ToggleEventInitMembers<'s> {- #[webidl(default = "")]- #[webidl(snapshot_attributes = v8::PropertyAttribute::READ_ONLY | v8::PropertyAttribute::DONT_DELETE | v8::PropertyAttribute::DONT_ENUM)]- old_state: String,- #[webidl(default = "")]- #[webidl(snapshot_attributes = v8::PropertyAttribute::READ_ONLY | v8::PropertyAttribute::DONT_DELETE | v8::PropertyAttribute::DONT_ENUM)]- new_state: String,- #[webidl(converter = "raw", snapshot_default = v8::null(scope).into())]- #[webidl(snapshot_attributes = v8::PropertyAttribute::READ_ONLY | v8::PropertyAttribute::DONT_DELETE | v8::PropertyAttribute::DONT_ENUM)]- source: Option<v8::Local<'s, v8::Value>>,-}-#[derive(Default, webidl::WebIdlDictionary)]#[webidl(prefix = "StorageEventInit", snapshot)]pub(in crate::context_bootstrap::events) struct StorageEventInitMembers<'s> {@@ -286,18 +229,6 @@ pub(super) fn parse_storage_event_init<'s>(crate::context_bootstrap::events::parse_event_dictionary(scope, args, "StorageEvent")}-pub(in crate::context_bootstrap::events::subclasses) fn initialize_clipboard_event<'s>(- scope: &mut v8::PinScope<'s, '_>,- event: v8::Local<'s, v8::Object>,- init: Option<v8::Local<'s, v8::Object>>,-) {- let clipboard_data =- init_value_property(scope, init, "clipboardData").unwrap_or_else(|| v8::null(scope).into());- ClipboardEventInitDeclaration::new(clipboard_data)- .initialize(scope, event)- .expect("ClipboardEvent init declaration should initialize");-}-fn captured_mouse_coordinate<'s>(scope: &mut v8::PinScope<'s, '_>,init: Option<v8::Local<'s, v8::Object>>,@@ -382,76 +313,6 @@ pub(in crate::context_bootstrap::events::subclasses) fn initialize_input_event<'.expect("InputEvent init declaration should initialize");}-pub(in crate::context_bootstrap::events::subclasses) fn initialize_pop_state_event<'s>(- scope: &mut v8::PinScope<'s, '_>,- event: v8::Local<'s, v8::Object>,- init: Option<v8::Local<'s, v8::Object>>,-) {- let state = init_value_property(scope, init, "state").unwrap_or_else(|| v8::null(scope).into());- PopStateEventInitDeclaration::new(state, false)- .initialize(scope, event)- .expect("PopStateEvent init declaration should initialize");-}--pub(in crate::context_bootstrap::events::subclasses) fn initialize_hash_change_event<'s>(- scope: &mut v8::PinScope<'s, '_>,- event: v8::Local<'s, v8::Object>,- init: Option<v8::Local<'s, v8::Object>>,-) -> bool {- let parsed = match init {- Some(init) => {- match webidl::parse_dictionary_object::<HashChangeEventInitMembers>(scope, init) {- Ok(parsed) => parsed,- Err(error) => {- webidl::throw_error(scope, &error);- return false;- }- }- }- None => HashChangeEventInitMembers::default(),- };- parsed- .initialize_snapshot(scope, event)- .expect("HashChangeEvent init declaration should initialize");- true-}--pub(in crate::context_bootstrap::events::subclasses) fn initialize_page_transition_event<'s>(- scope: &mut v8::PinScope<'s, '_>,- event: v8::Local<'s, v8::Object>,- init: Option<v8::Local<'s, v8::Object>>,-) {- let persisted = init_bool_property(scope, init, "persisted", false);- PageTransitionEventOwnInitDeclaration::new(persisted)- .initialize(scope, event)- .expect("PageTransitionEvent init declaration should initialize");-}--pub(in crate::context_bootstrap::events::subclasses) fn initialize_toggle_event<'s>(- scope: &mut v8::PinScope<'s, '_>,- event: v8::Local<'s, v8::Object>,- init: Option<v8::Local<'s, v8::Object>>,-) -> bool {- let parsed = match init {- Some(init) => {- match webidl::parse_dictionary_object::<ToggleEventInitMembers>(scope, init) {- Ok(parsed) => parsed,- Err(error) => {- webidl::throw_error(scope, &error);- return false;- }- }- }- None => ToggleEventInitMembers {- old_state: String::new(),- new_state: String::new(),- source: None,- },- };- let _ = parsed.initialize_snapshot(scope, event);- true-}-pub(in crate::context_bootstrap::events::subclasses) fn initialize_promise_rejection_event<'s>(scope: &mut v8::PinScope<'s, '_>,event: v8::Local<'s, v8::Object>,@@ -1140,35 +1001,6 @@ fn navigate_event_scroll_callback<'s>(}}-pub(in crate::context_bootstrap::events::subclasses) fn initialize_close_event<'s>(- scope: &mut v8::PinScope<'s, '_>,- event: v8::Local<'s, v8::Object>,- init: Option<v8::Local<'s, v8::Object>>,-) {- let was_clean = init_bool_property(scope, init, "wasClean", false);- let code = init_number_property(scope, init, "code", 0.0);- let reason = init_string_property(scope, init, "reason", "");- let reason_value = v8_string(scope, &reason).unwrap().into();- crate::context_bootstrap::set_event_private_value(- scope,- event,- CLOSE_EVENT_WAS_CLEAN_SLOT,- v8::Boolean::new(scope, was_clean).into(),- );- crate::context_bootstrap::set_event_private_value(- scope,- event,- CLOSE_EVENT_CODE_SLOT,- v8::Number::new(scope, code).into(),- );- crate::context_bootstrap::set_event_private_value(- scope,- event,- CLOSE_EVENT_REASON_SLOT,- reason_value,- );-}-pub(in crate::context_bootstrap::events::subclasses) fn initialize_submit_event<'s>(scope: &mut v8::PinScope<'s, '_>,event: v8::Local<'s, v8::Object>,@@ -1235,17 +1067,6 @@ pub(in crate::context_bootstrap::events::subclasses) fn initialize_form_data_evetrue}-pub(in crate::context_bootstrap::events::subclasses) fn initialize_command_event<'s>(- scope: &mut v8::PinScope<'s, '_>,- event: v8::Local<'s, v8::Object>,- init: Option<v8::Local<'s, v8::Object>>,-) {- let source =- init_value_property(scope, init, "source").unwrap_or_else(|| v8::null(scope).into());- let command = init_string_property(scope, init, "command", "");- let _ = CommandEventInitDeclaration::new(source, command).initialize(scope, event);-}-pub(in crate::context_bootstrap::events::subclasses) fn initialize_track_event<'s>(scope: &mut v8::PinScope<'s, '_>,event: v8::Local<'s, v8::Object>,@@ -1255,16 +1076,6 @@ pub(in crate::context_bootstrap::events::subclasses) fn initialize_track_event<'crate::context_bootstrap::set_event_private_value(scope, event, TRACK_EVENT_TRACK_SLOT, track);}-pub(in crate::context_bootstrap::events::subclasses) fn initialize_interest_event<'s>(- scope: &mut v8::PinScope<'s, '_>,- event: v8::Local<'s, v8::Object>,- init: Option<v8::Local<'s, v8::Object>>,-) {- let source =- init_value_property(scope, init, "source").unwrap_or_else(|| v8::null(scope).into());- let _ = InterestEventInitDeclaration::new(source).initialize(scope, event);-}-fn submit_event_submitter<'s>(scope: &mut v8::PinScope<'s, '_>,init: Option<v8::Local<'s, v8::Object>>,diff --git a/moli-renderer-v8/src/context_bootstrap/events/subclasses/values.rs b/moli-renderer-v8/src/context_bootstrap/events/subclasses/values.rsnew file mode 100644index 000000000..309283275--- /dev/null+++ b/moli-renderer-v8/src/context_bootstrap/events/subclasses/values.rs@@ -0,0 +1,172 @@+use super::super::{EventInit, parse_event_dictionary};+use super::*;+use crate::{web_api_interfaces, webidl};+use webidl::WebIdlDictionarySerialize;++#[derive(webidl::WebIdlDictionary)]+#[webidl(prefix = "ClipboardEventInit", snapshot)]+pub(super) struct ClipboardInit<'s> {+ #[webidl(inherit)]+ base: EventInit,+ #[webidl(nullable, interface = web_api_interfaces::DataTransfer)]+ clipboard_data: Option<v8::Local<'s, v8::Object>>,+}++#[derive(webidl::WebIdlDictionary)]+#[webidl(prefix = "CloseEventInit", snapshot)]+pub(super) struct CloseInit {+ #[webidl(inherit)]+ base: EventInit,+ #[webidl(default = 0, snapshot_slot = CLOSE_EVENT_CODE_SLOT)]+ code: u16,+ #[webidl(default = webidl::DomString16(Vec::new()), converter = "raw", snapshot_slot = CLOSE_EVENT_REASON_SLOT)]+ reason: webidl::DomString16,+ #[webidl(default = false, snapshot_slot = CLOSE_EVENT_WAS_CLEAN_SLOT)]+ was_clean: bool,+}++#[derive(webidl::WebIdlDictionary)]+#[webidl(prefix = "CommandEventInit", snapshot)]+pub(super) struct CommandInit<'s> {+ #[webidl(inherit)]+ base: EventInit,+ #[webidl(default = webidl::DomString16(Vec::new()), converter = "raw", snapshot_order = 1)]+ command: webidl::DomString16,+ #[webidl(nullable, interface = web_api_interfaces::Element, snapshot_order = 0)]+ source: Option<v8::Local<'s, v8::Object>>,+}++#[derive(webidl::WebIdlDictionary)]+#[webidl(prefix = "ToggleEventInit", snapshot)]+pub(super) struct ToggleInit<'s> {+ #[webidl(inherit)]+ base: EventInit,+ #[webidl(default = webidl::DomString16(Vec::new()), converter = "raw", snapshot_order = 1)]+ #[webidl(snapshot_attributes = v8::PropertyAttribute::READ_ONLY | v8::PropertyAttribute::DONT_DELETE | v8::PropertyAttribute::DONT_ENUM)]+ new_state: webidl::DomString16,+ #[webidl(default = webidl::DomString16(Vec::new()), converter = "raw", snapshot_order = 0)]+ #[webidl(snapshot_attributes = v8::PropertyAttribute::READ_ONLY | v8::PropertyAttribute::DONT_DELETE | v8::PropertyAttribute::DONT_ENUM)]+ old_state: webidl::DomString16,+ #[webidl(nullable, interface = web_api_interfaces::Element, snapshot_order = 2)]+ #[webidl(snapshot_attributes = v8::PropertyAttribute::READ_ONLY | v8::PropertyAttribute::DONT_DELETE | v8::PropertyAttribute::DONT_ENUM)]+ source: Option<v8::Local<'s, v8::Object>>,+}++#[derive(webidl::WebIdlDictionary)]+#[webidl(prefix = "InterestEventInit", snapshot)]+pub(super) struct InterestInit<'s> {+ #[webidl(inherit)]+ base: EventInit,+ #[webidl(nullable, interface = web_api_interfaces::Element)]+ source: Option<v8::Local<'s, v8::Object>>,+}++#[derive(webidl::WebIdlDictionary)]+#[webidl(prefix = "PopStateEventInit", snapshot)]+pub(super) struct PopStateInit<'s> {+ #[webidl(inherit)]+ base: EventInit,+ #[webidl(name = "hasUAVisualTransition", default = false, snapshot_order = 1)]+ has_ua_visual_transition: bool,+ #[webidl(converter = "raw", snapshot_default = v8::null(scope).into(), snapshot_order = 0)]+ state: Option<v8::Local<'s, v8::Value>>,+}++#[derive(webidl::WebIdlDictionary)]+#[webidl(prefix = "HashChangeEventInit", snapshot)]+pub(super) struct HashChangeInit {+ #[webidl(inherit)]+ base: EventInit,+ #[webidl(name = "newURL", default = webidl::DomString16(Vec::new()), converter = "raw")]+ new_url: webidl::DomString16,+ #[webidl(name = "oldURL", default = webidl::DomString16(Vec::new()), converter = "raw")]+ old_url: webidl::DomString16,+}++#[derive(webidl::WebIdlDictionary)]+#[webidl(prefix = "PageTransitionEventInit", snapshot)]+pub(super) struct PageTransitionInit {+ #[webidl(inherit)]+ base: EventInit,+ #[webidl(default = false)]+ persisted: bool,+}++pub(super) enum ValueEventInit<'s> {+ Clipboard(ClipboardInit<'s>),+ Close(CloseInit),+ Command(CommandInit<'s>),+ Toggle(ToggleInit<'s>),+ Interest(InterestInit<'s>),+ PopState(PopStateInit<'s>),+ HashChange(HashChangeInit),+ PageTransition(PageTransitionInit),+}++impl<'s> ValueEventInit<'s> {+ pub(super) fn parse(+ scope: &mut v8::PinScope<'s, '_>,+ args: &v8::FunctionCallbackArguments<'s>,+ kind: EventSubclassKind,+ ) -> Option<Self> {+ Some(match kind {+ EventSubclassKind::ClipboardEvent => {+ Self::Clipboard(parse_event_dictionary(scope, args, "ClipboardEvent")?)+ }+ EventSubclassKind::CloseEvent => {+ Self::Close(parse_event_dictionary(scope, args, "CloseEvent")?)+ }+ EventSubclassKind::CommandEvent => {+ Self::Command(parse_event_dictionary(scope, args, "CommandEvent")?)+ }+ EventSubclassKind::ToggleEvent => {+ Self::Toggle(parse_event_dictionary(scope, args, "ToggleEvent")?)+ }+ EventSubclassKind::InterestEvent => {+ Self::Interest(parse_event_dictionary(scope, args, "InterestEvent")?)+ }+ EventSubclassKind::PopStateEvent => {+ Self::PopState(parse_event_dictionary(scope, args, "PopStateEvent")?)+ }+ EventSubclassKind::HashChangeEvent => {+ Self::HashChange(parse_event_dictionary(scope, args, "HashChangeEvent")?)+ }+ EventSubclassKind::PageTransitionEvent => {+ Self::PageTransition(parse_event_dictionary(scope, args, "PageTransitionEvent")?)+ }+ _ => unreachable!("only value event kinds use ValueEventInit"),+ })+ }++ pub(super) fn event_flags(&self) -> (bool, bool, bool) {+ let base = match self {+ Self::Clipboard(init) => &init.base,+ Self::Close(init) => &init.base,+ Self::Command(init) => &init.base,+ Self::Toggle(init) => &init.base,+ Self::Interest(init) => &init.base,+ Self::PopState(init) => &init.base,+ Self::HashChange(init) => &init.base,+ Self::PageTransition(init) => &init.base,+ };+ (base.bubbles, base.cancelable, base.composed)+ }++ pub(super) fn initialize(+ self,+ scope: &mut v8::PinScope<'s, '_>,+ event: v8::Local<'s, v8::Object>,+ ) {+ match self {+ Self::Clipboard(init) => init.initialize_snapshot(scope, event),+ Self::Close(init) => init.initialize_snapshot(scope, event),+ Self::Command(init) => init.initialize_snapshot(scope, event),+ Self::Toggle(init) => init.initialize_snapshot(scope, event),+ Self::Interest(init) => init.initialize_snapshot(scope, event),+ Self::PopState(init) => init.initialize_snapshot(scope, event),+ Self::HashChange(init) => init.initialize_snapshot(scope, event),+ Self::PageTransition(init) => init.initialize_snapshot(scope, event),+ }+ .expect("value event dictionary state");+ }+}diff --git a/moli-renderer-v8/src/script_vm/tests/browser_api/event_constructor_type.js b/moli-renderer-v8/src/script_vm/tests/browser_api/event_constructor_type.jsindex d15eb325c..45f1729aa 100644--- a/moli-renderer-v8/src/script_vm/tests/browser_api/event_constructor_type.js+++ b/moli-renderer-v8/src/script_vm/tests/browser_api/event_constructor_type.js@@ -52,9 +52,9 @@get newURL() { urls.push('newURL'); return 'new\ud800'; },get oldURL() { urls.push('oldURL'); return 'old\udc00'; }});- check('HashChangeEvent URLs convert as USVString in dictionary order',- urls.join(',') === 'newURL,oldURL' && hashEvent.newURL === 'new\ufffd' &&- hashEvent.oldURL === 'old\ufffd' && hashEvent.type === raw && !hashEvent.isTrusted);+ check('HashChangeEvent URLs convert as DOMString in dictionary order',+ urls.join(',') === 'newURL,oldURL' && hashEvent.newURL === 'new\ud800' &&+ hashEvent.oldURL === 'old\udc00' && hashEvent.type === raw && !hashEvent.isTrusted);const emptyHashEvent = new HashChangeEvent('hashchange');check('HashChangeEvent URL defaults', emptyHashEvent.oldURL === '' && emptyHashEvent.newURL === '');const hashSentinel = new RangeError('URL conversion');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 9ad785f33..af5838aa4 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@@ -73,6 +73,7 @@ mod traversal;mod traversal_coordinator;mod traversal_receivers;mod trusted_types;+mod value_event_init;mod value_events;mod web_audio;mod web_mcp;diff --git a/moli-renderer-v8/src/script_vm/tests/browser_api/value_event_init.rs b/moli-renderer-v8/src/script_vm/tests/browser_api/value_event_init.rsnew file mode 100644index 000000000..ca6876e9e--- /dev/null+++ b/moli-renderer-v8/src/script_vm/tests/browser_api/value_event_init.rs@@ -0,0 +1,13 @@+use super::*;++#[test]+fn value_event_dictionaries_convert_inherited_members_before_payload_state() {+ let mut vm = new_storage_html_test_vm("https://value-event-dictionary.test/");+ assert_eq!(+ vm.eval(include_str!(+ "../../../../tests/fixtures/value-event-dictionary.js"+ ))+ .unwrap(),+ "true"+ );+}diff --git a/moli-renderer-v8/src/script_vm/tests/websocket.rs b/moli-renderer-v8/src/script_vm/tests/websocket.rsindex 77512852c..2f0d1612d 100644--- a/moli-renderer-v8/src/script_vm/tests/websocket.rs+++ b/moli-renderer-v8/src/script_vm/tests/websocket.rs@@ -1131,7 +1131,7 @@ fn websocket_wpt_target_global_constructor_and_prototype_descriptors() {}#[test]-fn websocket_wpt_target_close_event_reason_usvstring_conversion() {+fn websocket_wpt_target_close_event_reason_domstring_conversion() {let mut vm = new_storage_test_vm("https://websocket-wpt-target.test/");let result = vm@@ -1146,9 +1146,9 @@ fn websocket_wpt_target_close_event_reason_usvstring_conversion() {})()"#,)- .expect("target CloseEvent USVString conversion test should evaluate");+ .expect("target CloseEvent DOMString conversion test should evaluate");- assert_eq!(result, "1|fffd");+ assert_eq!(result, "1|d800");}#[test]diff --git a/moli-renderer-v8/tests/fixtures/value-event-dictionary.js b/moli-renderer-v8/tests/fixtures/value-event-dictionary.jsnew file mode 100644index 000000000..e9ab887a2--- /dev/null+++ b/moli-renderer-v8/tests/fixtures/value-event-dictionary.js@@ -0,0 +1,73 @@+(() => {+ const assert = (value, label) => { if (!value) throw Error(label); };+ const base = ['bubbles', 'cancelable', 'composed'];+ const cases = [+ [ClipboardEvent, ['clipboardData']], [CloseEvent, ['code', 'reason', 'wasClean']],+ [CommandEvent, ['command', 'source']], [ToggleEvent, ['newState', 'oldState', 'source']],+ [InterestEvent, ['source']], [PopStateEvent, ['hasUAVisualTransition', 'state']],+ [HashChangeEvent, ['newURL', 'oldURL']], [PageTransitionEvent, ['persisted']]+ ];+ for (const [Constructor, own] of cases) {+ const members = [...base, ...own];+ for (const value of [undefined, null, {}]) {+ const event = new Constructor('audit', value);+ assert(!event.bubbles && !event.cancelable && !event.composed, Constructor.name + ' flags default');+ }+ for (const value of [1, true, 'init', 1n, Symbol('init')]) {+ let caught;+ try { new Constructor('audit', value); } catch (error) { caught = error; }+ assert(caught instanceof TypeError, Constructor.name + ' primitive dictionary');+ }+ const reads = [];+ const options = new Proxy({}, {+ get(_, key) { reads.push(key); return base.includes(key) ? true : undefined; },+ has() { throw Error('dictionary must use Get'); }+ });+ const event = new Constructor('audit', options);+ assert(reads.join() === members.join(), Constructor.name + ' order: ' + reads);+ assert(event.bubbles && event.cancelable && event.composed, Constructor.name + ' flags');+ for (const member of members) for (const sentinel of [{}, null, undefined, 9]) {+ reads.length = 0;+ const bad = new Proxy({}, { get(_, key) {+ reads.push(key);+ if (key === member) throw sentinel;+ return undefined;+ }});+ let caught = Symbol();+ try { new Constructor('audit', bad); } catch (error) { caught = error; }+ assert(caught === sentinel, Constructor.name + '/' + member + ' original exception');+ assert(reads.join() === members.slice(0, members.indexOf(member) + 1).join(),+ Constructor.name + '/' + member + ' stop on abrupt completion: ' + reads);+ }+ }+ const object = {};+ for (const Constructor of [CommandEvent, ToggleEvent, InterestEvent]) {+ for (const source of [{}, new Proxy(document.body, {})]) {+ let caught;+ try { new Constructor('audit', {source}); } catch (error) { caught = error; }+ assert(caught instanceof TypeError, Constructor.name + ' source brand');+ }+ const source = document.createElement('span');+ Object.setPrototypeOf(source, null);+ assert(new Constructor('audit', {source}).source === source, Constructor.name + ' native identity');+ }+ const transfer = new DataTransfer();+ Object.setPrototypeOf(transfer, null);+ assert(new ClipboardEvent('audit', {clipboardData: transfer}).clipboardData === transfer, 'clipboard native identity');+ for (const clipboardData of [{}, new Proxy(transfer, {})]) {+ let caught;+ try { new ClipboardEvent('audit', {clipboardData}); } catch (error) { caught = error; }+ assert(caught instanceof TypeError, 'clipboard brand');+ }+ for (const [input, expected] of [[-1, 65535], [65536, 0], [1.9, 1], [Infinity, 0], [NaN, 0]])+ assert(new CloseEvent('audit', {code: input}).code === expected, 'close unsigned short');+ const utf16 = '\ud800\0\udc00';+ for (const [Constructor, member] of [[CloseEvent, 'reason'], [CommandEvent, 'command'],+ [ToggleEvent, 'newState'], [ToggleEvent, 'oldState']])+ assert(new Constructor('audit', {[member]: utf16})[member] === utf16, Constructor.name + ' UTF-16');+ assert(new HashChangeEvent('audit', {newURL: '\ud800', oldURL: '\udc00'}).newURL === '\ud800', 'HashChange DOMString');+ assert(new PopStateEvent('audit', {state: object, hasUAVisualTransition: 1}).state === object, 'state any identity');+ assert(new PopStateEvent('audit', {hasUAVisualTransition: 1}).hasUAVisualTransition, 'visual transition bool');+ assert(new PageTransitionEvent('audit', {persisted: []}).persisted, 'persisted bool');+ return true;+})()diff --git a/moli-wpt-compat/fixtures/wpt/ported/websockets/websocket-basic.html b/moli-wpt-compat/fixtures/wpt/ported/websockets/websocket-basic.htmlindex ecbfbaaaa..ba28757a3 100644--- a/moli-wpt-compat/fixtures/wpt/ported/websockets/websocket-basic.html+++ b/moli-wpt-compat/fixtures/wpt/ported/websockets/websocket-basic.html@@ -184,8 +184,8 @@ test(function () {assert_equals(event.reason.length, 1, "CloseEvent.reason length");assert_equals(event.reason.charCodeAt(0).toString(16),- "fffd",- "CloseEvent.reason should perform USVString conversion",+ "d800",+ "CloseEvent.reason should preserve DOMString code units",);-}, "CloseEvent exposes readonly prototype accessors and USVString conversion");+}, "CloseEvent exposes readonly prototype accessors and DOMString conversion");</script>