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(css): use native FontFaceSet bindings and shared EventTarget
ldm0c3b795bff26a
diff --git a/moli-renderer-v8/src/context_bootstrap.rs b/moli-renderer-v8/src/context_bootstrap.rsindex ae790e890..666925790 100644--- a/moli-renderer-v8/src/context_bootstrap.rs+++ b/moli-renderer-v8/src/context_bootstrap.rs@@ -130,7 +130,7 @@ pub(crate) use crypto::{CryptoKeyAlgorithmClonePayload, CryptoKeyClonePayload, WebCryptoRejection, WebCryptoTaskResult,crypto_key_clone_payload_from_object, crypto_key_object_from_clone_payload,};-pub(crate) use css_fontface_runtime::rebuild_font_face_set_faces;+pub(crate) use css_fontface_runtime::{new_font_face_set, rebuild_font_face_set_faces};pub(crate) use location_navigation::{LocationNavigationKind, dispatch_top_level_form_navigation_event,dispatch_top_level_navigation_event_with_source_element, meta_refresh_navigation_kind,diff --git a/moli-renderer-v8/src/context_bootstrap/assets/constructor_templates.rs b/moli-renderer-v8/src/context_bootstrap/assets/constructor_templates.rsindex b8db5765b..770ade205 100644--- a/moli-renderer-v8/src/context_bootstrap/assets/constructor_templates.rs+++ b/moli-renderer-v8/src/context_bootstrap/assets/constructor_templates.rs@@ -8,7 +8,7 @@ use super::super::{webgl_debug_renderer_info_constructor_callback, webgl_lose_context_constructor_callback,webgl_rendering_context_constructor_callback,},- css_fontface_runtime::{font_face_constructor_callback, font_face_set_constructor_callback},+ 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},@@ -711,7 +711,8 @@ pub(in crate::context_bootstrap) fn build_constructor_template<'s>(| ConstructorKind::NavigationHistoryEntry| ConstructorKind::NavigationActivation| ConstructorKind::NavigationTransition- | ConstructorKind::MediaQueryList => {+ | ConstructorKind::MediaQueryList+ | ConstructorKind::FontFaceSet => {v8::FunctionTemplate::builder(illegal_constructor_callback).build(scope)}ConstructorKind::MediaSource => {@@ -842,14 +843,6 @@ pub(in crate::context_bootstrap) fn build_constructor_template<'s>(.length(2).build(scope)}- ConstructorKind::FontFaceSet => {- v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(- web_api_interfaces::FontFaceSet,- font_face_set_constructor_callback- ))- .length(0)- .build(scope)- }ConstructorKind::AudioContext => build_audio_context_constructor_template(scope),ConstructorKind::AudioWorkletNode => build_audio_worklet_node_constructor_template(scope),ConstructorKind::OfflineAudioContext => {diff --git a/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime.rs b/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime.rsindex f981336ef..cc1358b82 100644--- a/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime.rs+++ b/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime.rs@@ -43,12 +43,11 @@ pub(super) use font_face::{font_face_constructor_callback, font_face_load_callback, install_font_face_template_accessors,};pub(super) use font_face_set::{- font_face_set_add_callback, font_face_set_add_event_listener_callback,- font_face_set_check_callback, font_face_set_clear_callback, font_face_set_constructor_callback,- font_face_set_delete_callback, font_face_set_dispatch_event_callback,- font_face_set_entries_callback, font_face_set_for_each_callback, font_face_set_has_callback,- font_face_set_keys_callback, font_face_set_load_callback,- font_face_set_remove_event_listener_callback, font_face_set_values_callback,+ font_face_set_add_callback, font_face_set_check_callback, font_face_set_clear_callback,+ font_face_set_delete_callback, font_face_set_entries_callback, font_face_set_for_each_callback,+ font_face_set_has_callback, font_face_set_keys_callback, font_face_set_load_callback,+ font_face_set_values_callback,};pub(super) use storage::install_font_face_set_template_accessors;+pub(crate) use storage::new_font_face_set;pub(crate) use storage::rebuild_font_face_set_faces;diff --git a/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime/events.rs b/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime/events.rsindex 0183cd8ba..9010b91e8 100644--- a/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime/events.rs+++ b/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime/events.rs@@ -39,7 +39,7 @@ const FONT_FACE_SET_EVENT_HANDLERS: &[FontFaceSetEventHandler] = &[];#[derive(WebApiFunctionTemplate)]-#[webapi(interface = web_api_interfaces::FontFaceSet)]+#[webapi(interface = web_api_interfaces::FontFaceSet, receiver)]struct FontFaceSetEventHandlerAccessorsDeclaration {#[webapi(accessor_property,@@ -70,7 +70,7 @@ struct FontFaceSetEventHandlerAccessorsDeclaration {}#[derive(WebApiFunctionTemplate)]-#[webapi(interface = web_api_interfaces::FontFaceSetLoadEvent, enumerable)]+#[webapi(interface = web_api_interfaces::FontFaceSetLoadEvent, enumerable, receiver)]struct FontFaceSetLoadEventPrototypeDeclaration {#[webapi(accessor_property,@@ -103,6 +103,7 @@ pub(super) fn initialize_font_face_set_event_target<'s>(scope: &mut v8::PinScope<'s, '_>,object: v8::Local<'s, v8::Object>,) {+ mark_simple_event_target_slot(scope, object, FONT_FACE_SET_LISTENERS_SLOT);for handler in FONT_FACE_SET_EVENT_HANDLERS {set_private_value(scope, object, handler.slot_name, v8::null(scope).into());}@@ -242,6 +243,9 @@ fn dispatched_font_face_set_load_event<'s>() -> v8::Local<'s, v8::Object> {let event = v8::Object::new(scope);initialize_event_object(scope, event, event_type, false, false);+ web_api_interfaces::FontFaceSetLoadEvent::DESCRIPTOR+ .initialize(scope, event)+ .expect("font loading events should carry their native interface brand");if let Some(prototype) = global_constructor_prototype(scope, "FontFaceSetLoadEvent") {let _ = event.set_prototype(scope, prototype.into());}diff --git a/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime/font_face_set.rs b/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime/font_face_set.rsindex b8c6146d5..51232433c 100644--- a/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime/font_face_set.rs+++ b/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime/font_face_set.rs@@ -5,14 +5,12 @@ use super::query::{};use super::storage::{array_contains_value, font_face_set_faces_array, font_face_set_manual_faces_array,- initialize_font_face_set_object, is_font_face_value, rebuild_font_face_set_faces,- replace_font_face_set_ready_promise, set_font_face_set_slot_value, set_font_face_set_status,+ is_font_face_value, rebuild_font_face_set_faces, replace_font_face_set_ready_promise,+ set_font_face_set_slot_value, set_font_face_set_status,};use super::*;mod collection;-mod constructor;-mod event_target;mod iteration;mod loading;@@ -20,11 +18,6 @@ pub(in crate::context_bootstrap) use collection::{font_face_set_add_callback, font_face_set_clear_callback, font_face_set_delete_callback,font_face_set_has_callback,};-pub(in crate::context_bootstrap) use constructor::font_face_set_constructor_callback;-pub(in crate::context_bootstrap) use event_target::{- font_face_set_add_event_listener_callback, font_face_set_dispatch_event_callback,- font_face_set_remove_event_listener_callback,-};pub(in crate::context_bootstrap) use iteration::{font_face_set_entries_callback, font_face_set_for_each_callback, font_face_set_keys_callback,font_face_set_values_callback,diff --git a/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime/font_face_set/constructor.rs b/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime/font_face_set/constructor.rsdeleted file mode 100644index 639c6e3e3..000000000--- a/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime/font_face_set/constructor.rs+++ /dev/null@@ -1,18 +0,0 @@-use super::*;--pub(in crate::context_bootstrap) fn font_face_set_constructor_callback<'s>(- scope: &mut v8::PinScope<'s, '_>,- args: v8::FunctionCallbackArguments<'s>,- mut rv: v8::ReturnValue<'s, v8::Value>,-) {- if !args.is_construct_call() {- throw_type_error(scope, "Constructor must be called with new");- return;- }- if args.length() > 0 {- throw_type_error(scope, "Illegal constructor");- return;- }- initialize_font_face_set_object(scope, args.this());- rv.set(args.this().into());-}diff --git a/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime/font_face_set/event_target.rs b/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime/font_face_set/event_target.rsdeleted file mode 100644index 9bf32ee91..000000000--- a/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime/font_face_set/event_target.rs+++ /dev/null@@ -1,51 +0,0 @@-use super::*;--pub(in crate::context_bootstrap) fn font_face_set_add_event_listener_callback<'s>(- scope: &mut v8::PinScope<'s, '_>,- args: v8::FunctionCallbackArguments<'s>,- mut rv: v8::ReturnValue<'s, v8::Value>,-) {- simple_object_event_target_add_listener(scope, &args, FONT_FACE_SET_LISTENERS_SLOT);- rv.set_undefined();-}--pub(in crate::context_bootstrap) fn font_face_set_remove_event_listener_callback<'s>(- scope: &mut v8::PinScope<'s, '_>,- args: v8::FunctionCallbackArguments<'s>,- mut rv: v8::ReturnValue<'s, v8::Value>,-) {- simple_object_event_target_remove_listener(scope, &args, FONT_FACE_SET_LISTENERS_SLOT);- rv.set_undefined();-}--pub(in crate::context_bootstrap) fn font_face_set_dispatch_event_callback<'s>(- scope: &mut v8::PinScope<'s, '_>,- args: v8::FunctionCallbackArguments<'s>,- mut rv: v8::ReturnValue<'s, v8::Value>,-) {- let event_value = args.get(0);- if !event_value.is_object() || event_value.is_function() {- rv.set(v8::Boolean::new(scope, false).into());- return;- }- let Ok(event) = v8::Local::<v8::Object>::try_from(event_value) else {- rv.set(v8::Boolean::new(scope, false).into());- return;- };- let Some(event_type) = event- .get(scope, v8str(scope, "type").into())- .and_then(|value| value.to_string(scope))- .map(|value| value.to_rust_string_lossy(scope))- else {- rv.set(v8::Boolean::new(scope, false).into());- return;- };- let dispatched = dispatch_simple_event_target_event(- scope,- args.this(),- FONT_FACE_SET_LISTENERS_SLOT,- &event_type,- event,- );- rv.set(v8::Boolean::new(scope, dispatched).into());-}diff --git a/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime/storage.rs b/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime/storage.rsindex a0a08fedf..64c39734f 100644--- a/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime/storage.rs+++ b/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime/storage.rs@@ -25,7 +25,7 @@ struct FontFaceSetObjectDeclaration {}#[derive(WebApiFunctionTemplate)]-#[webapi(interface = web_api_interfaces::FontFaceSet)]+#[webapi(interface = web_api_interfaces::FontFaceSet, receiver)]struct FontFaceSetPrototypeAccessorsDeclaration {#[webapi(accessor_property,@@ -38,6 +38,7 @@ struct FontFaceSetPrototypeAccessorsDeclaration {accessor_property,getter = font_face_set_attribute_getter_callback,data = callback_data_index_value(scope, 1),+ returns_promise,enumerable)]ready: (),@@ -104,15 +105,13 @@ fn font_face_set_attribute_getter_callback<'s>(}}-pub(super) fn initialize_font_face_set_object<'s>(+pub(crate) fn new_font_face_set<'s>(scope: &mut v8::PinScope<'s, '_>,- object: v8::Local<'s, v8::Object>,-) {- FontFaceSetObjectDeclaration::default()- .initialize(scope, object)- .expect("FontFaceSet declaration should initialize object");+) -> Option<v8::Local<'s, v8::Object>> {+ let object = FontFaceSetObjectDeclaration::default().bind(scope).ok()?;initialize_font_face_set_event_target(scope, object);replace_font_face_set_ready_promise(scope, object);+ Some(object)}pub(super) fn replace_font_face_set_ready_promise<'s>(diff --git a/moli-renderer-v8/src/context_bootstrap/style_font_template.rs b/moli-renderer-v8/src/context_bootstrap/style_font_template.rsindex 2b6c7b58c..fb056b714 100644--- a/moli-renderer-v8/src/context_bootstrap/style_font_template.rs+++ b/moli-renderer-v8/src/context_bootstrap/style_font_template.rs@@ -1,11 +1,9 @@use super::{css_fontface_runtime::{- font_face_load_callback, font_face_set_add_callback,- font_face_set_add_event_listener_callback, font_face_set_check_callback,+ font_face_load_callback, font_face_set_add_callback, font_face_set_check_callback,font_face_set_clear_callback, font_face_set_delete_callback,- font_face_set_dispatch_event_callback, font_face_set_entries_callback,- font_face_set_for_each_callback, font_face_set_has_callback, font_face_set_keys_callback,- font_face_set_load_callback, font_face_set_remove_event_listener_callback,+ font_face_set_entries_callback, font_face_set_for_each_callback,+ font_face_set_has_callback, font_face_set_keys_callback, font_face_set_load_callback,font_face_set_values_callback, install_font_face_set_event_handler_accessors,install_font_face_set_load_event_template_accessors,install_font_face_set_template_accessors, install_font_face_template_accessors,@@ -23,7 +21,7 @@ struct FontFaceTemplateMethodsDeclaration {}#[derive(WebApiFunctionTemplate)]-#[webapi(interface = web_api_interfaces::FontFaceSet, enumerable)]+#[webapi(interface = web_api_interfaces::FontFaceSet, enumerable, receiver)]struct FontFaceSetTemplateMethodsDeclaration {#[webapi(method, length = 1, callback = font_face_set_add_callback)]add: (),@@ -40,7 +38,7 @@ struct FontFaceSetTemplateMethodsDeclaration {#[webapi(method, length = 1, callback = font_face_set_check_callback)]check: (),- #[webapi(method, length = 1, callback = font_face_set_load_callback)]+ #[webapi(method, length = 1, callback = font_face_set_load_callback, returns_promise)]load: (),#[webapi(method, length = 0, callback = font_face_set_keys_callback)]@@ -57,19 +55,6 @@ struct FontFaceSetTemplateMethodsDeclaration {#[webapi(method, length = 1, callback = font_face_set_for_each_callback)]for_each: (),-- #[webapi(method, length = 2, callback = font_face_set_add_event_listener_callback)]- add_event_listener: (),-- #[webapi(- method,- length = 2,- callback = font_face_set_remove_event_listener_callback- )]- remove_event_listener: (),-- #[webapi(method, length = 1, callback = font_face_set_dispatch_event_callback)]- dispatch_event: (),}pub(super) fn install_style_font_template_bindings<'s>(diff --git a/moli-renderer-v8/src/native_bridge/document/css_state/accessors.rs b/moli-renderer-v8/src/native_bridge/document/css_state/accessors.rsindex fe80467ea..46ccbb2c6 100644--- a/moli-renderer-v8/src/native_bridge/document/css_state/accessors.rs+++ b/moli-renderer-v8/src/native_bridge/document/css_state/accessors.rs@@ -614,26 +614,10 @@ fn document_fonts_for_receiver<'s>(rv.set(existing);return;}- let global = scope.get_current_context().global(scope);- let Some(ctor_value) = global.get(scope, v8str(scope, "FontFaceSet").into()) else {- rv.set_undefined();- return;- };- let Ok(ctor) = v8::Local::<v8::Function>::try_from(ctor_value) else {- rv.set_undefined();- return;- };- let Some(fonts) = ctor.new_instance(scope, &[]) else {+ let Some(fonts) = create_document_font_face_set(scope, holder) else {rv.set_undefined();return;};- set_private_value(- scope,- fonts,- FONT_FACE_SET_OWNER_DOCUMENT_SLOT,- holder.into(),- );- let _ = holder.set(scope, slot.into(), fonts.into());if !is_detached {let _ = sync_document_fonts(scope, holder, runtime, handle);}@@ -653,25 +637,28 @@ pub(in crate::native_bridge::document) fn detached_document_fonts_getter<'s>(rv.set(existing);return;}- let global = scope.get_current_context().global(scope);- let Some(ctor_value) = global.get(scope, v8str(scope, "FontFaceSet").into()) else {- rv.set_undefined();- return;- };- let Ok(ctor) = v8::Local::<v8::Function>::try_from(ctor_value) else {- rv.set_undefined();- return;- };- let Some(fonts) = ctor.new_instance(scope, &[]) else {+ let Some(fonts) = create_document_font_face_set(scope, holder) else {rv.set_undefined();return;};+ rv.set(fonts.into());+}++fn create_document_font_face_set<'s>(+ scope: &mut v8::PinScope<'s, '_>,+ holder: v8::Local<'s, v8::Object>,+) -> Option<v8::Local<'s, v8::Object>> {+ // FontFaceSource creates its set natively in the Document's realm; the+ // public FontFaceSet interface object is not a callable constructor.+ let context = holder.get_creation_context(scope)?;+ let scope = &mut v8::ContextScope::new(scope, context);+ let fonts = crate::context_bootstrap::new_font_face_set(scope)?;set_private_value(scope,fonts,FONT_FACE_SET_OWNER_DOCUMENT_SLOT,holder.into(),);- let _ = holder.set(scope, slot.into(), fonts.into());- rv.set(fonts.into());+ let _ = holder.set(scope, v8str(scope, FONTS_SLOT).into(), fonts.into());+ Some(fonts)}diff --git a/moli-renderer-v8/src/script_vm/tests/browser_api/misc.rs b/moli-renderer-v8/src/script_vm/tests/browser_api/misc.rsindex f5053692e..2bd8c1830 100644--- a/moli-renderer-v8/src/script_vm/tests/browser_api/misc.rs+++ b/moli-renderer-v8/src/script_vm/tests/browser_api/misc.rs@@ -1577,7 +1577,7 @@ fn internal_dynamic_maps_ignore_object_prototype_pollution() {out.fileReaderProtoLength = Object.prototype.load.length;Object.prototype.loading = [];- const fonts = typeof FontFaceSet === "function" ? new FontFaceSet() : document.fonts;+ const fonts = document.fonts;fonts.addEventListener("loading", () => {});out.fontFaceSetProtoLength = Object.prototype.loading.length;@@ -1797,7 +1797,7 @@ fn font_face_set_load_event_copies_and_freezes_fontfaces() {}};- const fonts = new FontFaceSet();+ const fonts = document.implementation.createHTMLDocument('').fonts;fonts.add(face);let loadingShape = '';let doneShape = '';@@ -1883,7 +1883,7 @@ fn font_face_set_listeners_use_event_listener_callback_interface_semantics() {.eval(r#"(() => {- const fonts = new FontFaceSet();+ const fonts = document.implementation.createHTMLDocument('').fonts;const calls = [];let operationGets = 0;@@ -1998,7 +1998,7 @@ fn font_face_set_listener_uses_callback_realm_and_exact_window_lifetime() {(() => {const iframe = __fontFaceSetCallbackRealmFrame;const other = iframe.contentWindow;- const fonts = new FontFaceSet();+ const fonts = document.implementation.createHTMLDocument('').fonts;globalThis.__fontFaceSetCallbackRealmTarget = fonts;globalThis.__fontFaceSetCallbackExpectedRealm = other;globalThis.__fontFaceSetCallbackRealmFacts = [];@@ -2044,7 +2044,7 @@ fn font_face_load_updates_owner_sets_once_and_unlinks_removed_faces() {(() => {const face = new FontFace('Demo', 'url(demo.woff)');const documentFonts = document.fonts;- const secondary = new FontFaceSet();+ const secondary = document.implementation.createHTMLDocument('').fonts;documentFonts.add(face);secondary.add(face);@@ -2083,7 +2083,7 @@ fn font_face_load_updates_owner_sets_once_and_unlinks_removed_faces() {const eventCountBeforeRemovedLoad = events.length;removed.load();- const clearedSet = new FontFaceSet();+ const clearedSet = document.implementation.createHTMLDocument('').fonts;const cleared = new FontFace('Cleared', 'url(cleared.woff)');clearedSet.add(cleared);const clearedReadyBeforeLoad = clearedSet.ready;@@ -2347,7 +2347,7 @@ fn font_face_binary_source_union_rejects_invalid_font_data() {r#"(() => {const face = new FontFace('InvalidBinary', new ArrayBuffer(8));- const fonts = new FontFaceSet();+ const fonts = document.implementation.createHTMLDocument('').fonts;fonts.add(face);const events = [];for (const type of ['loading', 'loadingdone', 'loadingerror']) {@@ -2431,7 +2431,7 @@ fn maplike_and_setlike_iterators_use_v8_intrinsics_after_public_tampering() {styleTarget.style.display = "block";(document.body || document.documentElement || document).appendChild(styleTarget);const face = new FontFace("IntrinsicFace", "url(intrinsic.woff)");- const fontSet = new FontFaceSet();+ const fontSet = document.implementation.createHTMLDocument('').fonts;fontSet.add(face);const poisoned = function poisonedBuiltinIterator() {@@ -2545,6 +2545,73 @@ fn maplike_and_setlike_iterators_use_v8_intrinsics_after_public_tampering() {assert_eq!(result, "ok");}+#[test]+fn font_face_set_bindings_share_event_target_and_validate_native_receivers() {+ let mut vm = new_storage_test_vm("https://font-face-set-bindings.test/");+ vm.eval(&format!(+ r#"(async () => {{+ {}+ const frame = (document.body || document.documentElement || document)+ .appendChild(document.createElement('iframe'));+ const child = frame.contentWindow;+ const getter = Object.getOwnPropertyDescriptor(Document.prototype, 'fonts').get;+ const windowless = document.implementation.createHTMLDocument('');+ const mainConstructor = Object.getOwnPropertyDescriptor(window, 'FontFaceSet');+ const childConstructor = Object.getOwnPropertyDescriptor(child, 'FontFaceSet');+ const mainPrototype = FontFaceSet.prototype;+ const childPrototype = child.FontFaceSet.prototype;+ const poison = {{configurable: true, get() {{ throw new Error('author constructor'); }}}};+ let creation;+ try {{+ Object.defineProperty(window, 'FontFaceSet', poison);+ Object.defineProperty(child, 'FontFaceSet', poison);+ const childFonts = getter.call(child.document);+ creation = [+ Object.getPrototypeOf(document.fonts) === mainPrototype,+ Object.getPrototypeOf(windowless.fonts) === mainPrototype,+ Object.getPrototypeOf(childFonts) === childPrototype,+ childFonts === child.document.fonts,+ ];+ }} finally {{+ Object.defineProperty(window, 'FontFaceSet', mainConstructor);+ Object.defineProperty(child, 'FontFaceSet', childConstructor);+ }}+ const main = await fontFaceSetBindingsProbe(window, document.fonts);+ const other = await fontFaceSetBindingsProbe(child, child.document.fonts);+ const parentSize = Object.getOwnPropertyDescriptor(FontFaceSet.prototype, 'size').get;+ const childSize = Object.getOwnPropertyDescriptor(child.FontFaceSet.prototype, 'size').get;+ const face = new FontFace('CrossRealm', 'url(unused.ttf)');+ child.FontFaceSet.prototype.add.call(document.fonts, face);+ FontFaceSet.prototype.add.call(child.document.fonts, face);+ const crossRealm = [parentSize.call(child.document.fonts), childSize.call(document.fonts),+ child.FontFaceSet.prototype.has.call(document.fonts, face)];+ frame.remove();+ let illegal = false;+ try {{ new FontFaceSet([]); }} catch (error) {{ illegal = error instanceof TypeError; }}+ return JSON.stringify({{main, other, crossRealm, illegal, creation}});+ }})().then(+ result => globalThis.__fontFaceSetBindings = result,+ error => globalThis.__fontFaceSetBindings = String(error.stack || error)+ )"#,+ include_str!("../../../../tests/fixtures/fontfaceset-bindings.js"),+ ))+ .expect("FontFaceSet binding probe should evaluate");+ let result = vm+ .eval("__fontFaceSetBindings")+ .expect("FontFaceSet binding probe should settle");+ let result: serde_json::Value = serde_json::from_str(&result).unwrap();+ for realm in ["main", "other"] {+ assert_eq!(result[realm]["failures"], serde_json::json!([]), "{result}");+ assert_eq!(result[realm]["checks"], 221, "{result}");+ }+ assert_eq!(result["crossRealm"], serde_json::json!([1, 1, true]));+ assert_eq!(result["illegal"], true);+ assert_eq!(+ result["creation"],+ serde_json::json!([true, true, true, true])+ );+}+#[test]fn font_face_set_declared_slots_ignore_prototype_spoofing() {let mut vm = new_storage_test_vm("https://font-face-set-declared-slots.test/");@@ -2570,7 +2637,7 @@ fn font_face_set_declared_slots_ignore_prototype_spoofing() {].map(stringify).join(':');};const face = new FontFace('Demo', 'url(demo.woff)');- const fonts = new FontFaceSet();+ const fonts = document.implementation.createHTMLDocument('').fonts;const style = document.createElement('style');style.textContent = '@font-face { font-family: "Spoofed"; src: url(spoof.woff); }';(document.head || document.documentElement || document).appendChild(style);@@ -2614,12 +2681,14 @@ fn font_face_set_declared_slots_ignore_prototype_spoofing() {listenerCalls].join('|'),fake: [- fake.status,- fake.ready,- fake.size,- FontFaceSet.prototype.has.call(fake, face),- Array.from(FontFaceSet.prototype.values.call(fake)).length- ].map(stringify).join('|'),+ () => fake.status,+ () => fake.size,+ () => FontFaceSet.prototype.has.call(fake, face),+ () => FontFaceSet.prototype.values.call(fake)+ ].map(callback => {+ try { callback(); return 'accepted'; }+ catch (error) { return error.name; }+ }).join('|'),documentFontsOwnerSlot: documentFontsSlots.includes('__moliFontFaceSetOwnerDocument'),documentFontsSlots,descriptors: ['status', 'ready', 'size']@@ -2634,7 +2703,7 @@ fn font_face_set_declared_slots_ignore_prototype_spoofing() {assert_eq!(result,- r#"{"real":"loaded|function|1|true|1|1","fake":"undefined|undefined|0|false|0","documentFontsOwnerSlot":false,"documentFontsSlots":[],"descriptors":["status:function:get status:0:undefined:undefined:undefined:true:true:false","ready:function:get ready:0:undefined:undefined:undefined:true:true:false","size:function:get size:0:undefined:undefined:undefined:true:true:false"],"hasOwnSize":false,"ownSlots":[]}"#+ r#"{"real":"loaded|function|1|true|1|1","fake":"TypeError|TypeError|TypeError|TypeError","documentFontsOwnerSlot":false,"documentFontsSlots":[],"descriptors":["status:function:get status:0:undefined:undefined:undefined:true:true:false","ready:function:get ready:0:undefined:undefined:undefined:true:true:false","size:function:get size:0:undefined:undefined:undefined:true:true:false"],"hasOwnSize":false,"ownSlots":[]}"#);}diff --git a/moli-renderer-v8/src/web_api_interfaces.rs b/moli-renderer-v8/src/web_api_interfaces.rsindex 2b451a1a2..e69624661 100644--- a/moli-renderer-v8/src/web_api_interfaces.rs+++ b/moli-renderer-v8/src/web_api_interfaces.rs@@ -158,7 +158,7 @@ interfaces! {FileSystemWritableFileStream: WritableStream;FocusEvent: UIEvent;FontFace;- FontFaceSet;+ FontFaceSet: EventTarget;FontFaceSetIterator = "FontFaceSet Iterator";FontFaceSetLoadEvent: Event;FormData;diff --git a/moli-renderer-v8/tests/fixtures/fontfaceset-bindings.js b/moli-renderer-v8/tests/fixtures/fontfaceset-bindings.jsnew file mode 100644index 000000000..07632551a--- /dev/null+++ b/moli-renderer-v8/tests/fixtures/fontfaceset-bindings.js@@ -0,0 +1,127 @@+async function fontFaceSetBindingsProbe(realm, fonts) {+ const failures = [];+ let checks = 0;+ const check = (condition, label) => {+ ++checks;+ if (!condition) failures.push(label);+ };+ const throws = (callback, expected, label) => {+ try { callback(); check(false, label + ': accepted'); }+ catch (error) { check(error instanceof expected, label + ': exception realm'); }+ };+ const rejects = async (callback, expected, label) => {+ let promise;+ try { promise = callback(); }+ catch (_) { check(false, label + ': synchronous exception'); return; }+ check(promise instanceof realm.Promise, label + ': promise realm');+ try { await promise; check(false, label + ': fulfilled'); }+ catch (error) { check(error instanceof expected, label + ': exception realm'); }+ };+ // Use the intrinsic prototype even in browsers that do not expose the+ // FontFaceSet interface object as a global.+ const prototype = realm.Object.getPrototypeOf(fonts);+ check(realm.Object.getPrototypeOf(prototype) === realm.EventTarget.prototype, 'prototype inheritance');+ check(fonts instanceof realm.EventTarget, 'EventTarget identity');+ if (realm.FontFaceSet) {+ check(realm.Object.getPrototypeOf(realm.FontFaceSet) === realm.EventTarget, 'constructor inheritance');+ throws(() => new realm.FontFaceSet(), realm.TypeError, 'illegal zero-argument constructor');+ }+ for (const name of ['addEventListener', 'removeEventListener', 'dispatchEvent']) {+ check(!Object.hasOwn(prototype, name), 'inherited ' + name);+ check(fonts[name] === realm.EventTarget.prototype[name], 'shared ' + name);+ }++ const face = new realm.FontFace('BindingsProbe', 'url(unused-font.ttf)');+ let conversions = 0;+ let traps = 0;+ const query = {toString() { ++conversions; return '12px BindingsProbe'; }};+ const revoked = Proxy.revocable(fonts, {});+ revoked.revoke();+ const invalid = [null, undefined, 1, {}, Object.create(prototype), Object.create(fonts),+ new Proxy(fonts, {get() { ++traps; }, getPrototypeOf() { ++traps; return prototype; }}), revoked.proxy];+ const operations = [+ ['add', value => prototype.add.call(value, face)],+ ['has', value => prototype.has.call(value, face)],+ ['delete', value => prototype.delete.call(value, face)],+ ['clear', value => prototype.clear.call(value)],+ ['check', value => prototype.check.call(value, query)],+ ['keys', value => prototype.keys.call(value)],+ ['values', value => prototype.values.call(value)],+ ['entries', value => prototype.entries.call(value)],+ ['forEach', value => prototype.forEach.call(value, () => { ++conversions; })],+ ['addEventListener', value => fonts.addEventListener.call(value, query, () => {})],+ ['removeEventListener', value => fonts.removeEventListener.call(value, query, () => {})],+ ['dispatchEvent', value => fonts.dispatchEvent.call(value, new realm.Event('probe'))],+ ];+ for (const name of ['status', 'size', 'onloading', 'onloadingdone', 'onloadingerror']) {+ const descriptor = Object.getOwnPropertyDescriptor(prototype, name);+ operations.push(['get ' + name, value => descriptor.get.call(value)]);+ if (descriptor.set) operations.push(['set ' + name, value => descriptor.set.call(value, () => {})]);+ }+ const ready = Object.getOwnPropertyDescriptor(prototype, 'ready').get;+ for (const value of invalid) {+ for (const [name, operation] of operations) {+ // EventTarget has Global descendants: null/undefined this selects the+ // callback realm's global, which is a valid EventTarget.+ if (value == null && ['addEventListener', 'removeEventListener', 'dispatchEvent'].includes(name)) continue;+ throws(() => operation(value), realm.TypeError, name);+ }+ await rejects(() => prototype.load.call(value, query), realm.TypeError, 'load receiver');+ await rejects(() => ready.call(value), realm.TypeError, 'ready receiver');+ }+ check(conversions === 0, 'receiver validation before conversion');+ check(traps === 0, 'receiver validation without proxy traps');+ check(fonts.ready === ready.call(fonts), 'ready promise identity');+ await rejects(() => prototype.load.call(fonts), realm.TypeError, 'load required argument');+ await rejects(() => prototype.load.call(fonts, Symbol()), realm.TypeError, 'load string conversion');+ const marker = {};+ let conversionPromise;+ try {+ conversionPromise = prototype.load.call(fonts, {toString() { throw marker; }});+ } catch (_) { check(false, 'load conversion threw synchronously'); }+ if (conversionPromise) {+ check(conversionPromise instanceof realm.Promise, 'conversion promise realm');+ check(await conversionPromise.catch(error => error) === marker, 'conversion exception identity');+ }++ const methods = realm.EventTarget.prototype;+ const calls = [];+ const listener = event => {+ calls.push('listener');+ check(event.target === fonts && event.currentTarget === fonts, 'dispatch target');+ check(event.eventPhase === realm.Event.AT_TARGET, 'dispatch phase');+ throws(() => methods.dispatchEvent.call(fonts, event), realm.DOMException, 'recursive dispatch');+ };+ methods.addEventListener.call(fonts, 'loading', listener);+ fonts.onloading = () => calls.push('old handler');+ methods.addEventListener.call(fonts, 'loading', () => calls.push('once'), {once: true});+ fonts.onloading = () => { calls.push('handler'); return false; };+ methods.addEventListener.call(fonts, 'loading', () => calls.push('capture'), true);+ const controller = new realm.AbortController();+ methods.addEventListener.call(fonts, 'loading', () => check(false, 'aborted listener'), {signal: controller.signal});+ controller.abort();+ const event = new realm.Event('loading', {cancelable: true});+ check(methods.dispatchEvent.call(fonts, event) === false, 'event cancellation');+ check(calls.join() === 'capture,listener,handler,once', 'event handler order: ' + calls);+ check(event.currentTarget === null && event.eventPhase === 0, 'dispatch cleanup');+ methods.removeEventListener.call(fonts, 'loading', listener);+ fonts.onloading = null;+ calls.length = 0;+ check(fonts.dispatchEvent(new realm.Event('loading')), 'uncanceled dispatch');+ check(calls.join() === 'capture', 'shared removal and once');+ const fakeEvent = {get type() { ++traps; return 'loading'; }};+ throws(() => methods.dispatchEvent.call(fonts, fakeEvent), realm.TypeError, 'unbranded event');+ throws(() => methods.dispatchEvent.call(fonts, new Proxy(event, {})), realm.TypeError, 'proxy event');+ check(traps === 0, 'unbranded event properties not read');++ // The event interface is shared by script-created and native loading events.+ if (realm.FontFaceSetLoadEvent) {+ const getFaces = Object.getOwnPropertyDescriptor(realm.FontFaceSetLoadEvent.prototype, 'fontfaces').get;+ const loadEvent = new realm.FontFaceSetLoadEvent('loadingdone', {fontfaces: [face]});+ check(getFaces.call(loadEvent) === loadEvent.fontfaces && Object.isFrozen(loadEvent.fontfaces), 'frozen SameObject faces');+ for (const value of [{}, Object.create(loadEvent), new realm.Event('loadingdone'), new Proxy(loadEvent, {})]) {+ throws(() => getFaces.call(value), realm.TypeError, 'fontfaces receiver');+ }+ }+ return {checks, failures};+}diff --git a/moli-wpt-compat/fixtures/wpt/ported/css-font-loading/fontface-basic.html b/moli-wpt-compat/fixtures/wpt/ported/css-font-loading/fontface-basic.htmlindex 49665b462..03f0fa39f 100644--- a/moli-wpt-compat/fixtures/wpt/ported/css-font-loading/fontface-basic.html+++ b/moli-wpt-compat/fixtures/wpt/ported/css-font-loading/fontface-basic.html@@ -146,16 +146,18 @@ promise_test(async function () {assert_true(fonts.check("16px sans-serif"));}, "FontFaceSet load and check expose low-dependency font matching");-test(function () {+promise_test(async function (t) {const fonts = document.fonts;- assert_throws_name("TypeError", () => fonts.load(), "load font is required");+ await promise_rejects_js(t, TypeError, fonts.load(), "load font is required");assert_throws_name("TypeError", () => fonts.check(), "check font is required");- assert_throws_name("TypeError", () => fonts.load(Symbol("font")), "load font Symbol conversion should throw");+ await promise_rejects_js(t, TypeError, fonts.load(Symbol("font")), "load font Symbol conversion should reject");assert_throws_name("TypeError", () => fonts.check(Symbol("font")), "check font Symbol conversion should throw");- assert_throws_name(- "Error",- () => fonts.load({ toString() { throw new Error("font failed"); } }),+ const conversionError = new Error("font failed");+ await promise_rejects_exactly(+ t,+ conversionError,+ fonts.load({ toString() { throw conversionError; } }),"load font stringification errors should propagate",);assert_throws_name(