Skip to content

armgit / moli

Public Imported from GitHub
0

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

feat(speech): construct native synthesis events with validated payloads

ldm09c45bdc81c50
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 7cf2431fc..a9718ec3b 100644
--- a/moli-renderer-v8/src/context_bootstrap/assets/constructor_templates.rs
+++ b/moli-renderer-v8/src/context_bootstrap/assets/constructor_templates.rs
@@ -673,6 +673,14 @@ pub(in crate::context_bootstrap) fn build_constructor_template<'s>(
| ConstructorKind::Screen => v8::FunctionTemplate::builder(illegal_constructor_callback)
.length(0)
.build(scope),
+ ConstructorKind::SpeechSynthesisEvent => super::super::events::speech::build_template(
+ scope,
+ super::super::events::speech::SpeechEventKind::Synthesis,
+ ),
+ ConstructorKind::SpeechSynthesisErrorEvent => super::super::events::speech::build_template(
+ scope,
+ super::super::events::speech::SpeechEventKind::Error,
+ ),
ConstructorKind::SpeechSynthesisUtterance => {
v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(
web_api_interfaces::SpeechSynthesisUtterance,
diff --git a/moli-renderer-v8/src/context_bootstrap/event_template.rs b/moli-renderer-v8/src/context_bootstrap/event_template.rs
index 907c7d9a3..28da36009 100644
--- a/moli-renderer-v8/src/context_bootstrap/event_template.rs
+++ b/moli-renderer-v8/src/context_bootstrap/event_template.rs
@@ -450,6 +450,7 @@ pub(super) fn install_event_template_bindings<'s>(
install_event_base_bindings(scope, template);
}
super::events::install_value_event_template_bindings(scope, template, spec.interface.name());
+ super::events::speech::install(scope, template, spec.interface.name());
super::events::install_device_event_template_bindings(scope, template, spec.interface.name());
if let Some(declaration) = event_template_declaration(spec.interface.name()) {
diff --git a/moli-renderer-v8/src/context_bootstrap/events.rs b/moli-renderer-v8/src/context_bootstrap/events.rs
index c238c7488..3f79270c7 100644
--- a/moli-renderer-v8/src/context_bootstrap/events.rs
+++ b/moli-renderer-v8/src/context_bootstrap/events.rs
@@ -15,6 +15,7 @@ mod value;
mod wrappers;
pub(in crate::context_bootstrap) mod audio;
+pub(in crate::context_bootstrap) mod speech;
pub(in crate::context_bootstrap) use device::{
device_motion_event_constructor, device_orientation_event_constructor,
diff --git a/moli-renderer-v8/src/context_bootstrap/events/speech.rs b/moli-renderer-v8/src/context_bootstrap/events/speech.rs
new file mode 100644
index 000000000..3f2ea5156
--- /dev/null
+++ b/moli-renderer-v8/src/context_bootstrap/events/speech.rs
@@ -0,0 +1,247 @@
+//! Speech event construction is independent of the speech synthesis backend.
+
+use super::{
+ EventInit, 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, v8_string_from_utf16_units, v8str},
+ web_api_interfaces, webidl,
+};
+use moli_webapi_declare::WebApiFunctionTemplate;
+
+const UTTERANCE: &str = "__moliSpeechEventUtterance";
+const CHAR_INDEX: &str = "__moliSpeechEventCharIndex";
+const CHAR_LENGTH: &str = "__moliSpeechEventCharLength";
+const ELAPSED_TIME: &str = "__moliSpeechEventElapsedTime";
+const NAME: &str = "__moliSpeechEventName";
+const ERROR: &str = "__moliSpeechEventError";
+
+#[derive(Clone, Copy)]
+pub(in crate::context_bootstrap) enum SpeechEventKind {
+ Synthesis,
+ Error,
+}
+
+impl SpeechEventKind {
+ fn name(self) -> &'static str {
+ match self {
+ Self::Synthesis => "SpeechSynthesisEvent",
+ Self::Error => "SpeechSynthesisErrorEvent",
+ }
+ }
+}
+
+#[derive(Clone, Copy, webidl::WebIdlEnum)]
+#[webidl(name = "SpeechSynthesisErrorCode", rename_all = "kebab-case")]
+enum SpeechSynthesisErrorCode {
+ Canceled,
+ Interrupted,
+ AudioBusy,
+ AudioHardware,
+ Network,
+ SynthesisUnavailable,
+ SynthesisFailed,
+ LanguageUnavailable,
+ VoiceUnavailable,
+ TextTooLong,
+ InvalidArgument,
+ NotAllowed,
+}
+
+impl SpeechSynthesisErrorCode {
+ fn token(self) -> &'static str {
+ match self {
+ Self::Canceled => "canceled",
+ Self::Interrupted => "interrupted",
+ Self::AudioBusy => "audio-busy",
+ Self::AudioHardware => "audio-hardware",
+ Self::Network => "network",
+ Self::SynthesisUnavailable => "synthesis-unavailable",
+ Self::SynthesisFailed => "synthesis-failed",
+ Self::LanguageUnavailable => "language-unavailable",
+ Self::VoiceUnavailable => "voice-unavailable",
+ Self::TextTooLong => "text-too-long",
+ Self::InvalidArgument => "invalid-argument",
+ Self::NotAllowed => "not-allowed",
+ }
+ }
+}
+
+#[derive(webidl::WebIdlDictionary)]
+#[webidl(prefix = "SpeechSynthesisEventInit")]
+struct SpeechSynthesisEventInit<'s> {
+ #[webidl(inherit)]
+ base: EventInit,
+ #[webidl(required, interface = web_api_interfaces::SpeechSynthesisUtterance)]
+ utterance: v8::Local<'s, v8::Object>,
+ #[webidl(default = 0)]
+ char_index: u32,
+ #[webidl(default = 0)]
+ char_length: u32,
+ #[webidl(default = 0.0)]
+ elapsed_time: f32,
+ #[webidl(default = webidl::DomString16(Vec::new()), converter = "raw")]
+ name: webidl::DomString16,
+}
+
+#[derive(webidl::WebIdlDictionary)]
+#[webidl(prefix = "SpeechSynthesisErrorEventInit")]
+struct SpeechSynthesisErrorEventInit<'s> {
+ #[webidl(inherit)]
+ base: SpeechSynthesisEventInit<'s>,
+ #[webidl(required, converter = "enum")]
+ error: SpeechSynthesisErrorCode,
+}
+
+#[derive(WebApiFunctionTemplate)]
+#[webapi(interface = web_api_interfaces::SpeechSynthesisEvent, enumerable, receiver)]
+struct SpeechSynthesisEventPrototypeDeclaration {
+ #[webapi(accessor_property, getter = payload_getter, data = v8str(scope, UTTERANCE))]
+ utterance: (),
+ #[webapi(accessor_property, getter = payload_getter, data = v8str(scope, CHAR_INDEX))]
+ char_index: (),
+ #[webapi(accessor_property, getter = payload_getter, data = v8str(scope, CHAR_LENGTH))]
+ char_length: (),
+ #[webapi(accessor_property, getter = payload_getter, data = v8str(scope, ELAPSED_TIME))]
+ elapsed_time: (),
+ #[webapi(accessor_property, getter = payload_getter, data = v8str(scope, NAME))]
+ name: (),
+}
+
+#[derive(WebApiFunctionTemplate)]
+#[webapi(interface = web_api_interfaces::SpeechSynthesisErrorEvent, enumerable, receiver)]
+struct SpeechSynthesisErrorEventPrototypeDeclaration {
+ #[webapi(accessor_property, getter = payload_getter, data = v8str(scope, ERROR))]
+ error: (),
+}
+
+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 install<'s>(
+ scope: &mut v8::PinScope<'s, '_, ()>,
+ template: v8::Local<'s, v8::FunctionTemplate>,
+ name: &str,
+) {
+ let prototype = template.prototype_template(scope);
+ match name {
+ "SpeechSynthesisEvent" => {
+ SpeechSynthesisEventPrototypeDeclaration::initialize_prototype_template(
+ scope, prototype,
+ )
+ }
+ "SpeechSynthesisErrorEvent" => {
+ SpeechSynthesisErrorEventPrototypeDeclaration::initialize_prototype_template(
+ scope, prototype,
+ )
+ }
+ _ => {}
+ }
+}
+
+pub(in crate::context_bootstrap) fn build_template<'s>(
+ scope: &mut v8::PinScope<'s, '_, ()>,
+ kind: SpeechEventKind,
+) -> v8::Local<'s, v8::FunctionTemplate> {
+ v8::FunctionTemplate::builder(constructor)
+ .data(v8::Boolean::new(scope, matches!(kind, SpeechEventKind::Error)).into())
+ .length(2)
+ .build(scope)
+}
+
+fn constructor<'s>(
+ scope: &mut v8::PinScope<'s, '_>,
+ args: v8::FunctionCallbackArguments<'s>,
+ mut rv: v8::ReturnValue<'_, v8::Value>,
+) {
+ let kind = if args.data().is_true() {
+ SpeechEventKind::Error
+ } else {
+ SpeechEventKind::Synthesis
+ };
+ if !args.is_construct_call() {
+ throw_type_error(scope, &format!("{} requires 'new'.", kind.name()));
+ return;
+ }
+ if args.length() < 2 {
+ throw_type_error(scope, &format!("{} requires 2 arguments.", kind.name()));
+ return;
+ }
+ let Some(event_type) = args.get(0).to_string(scope) else {
+ return;
+ };
+ let parsed = (|| {
+ let dictionary =
+ webidl::dictionary_arg(&args, 1, webidl::Context::argument(kind.name(), 2))?
+ .unwrap_or_else(|| new_null_prototype_object(scope));
+ match kind {
+ SpeechEventKind::Synthesis => {
+ webidl::parse_dictionary_object::<SpeechSynthesisEventInit>(scope, dictionary)
+ .map(|init| (init, None))
+ }
+ SpeechEventKind::Error => {
+ webidl::parse_dictionary_object::<SpeechSynthesisErrorEventInit>(scope, dictionary)
+ .map(|init| (init.base, Some(init.error)))
+ }
+ }
+ })();
+ let (init, error) = match parsed {
+ Ok(parsed) => parsed,
+ Err(error) => {
+ webidl::throw_error(scope, &error);
+ return;
+ }
+ };
+ let state = new_event_state(scope);
+ initialize_event_object_with_type(
+ scope,
+ state,
+ event_type,
+ init.base.bubbles,
+ init.base.cancelable,
+ );
+ define_event_property(
+ scope,
+ state,
+ "composed",
+ v8::Boolean::new(scope, init.base.composed).into(),
+ );
+ set_event_private_value(scope, state, UTTERANCE, init.utterance.into());
+ set_event_private_value(
+ scope,
+ state,
+ CHAR_INDEX,
+ v8::Integer::new_from_unsigned(scope, init.char_index).into(),
+ );
+ set_event_private_value(
+ scope,
+ state,
+ CHAR_LENGTH,
+ v8::Integer::new_from_unsigned(scope, init.char_length).into(),
+ );
+ set_event_private_value(
+ scope,
+ state,
+ ELAPSED_TIME,
+ v8::Number::new(scope, f64::from(init.elapsed_time)).into(),
+ );
+ let name = v8_string_from_utf16_units(scope, &init.name.0).expect("speech event name");
+ set_event_private_value(scope, state, NAME, name.into());
+ if let Some(error) = error {
+ set_event_private_value(scope, state, ERROR, v8str(scope, error.token()).into());
+ }
+ web_api_interfaces::initialize(scope, state, kind.name())
+ .expect("speech 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/exposed_interfaces/metadata.rs b/moli-renderer-v8/src/context_bootstrap/exposed_interfaces/metadata.rs
index dc44d983c..d4c8ab6bb 100644
--- a/moli-renderer-v8/src/context_bootstrap/exposed_interfaces/metadata.rs
+++ b/moli-renderer-v8/src/context_bootstrap/exposed_interfaces/metadata.rs
@@ -782,6 +782,32 @@ mod tests {
assert!(dom_error.is_supported_by(TemplateBuildProfile::Window));
}
+ #[test]
+ fn shell_speech_events_uses_the_expected_exposure_and_lazy_policy() {
+ let table = ExposedInterfaceMetadataTable::from_constructor_specs(
+ &crate::context_bootstrap::specs::constructor_specs(),
+ )
+ .expect("shell exposure metadata");
+ for name in ["SpeechSynthesisEvent", "SpeechSynthesisErrorEvent"] {
+ let metadata = table.metadata_by_name(name).expect("interface metadata");
+ assert_eq!(metadata.installation, GlobalInstallation::Lazy, "{name}");
+ for (realm, expected) in [
+ (RealmKind::Window, true),
+ (RealmKind::DedicatedWorker, false),
+ (RealmKind::SharedWorker, false),
+ (RealmKind::ServiceWorker, false),
+ ] {
+ assert_eq!(metadata.is_exposed(realm, true), expected, "{name}");
+ assert_eq!(metadata.is_exposed(realm, false), expected, "{name}");
+ assert_eq!(
+ metadata.is_supported_by(TemplateBuildProfile::for_realm(realm)),
+ expected,
+ "{name}"
+ );
+ }
+ }
+ }
+
#[test]
fn metadata_rejects_duplicate_unknown_parent_and_cycle() {
assert!(
diff --git a/moli-renderer-v8/src/context_bootstrap/specs/registry.rs b/moli-renderer-v8/src/context_bootstrap/specs/registry.rs
index edc5f127a..4c7c3354f 100644
--- a/moli-renderer-v8/src/context_bootstrap/specs/registry.rs
+++ b/moli-renderer-v8/src/context_bootstrap/specs/registry.rs
@@ -752,6 +752,14 @@ const CONSTRUCTOR_SPECS_BEFORE_STREAMS: &[ConstructorSpec] = &[
interface: web_api_interfaces::SpeechSynthesisUtterance::DESCRIPTOR,
kind: ConstructorKind::SpeechSynthesisUtterance,
},
+ ConstructorSpec {
+ interface: web_api_interfaces::SpeechSynthesisEvent::DESCRIPTOR,
+ kind: ConstructorKind::SpeechSynthesisEvent,
+ },
+ ConstructorSpec {
+ interface: web_api_interfaces::SpeechSynthesisErrorEvent::DESCRIPTOR,
+ kind: ConstructorKind::SpeechSynthesisErrorEvent,
+ },
ConstructorSpec {
interface: web_api_interfaces::SpeechSynthesisVoice::DESCRIPTOR,
kind: ConstructorKind::Illegal,
diff --git a/moli-renderer-v8/src/context_bootstrap/specs/types.rs b/moli-renderer-v8/src/context_bootstrap/specs/types.rs
index 38c42fddc..d972eda25 100644
--- a/moli-renderer-v8/src/context_bootstrap/specs/types.rs
+++ b/moli-renderer-v8/src/context_bootstrap/specs/types.rs
@@ -120,6 +120,8 @@ pub(in crate::context_bootstrap) enum ConstructorKind {
WorkerLocation,
Screen,
SpeechSynthesisUtterance,
+ SpeechSynthesisEvent,
+ SpeechSynthesisErrorEvent,
WebSocketError,
WebSocketStream,
DomRectReadOnly,
diff --git a/moli-renderer-v8/src/script_vm/tests/mod.rs b/moli-renderer-v8/src/script_vm/tests/mod.rs
index 151ace88b..a38ae5534 100644
--- a/moli-renderer-v8/src/script_vm/tests/mod.rs
+++ b/moli-renderer-v8/src/script_vm/tests/mod.rs
@@ -2189,6 +2189,7 @@ mod readable_algorithm_arrays;
mod remote_playback_interface;
mod rendering_update;
mod script_terminal_completion;
+mod speech_events;
mod storage_dense_name_arrays;
mod streams;
mod svg_filter_interfaces;
diff --git a/moli-renderer-v8/src/script_vm/tests/speech_events.js b/moli-renderer-v8/src/script_vm/tests/speech_events.js
new file mode 100644
index 000000000..ef2c40127
--- /dev/null
+++ b/moli-renderer-v8/src/script_vm/tests/speech_events.js
@@ -0,0 +1,104 @@
+(() => {
+ const assert = (condition, message) => { if (!condition) throw Error(message); };
+ const throws = (run, Expected, label) => {
+ let error;
+ try { run(); } catch (caught) { error = caught; }
+ assert(error instanceof Expected, label + ': ' + error);
+ return error;
+ };
+ const errors = ['canceled', 'interrupted', 'audio-busy', 'audio-hardware', 'network',
+ 'synthesis-unavailable', 'synthesis-failed', 'language-unavailable',
+ 'voice-unavailable', 'text-too-long', 'invalid-argument', 'not-allowed'];
+ const child = document.getElementById('child').contentWindow;
+ for (const realm of [window, child]) {
+ const utterance = new realm.SpeechSynthesisUtterance('hello');
+ for (const name of ['SpeechSynthesisEvent', 'SpeechSynthesisErrorEvent']) {
+ const Constructor = realm[name];
+ const isError = name === 'SpeechSynthesisErrorEvent';
+ const Parent = isError ? realm.SpeechSynthesisEvent : realm.Event;
+ assert(typeof Constructor === 'function' && Constructor.name === name && Constructor.length === 2, name + ' constructor');
+ assert(Object.getPrototypeOf(Constructor) === Parent, name + ' constructor inheritance');
+ assert(Object.getPrototypeOf(Constructor.prototype) === Parent.prototype, name + ' prototype inheritance');
+ assert(Constructor.prototype.constructor === Constructor, name + ' prototype constructor');
+ const tag = Object.getOwnPropertyDescriptor(Constructor.prototype, Symbol.toStringTag);
+ assert(tag.value === name && !tag.writable && !tag.enumerable && tag.configurable, name + ' tag');
+ const callError = throws(() => Constructor(), realm.TypeError, name + ' requires new');
+ if (realm !== window) assert(!(callError instanceof TypeError), name + ' callee error realm');
+ for (const args of [[], ['x'], ['x', null], ['x', undefined], ['x', {}], ['x', { utterance: null }]]) {
+ throws(() => Reflect.construct(Constructor, args), realm.TypeError, name + ' required utterance');
+ }
+ const init = isError ? { utterance, error: 'network' } : { utterance };
+ const event = new Constructor('boundary', init);
+ assert(event instanceof Constructor && event instanceof realm.SpeechSynthesisEvent && event instanceof realm.Event, name + ' identity');
+ assert(Object.prototype.toString.call(event) === '[object ' + name + ']', name + ' instance tag');
+ assert(event.type === 'boundary' && event.utterance === utterance, name + ' type and utterance');
+ assert(event.charIndex === 0 && event.charLength === 0 && event.elapsedTime === 0 && event.name === '', name + ' payload defaults');
+ assert(!event.bubbles && !event.cancelable && !event.composed && !event.isTrusted && event.target === null, name + ' Event defaults');
+ if (isError) assert(event.error === 'network', 'error payload');
+ const converted = new Constructor('end\uD800', {
+ ...init, bubbles: true, cancelable: true, composed: true,
+ charIndex: 2 ** 32 + 3.8, charLength: -1,
+ elapsedTime: 1 / 3, name: 'word\uD800',
+ });
+ assert(converted.type === 'end\uD800' && converted.name === 'word\uD800', name + ' DOMString code units');
+ assert(converted.charIndex === 3 && converted.charLength === 4294967295 && converted.elapsedTime === Math.fround(1 / 3), name + ' numeric conversion');
+ assert(converted.bubbles && converted.cancelable && converted.composed, name + ' inherited EventInit');
+ class Derived extends Constructor {}
+ const derived = new Derived('boundary', init);
+ assert(Object.getPrototypeOf(derived) === Derived.prototype && derived.utterance === utterance, name + ' new.target');
+ const target = new realm.EventTarget();
+ let delivered;
+ target.addEventListener('boundary', value => { delivered = value; value.preventDefault(); });
+ const cancelable = new Constructor('boundary', { ...init, cancelable: true });
+ assert(target.dispatchEvent(cancelable) === false && delivered === cancelable && cancelable.defaultPrevented, name + ' native dispatch');
+ for (const property of isError ? ['error'] : ['utterance', 'charIndex', 'charLength', 'elapsedTime', 'name']) {
+ const descriptor = Object.getOwnPropertyDescriptor(Constructor.prototype, property);
+ assert(typeof descriptor.get === 'function' && descriptor.set === undefined && descriptor.enumerable && descriptor.configurable, name + '.' + property + ' readonly accessor');
+ assert(descriptor.get.call(event) === event[property], name + '.' + property + ' genuine receiver');
+ for (const receiver of [{}, Object.create(Constructor.prototype), Object.create(event), new Proxy(event, {})]) {
+ throws(() => descriptor.get.call(receiver), realm.TypeError, name + '.' + property + ' native brand');
+ }
+ const revoked = Proxy.revocable(event, {});
+ revoked.revoke();
+ throws(() => descriptor.get.call(revoked.proxy), realm.TypeError, name + '.' + property + ' revoked proxy');
+ }
+ for (const elapsedTime of [NaN, Infinity, -Infinity, 3.5e38, Symbol('time'), 1n]) {
+ throws(() => new Constructor('x', { ...init, elapsedTime }), realm.TypeError, name + ' restricted float');
+ }
+ let trapReads = 0;
+ const fake = new Proxy(utterance, { get() { trapReads++; throw Error('trap'); } });
+ throws(() => new Constructor('x', { ...init, utterance: fake }), realm.TypeError, name + ' author proxy utterance');
+ assert(trapReads === 0, name + ' brand check avoids author traps');
+ }
+ for (const error of errors) {
+ assert(new realm.SpeechSynthesisErrorEvent('error', { utterance, error }).error === error, 'enum ' + error);
+ }
+ for (const error of [undefined, '', 'Network', 'unknown', null]) {
+ throws(() => new realm.SpeechSynthesisErrorEvent('error', { utterance, error }), realm.TypeError, 'invalid error enum');
+ }
+ const reads = [];
+ const ordered = { bubbles: false, cancelable: false, composed: false,
+ charIndex: 0, charLength: 0, elapsedTime: 0, name: '', utterance, error: 'network' };
+ const dictionary = new Proxy(ordered, { get(target, key) { reads.push(key); return target[key]; } });
+ new realm.SpeechSynthesisErrorEvent({ toString() { reads.push('type'); return 'error'; } }, dictionary);
+ assert(reads.join(',') === 'type,bubbles,cancelable,composed,charIndex,charLength,elapsedTime,name,utterance,error', 'inherited dictionary conversion order: ' + reads);
+ const sentinel = {};
+ let caught;
+ try { new realm.SpeechSynthesisEvent('x', { utterance, get elapsedTime() { throw sentinel; } }); } catch (error) { caught = error; }
+ assert(caught === sentinel, 'dictionary getter exception identity');
+ caught = undefined;
+ try { new realm.SpeechSynthesisEvent('x', { utterance, name: { toString() { throw sentinel; } } }); } catch (error) { caught = error; }
+ assert(caught === sentinel, 'DOMString conversion exception identity');
+ let errorReads = 0;
+ throws(() => new realm.SpeechSynthesisErrorEvent('error', {
+ utterance: {}, get error() { errorReads++; return 'network'; },
+ }), realm.TypeError, 'base dictionary validation precedes derived members');
+ assert(errorReads === 0, 'invalid utterance stops conversion');
+ }
+ const foreignUtterance = new child.SpeechSynthesisUtterance('foreign');
+ const cross = new SpeechSynthesisEvent('end', { utterance: foreignUtterance });
+ assert(cross.utterance === foreignUtterance, 'cross-realm native utterance accepted');
+ const foreignGetter = Object.getOwnPropertyDescriptor(child.SpeechSynthesisEvent.prototype, 'charIndex').get;
+ assert(foreignGetter.call(cross) === 0, 'cross-realm genuine receiver accepted');
+ return 'ok';
+})()
diff --git a/moli-renderer-v8/src/script_vm/tests/speech_events.rs b/moli-renderer-v8/src/script_vm/tests/speech_events.rs
new file mode 100644
index 000000000..fbd078e02
--- /dev/null
+++ b/moli-renderer-v8/src/script_vm/tests/speech_events.rs
@@ -0,0 +1,19 @@
+use super::*;
+
+#[test]
+fn speech_events_construct_native_payloads_and_validate_dictionaries() {
+ for url in [
+ "https://shell-interfaces.test/",
+ "http://shell-interfaces.test/",
+ "http://localhost/",
+ ] {
+ let mut vm = new_storage_page_task_executor_test_vm(url);
+ vm.eval("document.body.innerHTML = '<iframe id=child></iframe>'")
+ .unwrap();
+ assert_eq!(
+ vm.eval(include_str!("speech_events.js")).unwrap(),
+ "ok",
+ "{url}"
+ );
+ }
+}
diff --git a/moli-renderer-v8/src/web_api_interfaces.rs b/moli-renderer-v8/src/web_api_interfaces.rs
index 6e8e45ce9..d8245aeac 100644
--- a/moli-renderer-v8/src/web_api_interfaces.rs
+++ b/moli-renderer-v8/src/web_api_interfaces.rs
@@ -526,6 +526,8 @@ interfaces! {
SharedWorker: EventTarget;
SharedWorkerGlobalScope: WorkerGlobalScope;
SpeechSynthesis: EventTarget;
+ SpeechSynthesisEvent: Event;
+ SpeechSynthesisErrorEvent: SpeechSynthesisEvent;
SpeechSynthesisUtterance: EventTarget;
SpeechSynthesisVoice;
StaticRange: AbstractRange;