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 base and UI subclass initialization
ldm028630d85edf9
diff --git a/moli-renderer-v8/src/context_bootstrap/event_template.rs b/moli-renderer-v8/src/context_bootstrap/event_template.rsindex 13d8d5e1e..4944fc601 100644--- a/moli-renderer-v8/src/context_bootstrap/event_template.rs+++ b/moli-renderer-v8/src/context_bootstrap/event_template.rs@@ -167,6 +167,9 @@ struct FormDataEventTemplateAccessorsDeclaration {#[derive(WebApiFunctionTemplate)]#[webapi(interface = web_api_interfaces::UIEvent, enumerable, receiver)]struct UiEventTemplateMethodsDeclaration {+ #[webapi(accessor_property, getter = event_platform_attribute_getter, data = crate::util::v8str(scope, "sourceCapabilities"))]+ source_capabilities: (),+#[webapi(accessor_property = "view", getter = event_platform_attribute_getter, data = crate::util::v8str(scope, "view"))]view: (),#[webapi(accessor_property = "detail", getter = event_value_attribute_getter, data = crate::util::v8str(scope, "detail"))]diff --git a/moli-renderer-v8/src/context_bootstrap/events/base.rs b/moli-renderer-v8/src/context_bootstrap/events/base.rsindex 7c72a08fa..d63096d8d 100644--- a/moli-renderer-v8/src/context_bootstrap/events/base.rs+++ b/moli-renderer-v8/src/context_bootstrap/events/base.rs@@ -477,12 +477,14 @@ pub(in crate::context_bootstrap) fn event_constructor_callback<'s>(}let wrapper = args.this();- let event = new_event_state(scope);let Some(event_type) = event_type_argument(scope, &args, "Event") else {return;};- let (bubbles, cancelable, composed) = read_event_init(scope, &args);+ let Some((bubbles, cancelable, composed)) = read_event_init(scope, &args) else {+ return;+ };+ let event = new_event_state(scope);initialize_event_object_with_type(scope, event, event_type, bubbles, cancelable);define_event_property(scope,diff --git a/moli-renderer-v8/src/context_bootstrap/events/init.rs b/moli-renderer-v8/src/context_bootstrap/events/init.rsindex 862fcb2a9..83c38edc4 100644--- a/moli-renderer-v8/src/context_bootstrap/events/init.rs+++ b/moli-renderer-v8/src/context_bootstrap/events/init.rs@@ -112,17 +112,7 @@ pub(super) fn init_window_view_property<'s>(pub(super) fn read_event_init<'s>(scope: &mut v8::PinScope<'s, '_>,args: &v8::FunctionCallbackArguments<'s>,-) -> (bool, bool, bool) {- parse_event_init(scope, webidl::optional_object_arg(args, 1)).unwrap_or((false, false, false))-}--pub(in crate::context_bootstrap) fn parse_event_init<'s>(- scope: &mut v8::PinScope<'s, '_>,- init: Option<v8::Local<'s, v8::Object>>,-) -> Result<(bool, bool, bool), webidl::WebIdlError> {- let Some(init) = init else {- return Ok((false, false, false));- };- webidl::parse_dictionary_object::<EventInit>(scope, init)- .map(|parsed| (parsed.bubbles, parsed.cancelable, parsed.composed))+) -> Option<(bool, bool, bool)> {+ parse_event_dictionary::<EventInit>(scope, args, "Event")+ .map(|init| (init.bubbles, init.cancelable, init.composed))}diff --git a/moli-renderer-v8/src/context_bootstrap/events/subclasses/basic.rs b/moli-renderer-v8/src/context_bootstrap/events/subclasses/basic.rsindex 10d357a9d..934820f07 100644--- a/moli-renderer-v8/src/context_bootstrap/events/subclasses/basic.rs+++ b/moli-renderer-v8/src/context_bootstrap/events/subclasses/basic.rs@@ -1,112 +1,175 @@+use super::super::{EventInit, ui::UiEventInit};use super::*;-use moli_webapi_declare::WebApiObject;+use crate::{web_api_interfaces, webidl};+use webidl::WebIdlDictionarySerialize;-#[derive(WebApiObject)]-#[webapi(plain, data_properties, enumerable)]-struct UiEventInitDeclaration<'scope> {- view: v8::Local<'scope, v8::Value>,- detail: f64,+#[derive(webidl::WebIdlDictionary)]+#[webidl(prefix = "FocusEventInit", snapshot)]+pub(super) struct FocusEventInit<'s> {+ #[webidl(inherit)]+ ui: UiEventInit<'s>,+ #[webidl(nullable, interface = web_api_interfaces::EventTarget)]+ related_target: Option<v8::Local<'s, v8::Object>>,}-#[derive(WebApiObject)]-#[webapi(plain, data_properties, enumerable)]-struct FocusEventInitDeclaration<'scope> {- view: v8::Local<'scope, v8::Value>,- detail: f64,- #[webapi(data_property = "relatedTarget")]- related_target: v8::Local<'scope, v8::Value>,- composed: bool,+#[derive(webidl::WebIdlDictionary)]+#[webidl(prefix = "CompositionEventInit", snapshot)]+pub(super) struct CompositionEventInit<'s> {+ #[webidl(inherit)]+ ui: UiEventInit<'s>,+ #[webidl(default = webidl::DomString16(Vec::new()), converter = "raw")]+ data: webidl::DomString16,}-#[derive(WebApiObject)]-#[webapi(plain, data_properties, enumerable)]-struct TextEventInitDeclaration<'scope> {- view: v8::Local<'scope, v8::Value>,- detail: f64,- data: v8::Local<'scope, v8::String>,+#[derive(webidl::WebIdlDictionary)]+#[webidl(prefix = "CustomEventInit", snapshot)]+pub(super) struct CustomEventInit<'s> {+ #[webidl(inherit)]+ base: EventInit,+ #[webidl(converter = "raw", snapshot_default = v8::null(scope).into())]+ detail: Option<v8::Local<'s, v8::Value>>,}-#[derive(WebApiObject)]-#[webapi(plain, data_properties, enumerable)]-struct CustomEventInitDeclaration<'scope> {- detail: v8::Local<'scope, v8::Value>,+impl<'s> FocusEventInit<'s> {+ pub(super) fn event_flags(&self) -> (bool, bool, bool) {+ self.ui.event_flags()+ }+ pub(super) fn initialize(+ &self,+ scope: &mut v8::PinScope<'s, '_>,+ event: v8::Local<'s, v8::Object>,+ ) {+ self.initialize_snapshot(scope, event)+ .expect("FocusEventInit state");+ }}-pub(in crate::context_bootstrap::events::subclasses) fn initialize_ui_event<'s>(- scope: &mut v8::PinScope<'s, '_>,- event: v8::Local<'s, v8::Object>,- init: Option<v8::Local<'s, v8::Object>>,-) -> bool {- let Ok(view) = init_window_view_property(scope, init, "UIEvent") else {- return false;- };- let detail = init_number_property(scope, init, "detail", 0.0);- UiEventInitDeclaration::new(view, detail)- .initialize(scope, event)- .expect("UIEvent init declaration should initialize");- true+impl<'s> CompositionEventInit<'s> {+ pub(super) fn event_flags(&self) -> (bool, bool, bool) {+ self.ui.event_flags()+ }+ pub(super) fn initialize(+ &self,+ scope: &mut v8::PinScope<'s, '_>,+ event: v8::Local<'s, v8::Object>,+ ) {+ self.initialize_snapshot(scope, event)+ .expect("CompositionEventInit state");+ }}-pub(in crate::context_bootstrap::events::subclasses) fn initialize_focus_event<'s>(- scope: &mut v8::PinScope<'s, '_>,- event: v8::Local<'s, v8::Object>,- init: Option<v8::Local<'s, v8::Object>>,-) -> bool {- let Ok(view) = init_window_view_property(scope, init, "FocusEvent") else {- return false;- };- let detail = init_number_property(scope, init, "detail", 0.0);- let related_target =- init_value_property(scope, init, "relatedTarget").unwrap_or_else(|| v8::null(scope).into());- let composed = init_bool_property(scope, init, "composed", false);- FocusEventInitDeclaration::new(view, detail, related_target, composed)- .initialize(scope, event)- .expect("FocusEvent init declaration should initialize");- true+impl<'s> CustomEventInit<'s> {+ pub(super) fn event_flags(&self) -> (bool, bool, bool) {+ (self.base.bubbles, self.base.cancelable, self.base.composed)+ }+ pub(super) fn initialize(+ &self,+ scope: &mut v8::PinScope<'s, '_>,+ event: v8::Local<'s, v8::Object>,+ ) {+ self.initialize_snapshot(scope, event)+ .expect("CustomEventInit state");+ }}+// Legacy createEvent("TextEvent") uses an empty, internal dictionary.pub(in crate::context_bootstrap::events) fn initialize_text_event<'s>(scope: &mut v8::PinScope<'s, '_>,event: v8::Local<'s, v8::Object>,init: Option<v8::Local<'s, v8::Object>>,) -> bool {- let Ok(view) = init_window_view_property(scope, init, "TextEvent") else {- return false;- };- let detail = init_number_property(scope, init, "detail", 0.0);- let data = init_string_property(scope, init, "data", "");- let data = v8_string(scope, &data).expect("text event data");- TextEventInitDeclaration::new(view, detail, data)- .initialize(scope, event)- .expect("TextEvent init declaration should initialize");- true+ let value = init+ .map(Into::into)+ .unwrap_or_else(|| v8::null(scope).into());+ match webidl::convert::<webidl::Dictionary<CompositionEventInit>>(+ scope,+ value,+ webidl::Context::argument("TextEvent", 2),+ ) {+ Ok(init) => {+ init.0.initialize(scope, event);+ true+ }+ Err(error) => {+ webidl::throw_error(scope, &error);+ false+ }+ }+}++use moli_webapi_declare::WebApiObject;+#[derive(WebApiObject)]+#[webapi(plain, data_properties, enumerable)]+struct UiEventInitDeclaration<'scope> {+ view: v8::Local<'scope, v8::Value>,+ detail: f64,}-pub(in crate::context_bootstrap::events::subclasses) fn initialize_composition_event<'s>(+pub(in crate::context_bootstrap::events::subclasses) fn initialize_ui_event<'s>(scope: &mut v8::PinScope<'s, '_>,event: v8::Local<'s, v8::Object>,init: Option<v8::Local<'s, v8::Object>>,) -> bool {- let Ok(view) = init_window_view_property(scope, init, "CompositionEvent") else {+ let Ok(view) = init_window_view_property(scope, init, "UIEvent") else {return false;};let detail = init_number_property(scope, init, "detail", 0.0);- let data = init_string_property(scope, init, "data", "");- let data = v8_string(scope, &data).expect("composition event data");- TextEventInitDeclaration::new(view, detail, data)+ UiEventInitDeclaration::new(view, detail).initialize(scope, event)- .expect("CompositionEvent init declaration should initialize");+ .expect("UIEvent init declaration should initialize");true}-pub(in crate::context_bootstrap::events::subclasses) fn initialize_custom_event<'s>(- scope: &mut v8::PinScope<'s, '_>,- event: v8::Local<'s, v8::Object>,- init: Option<v8::Local<'s, v8::Object>>,-) {- let detail =- init_value_property(scope, init, "detail").unwrap_or_else(|| v8::null(scope).into());- CustomEventInitDeclaration::new(detail)- .initialize(scope, event)- .expect("CustomEvent init declaration should initialize");+pub(super) enum BasicEventInit<'s> {+ Ui(UiEventInit<'s>),+ Focus(FocusEventInit<'s>),+ Text(CompositionEventInit<'s>),+ Composition(CompositionEventInit<'s>),+ Custom(CustomEventInit<'s>),+}++impl<'s> BasicEventInit<'s> {+ pub(super) fn parse(+ scope: &mut v8::PinScope<'s, '_>,+ args: &v8::FunctionCallbackArguments<'s>,+ kind: EventSubclassKind,+ ) -> Option<Self> {+ use super::super::parse_event_dictionary;+ Some(match kind {+ EventSubclassKind::UiEvent => Self::Ui(parse_event_dictionary(scope, args, "UIEvent")?),+ EventSubclassKind::FocusEvent => {+ Self::Focus(parse_event_dictionary(scope, args, "FocusEvent")?)+ }+ EventSubclassKind::TextEvent => {+ Self::Text(parse_event_dictionary(scope, args, "TextEvent")?)+ }+ EventSubclassKind::CompositionEvent => {+ Self::Composition(parse_event_dictionary(scope, args, "CompositionEvent")?)+ }+ EventSubclassKind::CustomEvent => {+ Self::Custom(parse_event_dictionary(scope, args, "CustomEvent")?)+ }+ _ => unreachable!("only basic event kinds use BasicEventInit"),+ })+ }+ pub(super) fn event_flags(&self) -> (bool, bool, bool) {+ match self {+ Self::Ui(init) => init.event_flags(),+ Self::Focus(init) => init.event_flags(),+ Self::Text(init) | Self::Composition(init) => init.event_flags(),+ Self::Custom(init) => init.event_flags(),+ }+ }+ pub(super) fn initialize(+ self,+ scope: &mut v8::PinScope<'s, '_>,+ event: v8::Local<'s, v8::Object>,+ ) {+ match self {+ Self::Ui(init) => init.initialize(scope, event),+ Self::Focus(init) => init.initialize(scope, event),+ Self::Text(init) | Self::Composition(init) => init.initialize(scope, event),+ Self::Custom(init) => init.initialize(scope, event),+ }+ }}diff --git a/moli-renderer-v8/src/context_bootstrap/events/subclasses/constructor.rs b/moli-renderer-v8/src/context_bootstrap/events/subclasses/constructor.rsindex 4a173f273..0c4d2573b 100644--- a/moli-renderer-v8/src/context_bootstrap/events/subclasses/constructor.rs+++ b/moli-renderer-v8/src/context_bootstrap/events/subclasses/constructor.rs@@ -31,7 +31,6 @@ fn event_subclass_constructor_callback<'s>(}let wrapper = args.this();- let event = new_event_state(scope);let Some(event_type) = event_type_argument(scope, &args, kind.constructor_name()) else {return;};@@ -43,6 +42,21 @@ fn event_subclass_constructor_callback<'s>(init_arg.to_object(scope)}};+ let basic_event_init = if matches!(+ kind,+ EventSubclassKind::UiEvent+ | EventSubclassKind::FocusEvent+ | EventSubclassKind::TextEvent+ | EventSubclassKind::CompositionEvent+ | EventSubclassKind::CustomEvent+ ) {+ let Some(init) = basic::BasicEventInit::parse(scope, &args, kind) else {+ return;+ };+ Some(init)+ } else {+ None+ };let storage_event_init = if kind == EventSubclassKind::StorageEvent {let Some(init) = data::parse_storage_event_init(scope, &args) else {return;@@ -84,7 +98,7 @@ fn event_subclass_constructor_callback<'s>(} else {None};- let (bubbles, cancelable, composed) = security_policy_init+ let Some((bubbles, cancelable, composed)) = security_policy_init.as_ref().map(security_policy::SecurityPolicyViolationEventInit::event_flags).or_else(|| error_init.as_ref().map(error::ErrorEventInit::event_flags))@@ -103,7 +117,17 @@ fn event_subclass_constructor_callback<'s>(.as_ref().map(message::MessageEventInit::event_flags)})- .unwrap_or_else(|| read_event_init(scope, &args));+ .or_else(|| {+ basic_event_init+ .as_ref()+ .map(basic::BasicEventInit::event_flags)+ })+ .or_else(|| read_event_init(scope, &args))+ else {+ return;+ };++ let event = new_event_state(scope);initialize_event_object_with_type(scope, event, event_type, bubbles, cancelable);define_event_property(@@ -114,27 +138,15 @@ fn event_subclass_constructor_callback<'s>();match kind {- EventSubclassKind::UiEvent => {- if !basic::initialize_ui_event(scope, event, init) {- return;- }- }- EventSubclassKind::FocusEvent => {- if !basic::initialize_focus_event(scope, event, init) {- return;- }- }- EventSubclassKind::TextEvent => {- if !basic::initialize_text_event(scope, event, init) {- return;- }- }- EventSubclassKind::CompositionEvent => {- if !basic::initialize_composition_event(scope, event, init) {- return;- }+ EventSubclassKind::UiEvent+ | EventSubclassKind::FocusEvent+ | EventSubclassKind::TextEvent+ | EventSubclassKind::CompositionEvent+ | EventSubclassKind::CustomEvent => {+ basic_event_init+ .expect("basic event init is parsed")+ .initialize(scope, event);}- EventSubclassKind::CustomEvent => basic::initialize_custom_event(scope, event, init),EventSubclassKind::MouseEvent => {if !pointer::initialize_mouse_event(scope, event, init) {return;diff --git a/moli-renderer-v8/src/context_bootstrap/events/subclasses/keyboard.rs b/moli-renderer-v8/src/context_bootstrap/events/subclasses/keyboard.rsindex fb0f71968..68931a36b 100644--- a/moli-renderer-v8/src/context_bootstrap/events/subclasses/keyboard.rs+++ b/moli-renderer-v8/src/context_bootstrap/events/subclasses/keyboard.rs@@ -22,6 +22,10 @@ struct KeyboardEventInitMembers {location: u32,#[webidl(default = false)]repeat: bool,+ // Retain the existing KeyboardEvent legacy input without adding a member+ // to UIEventInit or reading it for unrelated UI event subclasses.+ #[webidl(default = 0)]+ which: u32,}impl Default for KeyboardEventInitMembers {@@ -34,6 +38,7 @@ impl Default for KeyboardEventInitMembers {key_code: 0,location: 0,repeat: false,+ which: 0,}}}diff --git a/moli-renderer-v8/src/context_bootstrap/events/ui.rs b/moli-renderer-v8/src/context_bootstrap/events/ui.rsindex 386350183..c76652a7c 100644--- a/moli-renderer-v8/src/context_bootstrap/events/ui.rs+++ b/moli-renderer-v8/src/context_bootstrap/events/ui.rs@@ -11,7 +11,7 @@ fn nullable_window_value<'s>(.unwrap_or_else(|| v8::null(scope).into())}-/// Own UIEventInit members, including legacy which, in dictionary order.+/// UIEventInit members, converted after EventInit in dictionary order.#[derive(Default, webidl::WebIdlDictionary)]#[webidl(prefix = "UIEventInit", snapshot)]pub(super) struct UiEventInit<'s> {@@ -19,10 +19,10 @@ pub(super) struct UiEventInit<'s> {base: super::EventInit,#[webidl(default = 0)]detail: i32,+ #[webidl(nullable, interface = crate::web_api_interfaces::InputDeviceCapabilities)]+ source_capabilities: Option<v8::Local<'s, v8::Object>>,#[webidl(nullable, interface = crate::web_api_interfaces::Window, brand_check = crate::context_bootstrap::is_window_receiver)]view: Option<v8::Local<'s, v8::Object>>,- #[webidl(default = 0)]- which: u32,}impl<'s> UiEventInit<'s> {diff --git a/moli-renderer-v8/src/script_vm/tests/browser_api/basic_event_init.rs b/moli-renderer-v8/src/script_vm/tests/browser_api/basic_event_init.rsnew file mode 100644index 000000000..82836d7b9--- /dev/null+++ b/moli-renderer-v8/src/script_vm/tests/browser_api/basic_event_init.rs@@ -0,0 +1,13 @@+use super::*;++#[test]+fn event_and_ui_subclass_dictionaries_convert_before_initializing_state() {+ let mut vm = new_storage_html_test_vm("https://event-dictionary-conversion.test/");+ assert_eq!(+ vm.eval(include_str!(+ "../../../../tests/fixtures/event-dictionary-conversion.js"+ ))+ .unwrap(),+ "true"+ );+}diff --git a/moli-renderer-v8/src/script_vm/tests/browser_api/keyboard_event_init.js b/moli-renderer-v8/src/script_vm/tests/browser_api/keyboard_event_init.jsindex 2a007b196..d86db3297 100644--- a/moli-renderer-v8/src/script_vm/tests/browser_api/keyboard_event_init.js+++ b/moli-renderer-v8/src/script_vm/tests/browser_api/keyboard_event_init.js@@ -89,8 +89,8 @@const modifierMembers = ['altKey', 'ctrlKey', 'metaKey', 'modifierAltGraph', 'modifierCapsLock','modifierFn', 'modifierFnLock', 'modifierHyper', 'modifierNumLock', 'modifierScrollLock','modifierSuper', 'modifierSymbol', 'modifierSymbolLock', 'shiftKey'];- const order = ['bubbles', 'cancelable', 'composed', 'detail', 'view', 'which', ...modifierMembers,- 'charCode', 'code', 'isComposing', 'key', 'keyCode', 'location', 'repeat'];+ const order = ['bubbles', 'cancelable', 'composed', 'detail', 'sourceCapabilities', 'view', ...modifierMembers,+ 'charCode', 'code', 'isComposing', 'key', 'keyCode', 'location', 'repeat', 'which'];check('complete inherited dictionary order', () => {const seen = [];new KeyboardEvent('x', new Proxy({}, {get(_target, name) { seen.push(name); }}));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 b84cdf5dc..637050d87 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@@ -5,6 +5,7 @@ mod abort_signal_events;mod abort_signal_statics;mod adopted_style_sheets;mod bar_prop;+mod basic_event_init;mod broadcast_channel;mod chrome;mod clipboard_storage;diff --git a/moli-renderer-v8/src/web_api_interfaces.rs b/moli-renderer-v8/src/web_api_interfaces.rsindex 273e48b34..fd70b62fc 100644--- a/moli-renderer-v8/src/web_api_interfaces.rs+++ b/moli-renderer-v8/src/web_api_interfaces.rs@@ -313,6 +313,7 @@ interfaces! {MathMLElement: Element;MediaCapabilities;MediaDeviceInfo;+ InputDeviceCapabilities;InputDeviceInfo: MediaDeviceInfo;MediaStreamTrack: EventTarget;CanvasCaptureMediaStreamTrack: MediaStreamTrack;diff --git a/moli-renderer-v8/tests/fixtures/event-dictionary-conversion.js b/moli-renderer-v8/tests/fixtures/event-dictionary-conversion.jsnew file mode 100644index 000000000..2858e1a9b--- /dev/null+++ b/moli-renderer-v8/tests/fixtures/event-dictionary-conversion.js@@ -0,0 +1,66 @@+(() => {+ const assert = (value, label) => { if (!value) throw Error(label); };+ const sentinel = { original: true };+ const bases = ['bubbles', 'cancelable', 'composed'];+ const ui = ['detail', 'sourceCapabilities', 'view'];+ const cases = [+ [Event, bases],+ [UIEvent, [...bases, ...ui]],+ [FocusEvent, [...bases, ...ui, 'relatedTarget']],+ [CompositionEvent, [...bases, ...ui, 'data']],+ [CustomEvent, [...bases, 'detail']]+ ];+ for (const [Constructor, members] of cases) {+ for (const value of [undefined, null, {}]) {+ const event = new Constructor('audit', value);+ assert(!event.bubbles && !event.cancelable && !event.composed, Constructor.name + ' defaults');+ }+ 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 = {};+ for (const key of members) Object.defineProperty(options, key, {+ configurable: true, get() {+ reads.push(key);+ return bases.includes(key) ? true : undefined;+ }+ });+ const event = new Constructor('audit', options);+ assert(reads.join() === members.join(), Constructor.name + ' inheritance order: ' + reads);+ assert(event.bubbles && event.cancelable && event.composed, Constructor.name + ' flags');+ for (const key of members) {+ reads.length = 0;+ const bad = Object.create(options);+ Object.defineProperty(bad, key, {get() {reads.push(key); throw sentinel;}});+ let caught;+ try {new Constructor('audit', bad);} catch (error) {caught = error;}+ assert(caught === sentinel, Constructor.name + '/' + key + ' exception identity');+ assert(reads.join() === members.slice(0, members.indexOf(key) + 1).join(),+ Constructor.name + '/' + key + ' reads after abrupt completion: ' + reads);+ }+ }+ for (const Constructor of [UIEvent, FocusEvent, CompositionEvent]) {+ for (const [value, expected] of [[2147483648, -2147483648], [-2147483649, 2147483647],+ [4294967296, 0], [NaN, 0], [Infinity, 0], [-1.5, -1]])+ assert(new Constructor('audit', {detail: value}).detail === expected, Constructor.name + ' long conversion');+ for (const member of ['view', 'sourceCapabilities']) {+ let caught;+ try {new Constructor('audit', {[member]: {}});} catch (error) {caught = error;}+ assert(caught instanceof TypeError, Constructor.name + '/' + member + ' interface brand');+ }+ }+ for (const value of [{}, new Proxy(document.body, {})]) {+ let caught;+ try {new FocusEvent('audit', {relatedTarget: value});} catch (error) {caught = error;}+ assert(caught instanceof TypeError, 'FocusEvent relatedTarget brand');+ }+ assert(new FocusEvent('audit', {relatedTarget: document.body}).relatedTarget === document.body,+ 'FocusEvent relatedTarget identity');+ const payload = {arbitrary: true};+ assert(new CustomEvent('audit', {detail: payload}).detail === payload, 'CustomEvent any payload identity');+ assert(new CompositionEvent('audit', {data: '\ud800\0\udc00'}).data === '\ud800\0\udc00', 'CompositionEvent UTF-16');+ return true;+})()