Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

feat(events): implement animation transition and blob payloads

ldm0826c8e395757
diff --git a/moli-renderer-v8/src/context_bootstrap/assets/constructor_templates.rs b/moli-renderer-v8/src/context_bootstrap/assets/constructor_templates.rs
index 96e60d7ae..9346b7760 100644
--- a/moli-renderer-v8/src/context_bootstrap/assets/constructor_templates.rs
+++ b/moli-renderer-v8/src/context_bootstrap/assets/constructor_templates.rs
@@ -11,7 +11,10 @@ use super::super::{
css_fontface_runtime::font_face_constructor_callback,
css_runtime::{css_keyword_value_constructor_callback, css_unit_value_constructor_callback},
css_stylesheet_runtime::css_style_sheet_constructor_callback,
- events::{EventSubclassKind, build_event_subclass_template, event_constructor_callback},
+ events::{
+ EventSubclassKind, ValueEventKind, build_event_subclass_template,
+ build_value_event_template, event_constructor_callback,
+ },
exposed_interfaces::install_interface_template_metadata,
file_api::{
data_transfer_constructor_callback, file_constructor_callback,
@@ -96,6 +99,13 @@ pub(in crate::context_bootstrap) fn build_constructor_template<'s>(
.length(1)
.build(scope)
}
+ ConstructorKind::AnimationEvent => {
+ build_value_event_template(scope, ValueEventKind::Animation)
+ }
+ ConstructorKind::TransitionEvent => {
+ build_value_event_template(scope, ValueEventKind::Transition)
+ }
+ ConstructorKind::BlobEvent => build_value_event_template(scope, ValueEventKind::Blob),
ConstructorKind::UiEvent => {
build_event_subclass_template(scope, EventSubclassKind::UiEvent)
}
diff --git a/moli-renderer-v8/src/context_bootstrap/event_template.rs b/moli-renderer-v8/src/context_bootstrap/event_template.rs
index bec0b0fe1..06c378297 100644
--- a/moli-renderer-v8/src/context_bootstrap/event_template.rs
+++ b/moli-renderer-v8/src/context_bootstrap/event_template.rs
@@ -335,6 +335,7 @@ pub(super) fn install_event_template_bindings<'s>(
if spec.kind == ConstructorKind::Event {
install_event_base_bindings(scope, template);
}
+ super::events::install_value_event_template_bindings(scope, template, spec.interface.name());
match spec.interface.name() {
"UIEvent" => {
diff --git a/moli-renderer-v8/src/context_bootstrap/events.rs b/moli-renderer-v8/src/context_bootstrap/events.rs
index e74ef7230..73659b7a6 100644
--- a/moli-renderer-v8/src/context_bootstrap/events.rs
+++ b/moli-renderer-v8/src/context_bootstrap/events.rs
@@ -7,8 +7,13 @@ mod init;
mod kind;
mod methods;
mod subclasses;
+mod value;
mod wrappers;
+pub(in crate::context_bootstrap) use value::{
+ ValueEventKind, build_value_event_template, install_value_event_template_bindings,
+};
+
const CLOSE_EVENT_WAS_CLEAN_SLOT: &str = "__moliCloseEventWasClean";
const CLOSE_EVENT_CODE_SLOT: &str = "__moliCloseEventCode";
const CLOSE_EVENT_REASON_SLOT: &str = "__moliCloseEventReason";
@@ -232,7 +237,8 @@ pub(crate) use base::{
EVENT_DISPATCHING_SLOT, EVENT_PASSIVE_SLOT, EVENT_STOP_IMMEDIATE_PROPAGATION_SLOT,
EVENT_STOP_PROPAGATION_SLOT, clear_event_composed_path, define_event_property, event_backing,
event_initialized, event_internal_bool_flag, event_is_dispatching, initialize_event_object,
- mark_event_trusted, set_event_composed_path, set_event_internal_flag, set_event_trusted,
+ initialize_event_object_with_type, mark_event_trusted, set_event_composed_path,
+ set_event_internal_flag, set_event_trusted,
};
fn event_subclass_kind<'s>(
diff --git a/moli-renderer-v8/src/context_bootstrap/events/base.rs b/moli-renderer-v8/src/context_bootstrap/events/base.rs
index 3f5f86712..a5aa67ec7 100644
--- a/moli-renderer-v8/src/context_bootstrap/events/base.rs
+++ b/moli-renderer-v8/src/context_bootstrap/events/base.rs
@@ -331,18 +331,19 @@ pub(crate) fn initialize_event_object<'s>(
bubbles: bool,
cancelable: bool,
) {
- let event = event_backing(scope, event);
- initialize_event_declaration(scope, event, event_type, bubbles, cancelable);
+ let event_type = v8_string(scope, event_type).expect("event type value");
+ initialize_event_object_with_type(scope, event, event_type, bubbles, cancelable);
}
-fn initialize_event_declaration<'s>(
+pub(crate) fn initialize_event_object_with_type<'s>(
scope: &mut v8::PinScope<'s, '_>,
event: v8::Local<'s, v8::Object>,
- event_type: &str,
+ event_type: v8::Local<'s, v8::String>,
bubbles: bool,
cancelable: bool,
) {
- initialized_event_header_declaration(scope, event_type)
+ let event = event_backing(scope, event);
+ InitializedEventHeaderDeclaration::new(event_type)
.initialize(scope, event)
.expect("initialized event header declaration should initialize");
initialize_event_after_header(scope, event, bubbles, cancelable);
@@ -448,14 +449,6 @@ define_event_core_attribute_getter!(event_default_prevented_getter_function, "de
define_event_core_attribute_getter!(event_composed_getter_function, "composed");
define_event_core_attribute_getter!(event_src_element_getter_function, "srcElement");
-fn initialized_event_header_declaration<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- event_type: &str,
-) -> InitializedEventHeaderDeclaration<'s> {
- let type_value = v8_string(scope, event_type).expect("event type value");
- InitializedEventHeaderDeclaration::new(type_value)
-}
-
fn initialized_event_tail_declaration(
scope: &mut v8::PinScope<'_, '_>,
) -> InitializedEventTailDeclaration {
diff --git a/moli-renderer-v8/src/context_bootstrap/events/value.rs b/moli-renderer-v8/src/context_bootstrap/events/value.rs
new file mode 100644
index 000000000..3651681dd
--- /dev/null
+++ b/moli-renderer-v8/src/context_bootstrap/events/value.rs
@@ -0,0 +1,295 @@
+//! Constructible event payloads that do not require an animation or recording backend.
+
+use super::{
+ define_event_property, event_private_value, initialize_event_object_with_type,
+ initialize_event_wrapper, new_event_state, set_event_private_value,
+};
+use crate::{
+ util::{new_null_prototype_object, throw_type_error, v8str},
+ web_api_interfaces, webidl,
+};
+use moli_webapi_declare::WebApiFunctionTemplate;
+
+const NAME_SLOT: &str = "__moliValueEventName";
+const ELAPSED_TIME_SLOT: &str = "__moliValueEventElapsedTime";
+const PSEUDO_ELEMENT_SLOT: &str = "__moliValueEventPseudoElement";
+const BLOB_SLOT: &str = "__moliValueEventBlob";
+const TIMECODE_SLOT: &str = "__moliValueEventTimecode";
+
+#[derive(Clone, Copy)]
+pub(in crate::context_bootstrap) enum ValueEventKind {
+ Animation,
+ Transition,
+ Blob,
+}
+
+impl ValueEventKind {
+ fn name(self) -> &'static str {
+ match self {
+ Self::Animation => "AnimationEvent",
+ Self::Transition => "TransitionEvent",
+ Self::Blob => "BlobEvent",
+ }
+ }
+
+ fn length(self) -> i32 {
+ match self {
+ Self::Blob => 2,
+ _ => 1,
+ }
+ }
+}
+
+#[derive(WebApiFunctionTemplate)]
+#[webapi(interface = web_api_interfaces::AnimationEvent, enumerable, receiver)]
+struct AnimationEventPrototypeDeclaration {
+ #[webapi(accessor_property = "animationName", getter = payload_getter, data = v8str(scope, NAME_SLOT))]
+ animation_name: (),
+ #[webapi(accessor_property = "elapsedTime", getter = payload_getter, data = v8str(scope, ELAPSED_TIME_SLOT))]
+ elapsed_time: (),
+ #[webapi(accessor_property = "pseudoElement", getter = payload_getter, data = v8str(scope, PSEUDO_ELEMENT_SLOT))]
+ pseudo_element: (),
+}
+
+#[derive(WebApiFunctionTemplate)]
+#[webapi(interface = web_api_interfaces::TransitionEvent, enumerable, receiver)]
+struct TransitionEventPrototypeDeclaration {
+ #[webapi(accessor_property = "propertyName", getter = payload_getter, data = v8str(scope, NAME_SLOT))]
+ property_name: (),
+ #[webapi(accessor_property = "elapsedTime", getter = payload_getter, data = v8str(scope, ELAPSED_TIME_SLOT))]
+ elapsed_time: (),
+ #[webapi(accessor_property = "pseudoElement", getter = payload_getter, data = v8str(scope, PSEUDO_ELEMENT_SLOT))]
+ pseudo_element: (),
+}
+
+#[derive(WebApiFunctionTemplate)]
+#[webapi(interface = web_api_interfaces::BlobEvent, enumerable, receiver)]
+struct BlobEventPrototypeDeclaration {
+ #[webapi(accessor_property, getter = payload_getter, data = v8str(scope, BLOB_SLOT))]
+ data: (),
+ #[webapi(accessor_property, getter = payload_getter, data = v8str(scope, TIMECODE_SLOT))]
+ timecode: (),
+}
+
+// Inherited dictionary members precede derived members, whose declaration order
+// follows Web IDL's lexicographic conversion order. Preserve DOMString code units.
+#[derive(webidl::WebIdlDictionary)]
+#[webidl(prefix = "AnimationEventInit")]
+struct AnimationEventInit<'s> {
+ #[webidl(default = false)]
+ bubbles: bool,
+ #[webidl(default = false)]
+ cancelable: bool,
+ #[webidl(default = false)]
+ composed: bool,
+ #[webidl(name = "animationName", with = string_member)]
+ animation_name: v8::Local<'s, v8::String>,
+ #[webidl(name = "elapsedTime", converter = "double", default = 0.0)]
+ elapsed_time: f64,
+ #[webidl(name = "pseudoElement", with = string_member)]
+ pseudo_element: v8::Local<'s, v8::String>,
+}
+
+#[derive(webidl::WebIdlDictionary)]
+#[webidl(prefix = "TransitionEventInit")]
+struct TransitionEventInit<'s> {
+ #[webidl(default = false)]
+ bubbles: bool,
+ #[webidl(default = false)]
+ cancelable: bool,
+ #[webidl(default = false)]
+ composed: bool,
+ #[webidl(name = "elapsedTime", converter = "double", default = 0.0)]
+ elapsed_time: f64,
+ #[webidl(name = "propertyName", with = string_member)]
+ property_name: v8::Local<'s, v8::String>,
+ #[webidl(name = "pseudoElement", with = string_member)]
+ pseudo_element: v8::Local<'s, v8::String>,
+}
+
+#[derive(webidl::WebIdlDictionary)]
+#[webidl(prefix = "BlobEventInit")]
+struct BlobEventInit<'s> {
+ #[webidl(default = false)]
+ bubbles: bool,
+ #[webidl(default = false)]
+ cancelable: bool,
+ #[webidl(default = false)]
+ composed: bool,
+ #[webidl(with = blob_member)]
+ data: v8::Local<'s, v8::Object>,
+ #[webidl(converter = "double")]
+ timecode: Option<f64>,
+}
+
+fn string_member<'s>(
+ scope: &mut v8::PinScope<'s, '_>,
+ object: v8::Local<'s, v8::Object>,
+ name: &'static str,
+) -> Result<v8::Local<'s, v8::String>, webidl::WebIdlError> {
+ let context = webidl::Context::member("EventInit", name);
+ let value = webidl::property_result(scope, object, name, context)?;
+ match value.filter(|value| !value.is_undefined()) {
+ Some(value) => value
+ .to_string(scope)
+ .ok_or_else(|| webidl::WebIdlError::pending_exception(context)),
+ None => Ok(v8str(scope, "")),
+ }
+}
+
+fn blob_member<'s>(
+ scope: &mut v8::PinScope<'s, '_>,
+ object: v8::Local<'s, v8::Object>,
+ name: &'static str,
+) -> Result<v8::Local<'s, v8::Object>, webidl::WebIdlError> {
+ let context = webidl::Context::member("BlobEventInit", name);
+ let value = webidl::property_result(scope, object, name, context)?
+ .filter(|value| !value.is_undefined())
+ .ok_or_else(|| webidl::WebIdlError::missing_required(context))?;
+ let object = v8::Local::<v8::Object>::try_from(value)
+ .map_err(|_| webidl::WebIdlError::cannot_convert(context, "Blob"))?;
+ if !web_api_interfaces::Blob::is_instance(scope, object) {
+ return Err(webidl::WebIdlError::cannot_convert(context, "Blob"));
+ }
+ Ok(object)
+}
+
+pub(in crate::context_bootstrap) fn install_value_event_template_bindings<'s>(
+ scope: &mut v8::PinScope<'s, '_, ()>,
+ template: v8::Local<'s, v8::FunctionTemplate>,
+ name: &str,
+) {
+ let prototype = template.prototype_template(scope);
+ match name {
+ "AnimationEvent" => {
+ AnimationEventPrototypeDeclaration::initialize_prototype_template(scope, prototype)
+ }
+ "TransitionEvent" => {
+ TransitionEventPrototypeDeclaration::initialize_prototype_template(scope, prototype)
+ }
+ "BlobEvent" => {
+ BlobEventPrototypeDeclaration::initialize_prototype_template(scope, prototype)
+ }
+ _ => {}
+ }
+}
+
+fn payload_getter<'s>(
+ scope: &mut v8::PinScope<'s, '_>,
+ args: v8::FunctionCallbackArguments<'s>,
+ mut rv: v8::ReturnValue<'_, v8::Value>,
+) {
+ let key = args.data().to_rust_string_lossy(scope);
+ if let Some(value) = event_private_value(scope, args.this(), &key) {
+ rv.set(value);
+ }
+}
+
+pub(in crate::context_bootstrap) fn build_value_event_template<'s>(
+ scope: &mut v8::PinScope<'s, '_, ()>,
+ kind: ValueEventKind,
+) -> v8::Local<'s, v8::FunctionTemplate> {
+ v8::FunctionTemplate::builder(value_event_constructor)
+ .data(v8::Integer::new(scope, kind as i32).into())
+ .length(kind.length())
+ .build(scope)
+}
+
+fn value_event_constructor<'s>(
+ scope: &mut v8::PinScope<'s, '_>,
+ args: v8::FunctionCallbackArguments<'s>,
+ mut rv: v8::ReturnValue<'_, v8::Value>,
+) {
+ let kind = match args.data().int32_value(scope) {
+ Some(0) => ValueEventKind::Animation,
+ Some(1) => ValueEventKind::Transition,
+ Some(2) => ValueEventKind::Blob,
+ _ => return,
+ };
+ if !args.is_construct_call() {
+ throw_type_error(scope, &format!("{} requires 'new'.", kind.name()));
+ return;
+ }
+ if args.length() < kind.length() {
+ throw_type_error(
+ scope,
+ &format!("{} requires {} arguments.", kind.name(), kind.length()),
+ );
+ return;
+ }
+ let Some(event_type) = args.get(0).to_string(scope) else {
+ return;
+ };
+ let state = new_event_state(scope);
+ let result = (|| -> Result<(), webidl::WebIdlError> {
+ let dictionary =
+ webidl::dictionary_arg(&args, 1, webidl::Context::argument(kind.name(), 2))?
+ .unwrap_or_else(|| new_null_prototype_object(scope));
+ let (bubbles, cancelable, composed) = match kind {
+ ValueEventKind::Animation => {
+ let parsed =
+ webidl::parse_dictionary_object::<AnimationEventInit>(scope, dictionary)?;
+ set_event_private_value(scope, state, NAME_SLOT, parsed.animation_name.into());
+ set_event_private_value(
+ scope,
+ state,
+ ELAPSED_TIME_SLOT,
+ v8::Number::new(scope, parsed.elapsed_time).into(),
+ );
+ set_event_private_value(
+ scope,
+ state,
+ PSEUDO_ELEMENT_SLOT,
+ parsed.pseudo_element.into(),
+ );
+ (parsed.bubbles, parsed.cancelable, parsed.composed)
+ }
+ ValueEventKind::Transition => {
+ let parsed =
+ webidl::parse_dictionary_object::<TransitionEventInit>(scope, dictionary)?;
+ set_event_private_value(scope, state, NAME_SLOT, parsed.property_name.into());
+ set_event_private_value(
+ scope,
+ state,
+ ELAPSED_TIME_SLOT,
+ v8::Number::new(scope, parsed.elapsed_time).into(),
+ );
+ set_event_private_value(
+ scope,
+ state,
+ PSEUDO_ELEMENT_SLOT,
+ parsed.pseudo_element.into(),
+ );
+ (parsed.bubbles, parsed.cancelable, parsed.composed)
+ }
+ ValueEventKind::Blob => {
+ let parsed = webidl::parse_dictionary_object::<BlobEventInit>(scope, dictionary)?;
+ set_event_private_value(scope, state, BLOB_SLOT, parsed.data.into());
+ set_event_private_value(
+ scope,
+ state,
+ TIMECODE_SLOT,
+ v8::Number::new(scope, parsed.timecode.unwrap_or(f64::NAN)).into(),
+ );
+ (parsed.bubbles, parsed.cancelable, parsed.composed)
+ }
+ };
+ initialize_event_object_with_type(scope, state, event_type, bubbles, cancelable);
+ define_event_property(
+ scope,
+ state,
+ "composed",
+ v8::Boolean::new(scope, composed).into(),
+ );
+ Ok(())
+ })();
+ if let Err(error) = result {
+ webidl::throw_error(scope, &error);
+ return;
+ }
+ web_api_interfaces::initialize(scope, state, kind.name())
+ .expect("value event brand should initialize");
+ if initialize_event_wrapper(scope, args.this(), state).is_some() {
+ rv.set(args.this().into());
+ }
+}
diff --git a/moli-renderer-v8/src/context_bootstrap/specs/registry.rs b/moli-renderer-v8/src/context_bootstrap/specs/registry.rs
index 42950acdf..8ed008eef 100644
--- a/moli-renderer-v8/src/context_bootstrap/specs/registry.rs
+++ b/moli-renderer-v8/src/context_bootstrap/specs/registry.rs
@@ -188,6 +188,18 @@ const CONSTRUCTOR_SPECS_BEFORE_STREAMS: &[ConstructorSpec] = &[
interface: web_api_interfaces::Event::DESCRIPTOR,
kind: ConstructorKind::Event,
},
+ ConstructorSpec {
+ interface: web_api_interfaces::AnimationEvent::DESCRIPTOR,
+ kind: ConstructorKind::AnimationEvent,
+ },
+ ConstructorSpec {
+ interface: web_api_interfaces::TransitionEvent::DESCRIPTOR,
+ kind: ConstructorKind::TransitionEvent,
+ },
+ ConstructorSpec {
+ interface: web_api_interfaces::BlobEvent::DESCRIPTOR,
+ kind: ConstructorKind::BlobEvent,
+ },
ConstructorSpec {
interface: web_api_interfaces::UIEvent::DESCRIPTOR,
kind: ConstructorKind::UiEvent,
diff --git a/moli-renderer-v8/src/context_bootstrap/specs/types.rs b/moli-renderer-v8/src/context_bootstrap/specs/types.rs
index 1d32bb52d..93db2156a 100644
--- a/moli-renderer-v8/src/context_bootstrap/specs/types.rs
+++ b/moli-renderer-v8/src/context_bootstrap/specs/types.rs
@@ -3,6 +3,9 @@ pub(in crate::context_bootstrap) enum ConstructorKind {
Illegal,
Unsupported,
Event,
+ AnimationEvent,
+ TransitionEvent,
+ BlobEvent,
UiEvent,
FocusEvent,
CompositionEvent,
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.rs
index c8d50e946..85ea20881 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
@@ -50,6 +50,7 @@ mod transferable_streams;
mod traversal;
mod traversal_coordinator;
mod trusted_types;
+mod value_events;
mod web_audio;
mod webrtc;
diff --git a/moli-renderer-v8/src/script_vm/tests/browser_api/value_events.js b/moli-renderer-v8/src/script_vm/tests/browser_api/value_events.js
new file mode 100644
index 000000000..d6e008945
--- /dev/null
+++ b/moli-renderer-v8/src/script_vm/tests/browser_api/value_events.js
@@ -0,0 +1,89 @@
+(() => {
+ function assert(value, message) { if (!value) throw new Error(message); }
+ function throws(expected, fn, message) {
+ try { fn(); } catch(error) {
+ assert(error instanceof expected, message + ': wrong exception ' + error);
+ return;
+ }
+ throw new Error(message + ': did not throw');
+ }
+ const frame = document.createElement('iframe');
+ document.body.appendChild(frame);
+ const child = frame.contentWindow;
+ try {
+ for (const realm of [window, child]) {
+ const blob = new realm.Blob(['value']);
+ for (const [name, member, init, expected, order] of [
+ ['AnimationEvent', 'animationName', {animationName:'name\uD800', elapsedTime:-0, pseudoElement:'::\uDC00'}, 'name\uD800',
+ ['bubbles','cancelable','composed','animationName','elapsedTime','pseudoElement']],
+ ['TransitionEvent', 'propertyName', {propertyName:'name\uD800', elapsedTime:2.5, pseudoElement:'::\uDC00'}, 'name\uD800',
+ ['bubbles','cancelable','composed','elapsedTime','propertyName','pseudoElement']],
+ ['BlobEvent', 'data', {data:blob, timecode:123}, blob,
+ ['bubbles','cancelable','composed','data','timecode']]
+ ]) {
+ const C = realm[name];
+ const gets = [];
+ const values = {...init,bubbles:true,cancelable:true,composed:true};
+ const event = new C('type\uD800', new Proxy(values, {
+ get(target,key,receiver) { gets.push(key); return Reflect.get(target,key,receiver); }
+ }));
+ assert(gets.join(',') === order.join(','), name + ': dictionary order ' + gets);
+ assert(event.type === 'type\uD800' && event[member] === expected, name + ': UTF-16/data');
+ assert(event.bubbles && event.cancelable && event.composed && !event.isTrusted, name + ': flags');
+ assert(event instanceof realm.Event && event instanceof C, name + ': inheritance');
+ assert(Object.getPrototypeOf(C) === realm.Event && Object.getPrototypeOf(C.prototype) === realm.Event.prototype, name + ': prototype chain');
+ assert(Object.prototype.toString.call(event) === '[object ' + name + ']', name + ': tag');
+ const descriptor = Object.getOwnPropertyDescriptor(C.prototype,member);
+ assert(descriptor.enumerable && descriptor.configurable && !descriptor.set &&
+ descriptor.get.length === 0 && descriptor.get.name === 'get ' + member &&
+ !Object.hasOwn(event,member), name + ': accessor');
+ throws(realm.TypeError, () => C('x', init), name + ': new required');
+ throws(realm.TypeError, () => new C(), name + ': arguments required');
+ for(const bad of [true, 42, 'bad', Symbol('bad')]) {
+ throws(realm.TypeError, () => new C('x', bad), name + ': dictionary required');
+ }
+ let traps = 0;
+ const proxy = new Proxy(event, {get(){++traps;throw new Error('trap');},getPrototypeOf(){++traps;throw new Error('trap');}});
+ const revoked = Proxy.revocable(event,{}); revoked.revoke();
+ for(const fake of [{},Object.create(event),proxy,revoked.proxy,new realm.Event('x')]) {
+ throws(realm.TypeError, () => descriptor.get.call(fake), name + ': native receiver');
+ }
+ assert(traps === 0, name + ': proxy traps');
+ const other = new window[name]('x', init);
+ assert(descriptor.get.call(other) === expected, name + ': cross-realm receiver');
+ const marker = {};
+ const failedReads = [];
+ try {
+ new C('x', new Proxy(values,{get(target,key,receiver) {
+ failedReads.push(key);
+ if (key === order[3]) throw marker;
+ return Reflect.get(target,key,receiver);
+ }}));
+ throw new Error('not thrown');
+ } catch(error) { assert(error === marker, name + ': exception identity'); }
+ assert(failedReads.join(',') === order.slice(0,4).join(','), name + ': short-circuit');
+ if (name !== 'BlobEvent') {
+ assert(event.pseudoElement === '::\uDC00', name + ': pseudo-element UTF-16');
+ assert(Object.is(event.elapsedTime,init.elapsedTime), name + ': signed zero');
+ for(const value of [NaN,Infinity,-Infinity,1n,Symbol('bad')]) {
+ throws(realm.TypeError, () => new C('x',{elapsedTime:value}), name + ': finite double');
+ }
+ }
+ let dispatched = null;
+ const target = document.createElement('div');
+ target.addEventListener(event.type, value => { dispatched = value; value.preventDefault(); });
+ assert(!target.dispatchEvent(event) && dispatched === event && event[member] === expected, name + ': dispatch');
+ }
+ for(const init of [null,undefined,{}, {data:null},{data:undefined},{data:{}},{data:Object.create(blob)}, {data:new Proxy(blob,{})}]) {
+ throws(realm.TypeError, () => new realm.BlobEvent('x',init), 'BlobEvent: Blob brand required');
+ }
+ const file = new realm.File(['x'],'x.txt');
+ assert(new realm.BlobEvent('x',{data:file}).data === file, 'BlobEvent: File is Blob');
+ assert(Number.isNaN(new realm.BlobEvent('x',{data:blob}).timecode), 'BlobEvent: omitted timecode');
+ for(const value of [NaN,Infinity,-Infinity]) {
+ throws(realm.TypeError, () => new realm.BlobEvent('x',{data:blob,timecode:value}), 'BlobEvent: finite timecode');
+ }
+ }
+ return true;
+ } finally { frame.remove(); }
+})()
diff --git a/moli-renderer-v8/src/script_vm/tests/browser_api/value_events.rs b/moli-renderer-v8/src/script_vm/tests/browser_api/value_events.rs
new file mode 100644
index 000000000..a96c81cfc
--- /dev/null
+++ b/moli-renderer-v8/src/script_vm/tests/browser_api/value_events.rs
@@ -0,0 +1,10 @@
+use super::*;
+
+#[test]
+fn animation_transition_and_blob_events_preserve_native_payloads_and_conversions() {
+ let mut vm = new_parsed_test_vm("https://value-events.test/", "<!doctype html><body></body>");
+ let result = vm
+ .eval(include_str!("value_events.js"))
+ .expect("event payload constructors should preserve Web IDL semantics");
+ assert_eq!(result, "true");
+}
diff --git a/moli-renderer-v8/src/web_api_interfaces.rs b/moli-renderer-v8/src/web_api_interfaces.rs
index f79cf1a55..00b287078 100644
--- a/moli-renderer-v8/src/web_api_interfaces.rs
+++ b/moli-renderer-v8/src/web_api_interfaces.rs
@@ -26,6 +26,7 @@ interfaces! {
AnalyserNode;
Animation;
AnimationEffect;
+ AnimationEvent: Event;
AnimationPlaybackEvent: Event;
AnimationTimeline;
Attr: Node;
@@ -41,6 +42,7 @@ interfaces! {
BeforeUnloadEvent: Event;
BiquadFilterNode;
Blob;
+ BlobEvent: Event;
BroadcastChannel: EventTarget;
ByteLengthQueuingStrategy;
CDATASection: Text;
@@ -459,6 +461,7 @@ interfaces! {
TouchList;
TrackEvent: Event;
TransformStream;
+ TransitionEvent: Event;
TransformStreamDefaultController;
TreeWalker;
TrustedHTML;
diff --git a/moli-webidl/src/error.rs b/moli-webidl/src/error.rs
index 9c95507c9..d914b1e51 100644
--- a/moli-webidl/src/error.rs
+++ b/moli-webidl/src/error.rs
@@ -64,6 +64,10 @@ impl WebIdlError {
Self::new(context, WebIdlErrorKind::MissingRequired)
}
+ pub fn cannot_convert(context: Context, target_type: &'static str) -> Self {
+ Self::new(context, WebIdlErrorKind::CannotConvert(target_type))
+ }
+
pub fn custom_message(message: &'static str) -> Self {
Self::new(
Context::argument("", 1),