Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
refactor(webapi): migrate native construction paths to shared identity
ldm09f2e9632ac6d
diff --git a/moli-renderer-v8/src/blob.rs b/moli-renderer-v8/src/blob.rsindex 86747a024..d71dcb029 100644--- a/moli-renderer-v8/src/blob.rs+++ b/moli-renderer-v8/src/blob.rs@@ -28,7 +28,7 @@ fn native_blob_line_ending() -> &'static str {}#[derive(WebApiObject)]-#[webapi(interface = "Object")]+#[webapi(prototype = "Object", interface = "Blob")]struct BlobInstanceDeclaration<'scope> {#[webapi(slot = BLOB_ID_SLOT)]blob_id: v8::Local<'scope, v8::BigInt>,diff --git a/moli-renderer-v8/src/context_bootstrap/assets/constructor_templates.rs b/moli-renderer-v8/src/context_bootstrap/assets/constructor_templates.rsindex 8160b40bc..989187eec 100644--- a/moli-renderer-v8/src/context_bootstrap/assets/constructor_templates.rs+++ b/moli-renderer-v8/src/context_bootstrap/assets/constructor_templates.rs@@ -88,9 +88,11 @@ pub(in crate::context_bootstrap) fn build_constructor_template<'s>(.length(0).build(scope)}- ConstructorKind::Event => v8::FunctionTemplate::builder(event_constructor_callback)- .length(1)- .build(scope),+ ConstructorKind::Event => v8::FunctionTemplate::builder(+ moli_webapi_declare::web_api_constructor!("Event", event_constructor_callback),+ )+ .length(1)+ .build(scope),ConstructorKind::UiEvent => {build_event_subclass_template(scope, EventSubclassKind::UiEvent)}@@ -116,9 +118,12 @@ pub(in crate::context_bootstrap) fn build_constructor_template<'s>(build_event_subclass_template(scope, EventSubclassKind::ClipboardEvent)}ConstructorKind::ClipboardItem => {- v8::FunctionTemplate::builder(clipboard_item_constructor_callback)- .length(1)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "ClipboardItem",+ clipboard_item_constructor_callback+ ))+ .length(1)+ .build(scope)}ConstructorKind::KeyboardEvent => {build_event_subclass_template(scope, EventSubclassKind::KeyboardEvent)@@ -185,22 +190,33 @@ pub(in crate::context_bootstrap) fn build_constructor_template<'s>(build_event_subclass_template(scope, EventSubclassKind::FontFaceSetLoadEvent)}ConstructorKind::DomException => {- v8::FunctionTemplate::builder(dom_exception_constructor_callback)- .length(0)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "DOMException",+ dom_exception_constructor_callback+ ))+ .length(0)+ .build(scope)}- ConstructorKind::DomError => v8::FunctionTemplate::builder(dom_error_constructor_callback)- .length(1)- .build(scope),+ ConstructorKind::DomError => v8::FunctionTemplate::builder(+ moli_webapi_declare::web_api_constructor!("DOMError", dom_error_constructor_callback),+ )+ .length(1)+ .build(scope),ConstructorKind::QuotaExceededError => {- v8::FunctionTemplate::builder(quota_exceeded_error_constructor_callback)- .length(0)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "QuotaExceededError",+ quota_exceeded_error_constructor_callback+ ))+ .length(0)+ .build(scope)}ConstructorKind::CustomElementRegistry => {- v8::FunctionTemplate::builder(custom_elements_registry_constructor_callback)- .length(0)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "CustomElementRegistry",+ custom_elements_registry_constructor_callback+ ))+ .length(0)+ .build(scope)}ConstructorKind::Document => v8::FunctionTemplate::builder(document_constructor_callback).length(0)@@ -211,44 +227,68 @@ pub(in crate::context_bootstrap) fn build_constructor_template<'s>(.build(scope)}ConstructorKind::XmlHttpRequest => {- v8::FunctionTemplate::builder(network_host::xhr_constructor_callback)- .length(0)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "XMLHttpRequest",+ network_host::xhr_constructor_callback+ ))+ .length(0)+ .build(scope)}ConstructorKind::Headers => {- v8::FunctionTemplate::builder(network_host::headers_constructor_callback)- .length(0)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "Headers",+ network_host::headers_constructor_callback+ ))+ .length(0)+ .build(scope)}ConstructorKind::Request => {- v8::FunctionTemplate::builder(network_host::request_constructor_callback)- .length(1)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "Request",+ network_host::request_constructor_callback+ ))+ .length(1)+ .build(scope)}ConstructorKind::Response => {- v8::FunctionTemplate::builder(network_host::response_constructor_callback)- .length(0)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "Response",+ network_host::response_constructor_callback+ ))+ .length(0)+ .build(scope)}ConstructorKind::ProgressEvent => {- v8::FunctionTemplate::builder(network_host::progress_event_constructor_callback)- .length(1)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "ProgressEvent",+ network_host::progress_event_constructor_callback+ ))+ .length(1)+ .build(scope)}ConstructorKind::DomParser => {- v8::FunctionTemplate::builder(dom_parser::dom_parser_constructor_callback)- .length(0)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "DOMParser",+ dom_parser::dom_parser_constructor_callback+ ))+ .length(0)+ .build(scope)}ConstructorKind::TextEncoder => {- v8::FunctionTemplate::builder(text_encoder_constructor_callback)- .length(0)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "TextEncoder",+ text_encoder_constructor_callback+ ))+ .length(0)+ .build(scope)}ConstructorKind::TextDecoder => {- v8::FunctionTemplate::builder(text_decoder_constructor_callback)- .length(0)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "TextDecoder",+ text_decoder_constructor_callback+ ))+ .length(0)+ .build(scope)}ConstructorKind::ReadableStream => {v8::FunctionTemplate::builder(readable_stream_constructor_callback)@@ -317,16 +357,25 @@ pub(in crate::context_bootstrap) fn build_constructor_template<'s>(.length(1).build(scope)}- ConstructorKind::Blob => v8::FunctionTemplate::builder(blob::blob_constructor_callback)- .length(0)- .build(scope),+ ConstructorKind::Blob => v8::FunctionTemplate::builder(+ moli_webapi_declare::web_api_constructor!("Blob", blob::blob_constructor_callback),+ )+ .length(0)+ .build(scope),ConstructorKind::DataTransfer => {- v8::FunctionTemplate::builder(data_transfer_constructor_callback)- .length(0)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "DataTransfer",+ data_transfer_constructor_callback+ ))+ .length(0)+ .build(scope)}ConstructorKind::ImageData => {- let template = v8::FunctionTemplate::builder(image_data_constructor_callback)+ let template =+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "ImageData",+ image_data_constructor_callback+ )).length(2).build(scope);let instance = template.instance_template(scope);@@ -334,126 +383,196 @@ pub(in crate::context_bootstrap) fn build_constructor_template<'s>(template}ConstructorKind::OffscreenCanvas => {- v8::FunctionTemplate::builder(offscreen_canvas_constructor_callback)- .length(2)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "OffscreenCanvas",+ offscreen_canvas_constructor_callback+ ))+ .length(2)+ .build(scope)}ConstructorKind::CanvasRenderingContext2D => {- v8::FunctionTemplate::builder(canvas_rendering_context_2d_constructor_callback)- .length(0)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "CanvasRenderingContext2D",+ canvas_rendering_context_2d_constructor_callback+ ))+ .length(0)+ .build(scope)+ }+ ConstructorKind::OffscreenCanvasRenderingContext2D => {+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "OffscreenCanvasRenderingContext2D",+ offscreen_canvas_rendering_context_2d_constructor_callback+ ))+ .length(0)+ .build(scope)}- ConstructorKind::OffscreenCanvasRenderingContext2D => v8::FunctionTemplate::builder(- offscreen_canvas_rendering_context_2d_constructor_callback,- )- .length(0)- .build(scope),ConstructorKind::WebGLRenderingContext => {- v8::FunctionTemplate::builder(webgl_rendering_context_constructor_callback)- .length(0)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "WebGLRenderingContext",+ webgl_rendering_context_constructor_callback+ ))+ .length(0)+ .build(scope)}ConstructorKind::WebGlDebugRendererInfo => {- v8::FunctionTemplate::builder(webgl_debug_renderer_info_constructor_callback)- .length(0)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "WEBGL_debug_renderer_info",+ webgl_debug_renderer_info_constructor_callback+ ))+ .length(0)+ .build(scope)}ConstructorKind::WebGlLoseContext => {- v8::FunctionTemplate::builder(webgl_lose_context_constructor_callback)- .length(0)- .build(scope)- }- ConstructorKind::File => v8::FunctionTemplate::builder(file_constructor_callback)- .length(2)- .build(scope),- ConstructorKind::FileList => v8::FunctionTemplate::builder(file_list_constructor_callback)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "WEBGL_lose_context",+ webgl_lose_context_constructor_callback+ )).length(0)- .build(scope),+ .build(scope)+ }+ ConstructorKind::File => v8::FunctionTemplate::builder(+ moli_webapi_declare::web_api_constructor!("File", file_constructor_callback),+ )+ .length(2)+ .build(scope),+ ConstructorKind::FileList => v8::FunctionTemplate::builder(+ moli_webapi_declare::web_api_constructor!("FileList", file_list_constructor_callback),+ )+ .length(0)+ .build(scope),ConstructorKind::FileReader => {- v8::FunctionTemplate::builder(file_reader_constructor_callback)- .length(0)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "FileReader",+ file_reader_constructor_callback+ ))+ .length(0)+ .build(scope)}ConstructorKind::FileReaderSync => {- v8::FunctionTemplate::builder(file_reader_sync_constructor_callback)- .length(0)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "FileReaderSync",+ file_reader_sync_constructor_callback+ ))+ .length(0)+ .build(scope)}- ConstructorKind::DomRectReadOnly => v8::FunctionTemplate::builder(- super::super::dom_rect::dom_rect_readonly_constructor_callback,+ ConstructorKind::DomRectReadOnly => {+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "DOMRectReadOnly",+ super::super::dom_rect::dom_rect_readonly_constructor_callback+ ))+ .length(0)+ .build(scope)+ }+ ConstructorKind::DomRect => {+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "DOMRect",+ super::super::dom_rect::dom_rect_constructor_callback+ ))+ .length(0)+ .build(scope)+ }+ ConstructorKind::DomPoint => v8::FunctionTemplate::builder(+ moli_webapi_declare::web_api_constructor!("DOMPoint", dom_point_constructor_callback),).length(0).build(scope),- ConstructorKind::DomRect => {- v8::FunctionTemplate::builder(super::super::dom_rect::dom_rect_constructor_callback)- .length(0)- .build(scope)- }- ConstructorKind::DomPoint => v8::FunctionTemplate::builder(dom_point_constructor_callback)- .length(0)- .build(scope),ConstructorKind::DomMatrix => {v8::FunctionTemplate::builder(dom_matrix_constructor_callback).length(0).build(scope)}ConstructorKind::XmlSerializer => {- v8::FunctionTemplate::builder(xml_serializer::xml_serializer_constructor_callback)- .length(0)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "XMLSerializer",+ xml_serializer::xml_serializer_constructor_callback+ ))+ .length(0)+ .build(scope)}ConstructorKind::AbortController => {- v8::FunctionTemplate::builder(abort::abort_controller_constructor_callback)- .length(0)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "AbortController",+ abort::abort_controller_constructor_callback+ ))+ .length(0)+ .build(scope)}ConstructorKind::MessageChannel => {- v8::FunctionTemplate::builder(message_channel_constructor_callback)- .length(0)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "MessageChannel",+ message_channel_constructor_callback+ ))+ .length(0)+ .build(scope)}ConstructorKind::MessagePort => {- v8::FunctionTemplate::builder(message_port_constructor_callback)- .length(0)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "MessagePort",+ message_port_constructor_callback+ ))+ .length(0)+ .build(scope)}ConstructorKind::BroadcastChannel => {+ // The callback initializes both live and detached instances through+ // BroadcastChannelObjectDeclaration in their relevant realm.v8::FunctionTemplate::builder(broadcast_channel_constructor_callback).length(1).build(scope)}ConstructorKind::EventSource => {- v8::FunctionTemplate::builder(network_host::event_source_constructor_callback)- .length(1)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "EventSource",+ network_host::event_source_constructor_callback+ ))+ .length(1)+ .build(scope)}ConstructorKind::IdleDetector => {- v8::FunctionTemplate::builder(idle_detector_constructor_callback)- .length(0)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "IdleDetector",+ idle_detector_constructor_callback+ ))+ .length(0)+ .build(scope)}ConstructorKind::Notification => {- v8::FunctionTemplate::builder(notification_constructor_callback)- .length(1)- .build(scope)- }- ConstructorKind::WebSocket => v8::FunctionTemplate::builder(websocket_constructor_callback)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "Notification",+ notification_constructor_callback+ )).length(1)- .build(scope),+ .build(scope)+ }+ ConstructorKind::WebSocket => v8::FunctionTemplate::builder(+ moli_webapi_declare::web_api_constructor!("WebSocket", websocket_constructor_callback),+ )+ .length(1)+ .build(scope),ConstructorKind::RtcPeerConnection => {- v8::FunctionTemplate::builder(rtc_peer_connection_constructor_callback)- .length(0)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "RTCPeerConnection",+ rtc_peer_connection_constructor_callback+ ))+ .length(0)+ .build(scope)}ConstructorKind::RtcIceCandidate => {- v8::FunctionTemplate::builder(rtc_ice_candidate_constructor_callback)- .length(0)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "RTCIceCandidate",+ rtc_ice_candidate_constructor_callback+ ))+ .length(0)+ .build(scope)}ConstructorKind::RtcSessionDescription => {- v8::FunctionTemplate::builder(rtc_session_description_constructor_callback)- .length(1)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "RTCSessionDescription",+ rtc_session_description_constructor_callback+ ))+ .length(1)+ .build(scope)}ConstructorKind::Navigator| ConstructorKind::WorkerNavigator@@ -464,29 +583,44 @@ pub(in crate::context_bootstrap) fn build_constructor_template<'s>(.length(0).build(scope),ConstructorKind::SpeechSynthesisUtterance => {- v8::FunctionTemplate::builder(speech_synthesis_utterance_constructor_callback)- .length(0)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "SpeechSynthesisUtterance",+ speech_synthesis_utterance_constructor_callback+ ))+ .length(0)+ .build(scope)}ConstructorKind::WebSocketError => {- v8::FunctionTemplate::builder(websocket_error_constructor_callback)- .length(0)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "WebSocketError",+ websocket_error_constructor_callback+ ))+ .length(0)+ .build(scope)}ConstructorKind::WebSocketStream => {- v8::FunctionTemplate::builder(websocket_stream_constructor_callback)- .length(1)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "WebSocketStream",+ websocket_stream_constructor_callback+ ))+ .length(1)+ .build(scope)}ConstructorKind::ResizeObserver => {- v8::FunctionTemplate::builder(resize_observer_constructor_callback)- .length(1)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "ResizeObserver",+ resize_observer_constructor_callback+ ))+ .length(1)+ .build(scope)}ConstructorKind::PerformanceObserver => {- v8::FunctionTemplate::builder(performance_observer_constructor_callback)- .length(1)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "PerformanceObserver",+ performance_observer_constructor_callback+ ))+ .length(1)+ .build(scope)}ConstructorKind::Selection => {v8::FunctionTemplate::builder(illegal_constructor_callback).build(scope)@@ -499,28 +633,39 @@ pub(in crate::context_bootstrap) fn build_constructor_template<'s>(| ConstructorKind::TextTrack| ConstructorKind::TextTrackList| ConstructorKind::TextTrackCueList => {- v8::FunctionTemplate::builder(media_error_constructor_callback)- .length(0)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "TextTrackCueList",+ media_error_constructor_callback+ ))+ .length(0)+ .build(scope)}ConstructorKind::TrackEvent => {build_event_subclass_template(scope, EventSubclassKind::TrackEvent)}ConstructorKind::TextTrackCue => {- v8::FunctionTemplate::builder(text_track_cue_constructor_callback)- .length(0)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "TextTrackCue",+ text_track_cue_constructor_callback+ ))+ .length(0)+ .build(scope)}- ConstructorKind::VTTCue => v8::FunctionTemplate::builder(vtt_cue_constructor_callback)- .length(3)- .build(scope),+ ConstructorKind::VTTCue => v8::FunctionTemplate::builder(+ moli_webapi_declare::web_api_constructor!("VTTCue", vtt_cue_constructor_callback),+ )+ .length(3)+ .build(scope),ConstructorKind::PerformanceObserverEntryList => {v8::FunctionTemplate::builder(illegal_constructor_callback).build(scope)}ConstructorKind::PerformanceMark => {- v8::FunctionTemplate::builder(performance_mark_constructor_callback)- .length(1)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "PerformanceMark",+ performance_mark_constructor_callback+ ))+ .length(1)+ .build(scope)}ConstructorKind::PerformanceEntry| ConstructorKind::PerformanceNavigationTiming@@ -542,17 +687,25 @@ pub(in crate::context_bootstrap) fn build_constructor_template<'s>(v8::FunctionTemplate::builder(illegal_constructor_callback).build(scope)}ConstructorKind::MediaSource => {- v8::FunctionTemplate::builder(media_source_constructor_callback)- .length(0)- .build(scope)- }- ConstructorKind::Animation => v8::FunctionTemplate::builder(animation_constructor_callback)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "MediaSource",+ media_source_constructor_callback+ )).length(0)- .build(scope),+ .build(scope)+ }+ ConstructorKind::Animation => v8::FunctionTemplate::builder(+ moli_webapi_declare::web_api_constructor!("Animation", animation_constructor_callback),+ )+ .length(0)+ .build(scope),ConstructorKind::KeyframeEffect => {- v8::FunctionTemplate::builder(keyframe_effect_constructor_callback)- .length(2)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "KeyframeEffect",+ keyframe_effect_constructor_callback+ ))+ .length(2)+ .build(scope)}ConstructorKind::HtmlElement => {let Some(constructor_name) = v8_string(scope, spec.name) else {@@ -563,35 +716,59 @@ pub(in crate::context_bootstrap) fn build_constructor_template<'s>(.length(0).build(scope)}- ConstructorKind::Option => v8::FunctionTemplate::builder(option_constructor_callback)+ ConstructorKind::Option => {+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "HTMLOptionElement",+ option_constructor_callback+ )).length(0)- .build(scope),+ .build(scope)+ }ConstructorKind::MutationObserver => {- v8::FunctionTemplate::builder(observer_runtime::mutation_observer_constructor_callback)- .length(1)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "MutationObserver",+ observer_runtime::mutation_observer_constructor_callback+ ))+ .length(1)+ .build(scope)+ }+ ConstructorKind::IntersectionObserver => {+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "IntersectionObserver",+ observer_runtime::intersection_observer_constructor_callback+ ))+ .length(1)+ .build(scope)+ }+ ConstructorKind::IntersectionObserverEntry => {+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "IntersectionObserverEntry",+ observer_runtime::intersection_observer_entry_constructor_callback+ ))+ .length(1)+ .build(scope)}- ConstructorKind::IntersectionObserver => v8::FunctionTemplate::builder(- observer_runtime::intersection_observer_constructor_callback,- )- .length(1)- .build(scope),- ConstructorKind::IntersectionObserverEntry => v8::FunctionTemplate::builder(- observer_runtime::intersection_observer_entry_constructor_callback,- )- .length(1)- .build(scope),ConstructorKind::MutationRecord => {v8::FunctionTemplate::builder(illegal_constructor_callback).length(0).build(scope)}- ConstructorKind::Image => v8::FunctionTemplate::builder(image_constructor_callback)+ ConstructorKind::Image => {+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "HTMLImageElement",+ image_constructor_callback+ )).length(2)- .build(scope),- ConstructorKind::Audio => v8::FunctionTemplate::builder(audio_constructor_callback)+ .build(scope)+ }+ ConstructorKind::Audio => {+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "HTMLAudioElement",+ audio_constructor_callback+ )).length(1)- .build(scope),+ .build(scope)+ }ConstructorKind::StyleSheet| ConstructorKind::StyleSheetList| ConstructorKind::MediaList@@ -603,34 +780,51 @@ pub(in crate::context_bootstrap) fn build_constructor_template<'s>(.build(scope)}ConstructorKind::CssStyleSheet => {- v8::FunctionTemplate::builder(css_style_sheet_constructor_callback)- .length(0)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "CSSStyleSheet",+ css_style_sheet_constructor_callback+ ))+ .length(0)+ .build(scope)}ConstructorKind::CssKeywordValue => {- v8::FunctionTemplate::builder(css_keyword_value_constructor_callback)- .length(1)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "CSSKeywordValue",+ css_keyword_value_constructor_callback+ ))+ .length(1)+ .build(scope)}ConstructorKind::CssUnitValue => {- v8::FunctionTemplate::builder(css_unit_value_constructor_callback)- .length(2)- .build(scope)- }- ConstructorKind::FontFace => v8::FunctionTemplate::builder(font_face_constructor_callback)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "CSSUnitValue",+ css_unit_value_constructor_callback+ )).length(2)- .build(scope),+ .build(scope)+ }+ ConstructorKind::FontFace => v8::FunctionTemplate::builder(+ moli_webapi_declare::web_api_constructor!("FontFace", font_face_constructor_callback),+ )+ .length(2)+ .build(scope),ConstructorKind::FontFaceSet => {- v8::FunctionTemplate::builder(font_face_set_constructor_callback)- .length(0)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "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 => {- v8::FunctionTemplate::builder(offline_audio_context_constructor_callback)- .length(3)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "OfflineAudioContext",+ offline_audio_context_constructor_callback+ ))+ .length(3)+ .build(scope)}ConstructorKind::BaseAudioContext| ConstructorKind::AudioDestinationNode@@ -650,26 +844,39 @@ pub(in crate::context_bootstrap) fn build_constructor_template<'s>(ConstructorKind::Comment => v8::FunctionTemplate::builder(comment_constructor_callback).length(0).build(scope),- ConstructorKind::Touch => v8::FunctionTemplate::builder(touch_constructor_callback)- .length(1)- .build(scope),+ ConstructorKind::Touch => v8::FunctionTemplate::builder(+ moli_webapi_declare::web_api_constructor!("Touch", touch_constructor_callback),+ )+ .length(1)+ .build(scope),ConstructorKind::EventTarget => {- v8::FunctionTemplate::builder(event_target_constructor_callback)- .length(0)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "EventTarget",+ event_target_constructor_callback+ ))+ .length(0)+ .build(scope)}ConstructorKind::XPathEvaluator => {- v8::FunctionTemplate::builder(xpath_evaluator_constructor_callback)- .length(0)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "XPathEvaluator",+ xpath_evaluator_constructor_callback+ ))+ .length(0)+ .build(scope)}- ConstructorKind::Worker => v8::FunctionTemplate::builder(worker_constructor_callback)- .length(1)- .build(scope),+ ConstructorKind::Worker => v8::FunctionTemplate::builder(+ moli_webapi_declare::web_api_constructor!("Worker", worker_constructor_callback),+ )+ .length(1)+ .build(scope),ConstructorKind::SharedWorker => {- v8::FunctionTemplate::builder(shared_worker_constructor_callback)- .length(1)- .build(scope)+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "SharedWorker",+ shared_worker_constructor_callback+ ))+ .length(1)+ .build(scope)}ConstructorKind::AbstractRange => build_abstract_range_template(scope),ConstructorKind::Range => build_range_constructor_template(scope),@@ -680,11 +887,14 @@ pub(in crate::context_bootstrap) fn build_constructor_template<'s>(ConstructorKind::IndexedDb => v8::FunctionTemplate::builder(illegal_constructor_callback).length(0).build(scope),- ConstructorKind::IndexedDbVersionChangeEvent => v8::FunctionTemplate::builder(- crate::context_bootstrap::indexed_db::idb_version_change_event_constructor_callback,- )- .length(2)- .build(scope),+ ConstructorKind::IndexedDbVersionChangeEvent => {+ v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(+ "IDBVersionChangeEvent",+ crate::context_bootstrap::indexed_db::idb_version_change_event_constructor_callback+ ))+ .length(2)+ .build(scope)+ }};finalize_constructor_template(scope, spec, template)}diff --git a/moli-renderer-v8/src/context_bootstrap/css_runtime/highlights.rs b/moli-renderer-v8/src/context_bootstrap/css_runtime/highlights.rsindex 37bd5a436..ea3767172 100644--- a/moli-renderer-v8/src/context_bootstrap/css_runtime/highlights.rs+++ b/moli-renderer-v8/src/context_bootstrap/css_runtime/highlights.rs@@ -120,6 +120,8 @@ pub(super) fn build_highlight_runtime_state<'s>("failed to create the Highlight callback callability predicate"));};+ let initialize_identity = v8::Function::new(scope, initialize_highlight_identity_callback)+ .ok_or_else(|| anyhow!("failed to create Highlight identity initializer"))?;let Some(value) = initializer.call(scope,v8::undefined(scope).into(),@@ -127,12 +129,14 @@ pub(super) fn build_highlight_runtime_state<'s>(iterator_factory.into(),call_callback.into(),callback_is_callable.into(),+ initialize_identity.into(),],) else {return Err(anyhow!("failed to initialize Highlight runtime"));};let registry = v8::Local::<v8::Object>::try_from(value).map_err(|_| anyhow!("Highlight runtime did not return a registry object"))?;+ moli_webapi_declare::initialize_web_api_object(scope, registry, "HighlightRegistry")?;let highlight_constructor = highlight_constructor(scope, registry)?;let registry_constructor = highlight_registry_constructor(scope, registry)?;Ok(HighlightRuntimeState {@@ -142,6 +146,19 @@ pub(super) fn build_highlight_runtime_state<'s>(})}+fn initialize_highlight_identity_callback<'s>(+ scope: &mut v8::PinScope<'s, '_>,+ args: v8::FunctionCallbackArguments<'s>,+ _rv: v8::ReturnValue<'_, v8::Value>,+) {+ let Ok(object) = v8::Local::<v8::Object>::try_from(args.get(0)) else {+ return;+ };+ if let Err(error) = moli_webapi_declare::initialize_web_api_object(scope, object, "Highlight") {+ throw_type_error(scope, &error.to_string());+ }+}+fn highlight_iterator_factory_callback<'s>(scope: &mut v8::PinScope<'s, '_>,args: v8::FunctionCallbackArguments<'s>,@@ -176,6 +193,13 @@ fn highlight_iterator_factory_callback<'s>(throw_type_error(scope, "Failed to bind Highlight iterator prototype");return;}+ let interface = match kind {+ HighlightIteratorKind::Highlight => "Highlight Iterator",+ HighlightIteratorKind::Registry => "HighlightRegistry Iterator",+ };+ if moli_webapi_declare::initialize_web_api_object(scope, iterator, interface).is_err() {+ return;+ }rv.set(iterator.into());}@@ -292,7 +316,7 @@ fn highlight_registry_constructor<'s>(}const HIGHLIGHT_RUNTIME_SOURCE: &str = r#"-((createIterator, callCallback, callbackIsCallable) => {+((createIterator, callCallback, callbackIsCallable, initializeIdentity) => {// Generated maplike/setlike forEach performs an ordinary Call. The caller// supplies the Reflect.apply intrinsic captured during Window bootstrap;// reading callback.call would instead invoke a page-observable property.@@ -331,6 +355,7 @@ const HIGHLIGHT_RUNTIME_SOURCE: &str = r#"class Highlight {constructor(...ranges) {+ initializeIdentity(this);this[rangeSlot] = [];this[typeSlot] = 'highlight';this.priority = 0;diff --git a/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/install.rs b/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/install.rsindex 84403c844..b0d916fe3 100644--- a/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/install.rs+++ b/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/install.rs@@ -2,7 +2,7 @@ use super::*;use moli_webapi_declare::{WebApiFunctionTemplate, WebApiObject};#[derive(WebApiObject)]-#[webapi(interface = "Object")]+#[webapi(prototype = "Object", interface = "CSSFontFeatureValuesMap")]struct CssFontFeatureValuesMapObjectDeclaration<'s> {#[webapi(slot = CSS_FONT_FEATURE_VALUES_MAP_BACKING_SLOT)]backing: v8::Local<'s, v8::Map>,diff --git a/moli-renderer-v8/src/context_bootstrap/events/base.rs b/moli-renderer-v8/src/context_bootstrap/events/base.rsindex c623bf12a..896740d05 100644--- a/moli-renderer-v8/src/context_bootstrap/events/base.rs+++ b/moli-renderer-v8/src/context_bootstrap/events/base.rs@@ -31,7 +31,7 @@ struct InitializedEventHeaderDeclaration<'scope> {}#[derive(WebApiObject)]-#[webapi(interface = "Object", data_properties, enumerable)]+#[webapi(prototype = "Object", interface = "Event", data_properties, enumerable)]struct InitializedEventStateDeclaration {bubbles: bool,cancelable: bool,diff --git a/moli-renderer-v8/src/context_bootstrap/events/subclasses/constructor.rs b/moli-renderer-v8/src/context_bootstrap/events/subclasses/constructor.rsindex d9791bb69..74f4ad5fd 100644--- a/moli-renderer-v8/src/context_bootstrap/events/subclasses/constructor.rs+++ b/moli-renderer-v8/src/context_bootstrap/events/subclasses/constructor.rs@@ -168,6 +168,8 @@ fn event_subclass_constructor_callback<'s>(}}+ moli_webapi_declare::initialize_web_api_object(scope, event, kind.constructor_name())+ .expect("event primary interface should initialize");set_private_value(scope,event,diff --git a/moli-renderer-v8/src/context_bootstrap/events/subclasses/data.rs b/moli-renderer-v8/src/context_bootstrap/events/subclasses/data.rsindex ebac368ec..f534c3d8f 100644--- a/moli-renderer-v8/src/context_bootstrap/events/subclasses/data.rs+++ b/moli-renderer-v8/src/context_bootstrap/events/subclasses/data.rs@@ -73,7 +73,7 @@ struct NavigationInterceptOptionsMembers {}#[derive(WebApiObject)]-#[webapi(interface = "Object")]+#[webapi(prototype = "Object", interface = "NavigationPrecommitController")]struct PrecommitControllerDeclaration<'scope> {#[webapi(slot = PRECOMMIT_CONTROLLER_EVENT_SLOT)]event: v8::Local<'scope, v8::Object>,diff --git a/moli-renderer-v8/src/context_bootstrap/form_data_runtime/iterators.rs b/moli-renderer-v8/src/context_bootstrap/form_data_runtime/iterators.rsindex 8cbd7beba..5bd16b1d8 100644--- a/moli-renderer-v8/src/context_bootstrap/form_data_runtime/iterators.rs+++ b/moli-renderer-v8/src/context_bootstrap/form_data_runtime/iterators.rs@@ -12,7 +12,7 @@ const FORM_DATA_ITERATOR_KIND_SLOT: &str = "__moliFormDataIteratorKind";const FORM_DATA_ITERATOR_PROTOTYPE_SLOT: &str = "__moliFormDataIteratorPrototype";#[derive(WebApiObject)]-#[webapi(interface = "Object")]+#[webapi(prototype = "Object", interface = "FormData Iterator")]struct FormDataIteratorDeclaration<'scope> {#[webapi(slot = FORM_DATA_ITERATOR_TARGET_SLOT)]target: v8::Local<'scope, v8::Object>,diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/core/cursors/surface.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/core/cursors/surface.rsindex 087c33bc0..79cc57ce9 100644--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/core/cursors/surface.rs+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/core/cursors/surface.rs@@ -2,7 +2,12 @@ use super::*;use moli_webapi_declare::WebApiObject;#[derive(WebApiObject)]-#[webapi(interface = "Object", data_properties, enumerable)]+#[webapi(+ prototype = "Object",+ interface = "IDBCursor",+ data_properties,+ enumerable+)]struct IdbCursorObjectDeclaration<'scope> {source: v8::Local<'scope, v8::Object>,@@ -111,6 +116,12 @@ fn create_cursor_object_in_current_context<'s>(global_constructor_prototype(scope, "IDBCursorWithValue")?};let _ = cursor.set_prototype(scope, prototype.into());+ let interface = if key_only {+ "IDBCursor"+ } else {+ "IDBCursorWithValue"+ };+ moli_webapi_declare::initialize_web_api_object(scope, cursor, interface).ok()?;let storage_scope = indexed_db_typed_storage_scope(scope, request);let owner = indexed_db_typed_execution_owner(scope, request).expect("IDBCursor should inherit typed owner from request");diff --git a/moli-renderer-v8/src/context_bootstrap/indexed_db/core/objects/creation/request.rs b/moli-renderer-v8/src/context_bootstrap/indexed_db/core/objects/creation/request.rsindex 9643707c6..747d63533 100644--- a/moli-renderer-v8/src/context_bootstrap/indexed_db/core/objects/creation/request.rs+++ b/moli-renderer-v8/src/context_bootstrap/indexed_db/core/objects/creation/request.rs@@ -2,7 +2,7 @@ use super::*;use moli_webapi_declare::WebApiObject;#[derive(WebApiObject)]-#[webapi(interface = "Object")]+#[webapi(prototype = "Object", interface = "IDBRequest")]struct IdbRequestObjectDeclaration<'scope> {#[webapi(slot = INDEXED_DB_EVENT_LISTENERS_SLOT, init = "null_object")]event_listeners: (),@@ -30,7 +30,7 @@ struct IdbRequestObjectDeclaration<'scope> {}#[derive(Default, WebApiObject)]-#[webapi(interface = "Object")]+#[webapi(prototype = "Object", interface = "IDBOpenDBRequest")]struct IdbOpenRequestHandlersDeclaration {#[webapi(data_property, enumerable, init = "null")]onupgradeneeded: (),diff --git a/moli-renderer-v8/src/context_bootstrap/media_queries/events/simple_event_target/install.rs b/moli-renderer-v8/src/context_bootstrap/media_queries/events/simple_event_target/install.rsindex 619710d35..18ceb5b32 100644--- a/moli-renderer-v8/src/context_bootstrap/media_queries/events/simple_event_target/install.rs+++ b/moli-renderer-v8/src/context_bootstrap/media_queries/events/simple_event_target/install.rs@@ -3,7 +3,7 @@ use crate::util::set_private_value;use moli_webapi_declare::WebApiObject;#[derive(WebApiObject)]-#[webapi(interface = "Object", enumerable)]+#[webapi(interface = "EventTarget", prototype = "Object", enumerable)]struct SimpleEventTargetMethodsDeclaration<'scope> {#[webapi(method, length = 2, callback = simple_event_target_add_event_listener_callback)]add_event_listener: (),diff --git a/moli-renderer-v8/src/context_bootstrap/message_ports/state.rs b/moli-renderer-v8/src/context_bootstrap/message_ports/state.rsindex c25843c99..5d55e5428 100644--- a/moli-renderer-v8/src/context_bootstrap/message_ports/state.rs+++ b/moli-renderer-v8/src/context_bootstrap/message_ports/state.rs@@ -115,7 +115,7 @@ impl MessagePortRealmBinding {}#[derive(WebApiObject)]-#[webapi(interface = "Object")]+#[webapi(prototype = "Object", interface = "MessagePort")]struct MessagePortObjectDeclaration<'scope> {#[webapi(prototype)]prototype: v8::Local<'scope, v8::Object>,diff --git a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/navigator.rs b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/navigator.rsindex 1c7b3b93a..078c7cfeb 100644--- a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/navigator.rs+++ b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/navigator.rs@@ -291,7 +291,11 @@ struct PermissionStatusPrototypeDeclaration {}#[derive(Default, WebApiObject)]-#[webapi(interface = "Object")]+#[webapi(+ interface = "NetworkInformation",+ parent = "EventTarget",+ prototype = "Object"+)]struct NavigatorConnectionDeclaration {#[webapi(slot = NAVIGATOR_CONNECTION_BRAND_SLOT, init = true)]brand: (),diff --git a/moli-renderer-v8/src/context_bootstrap/opfs.rs b/moli-renderer-v8/src/context_bootstrap/opfs.rsindex 8f7fd111f..eae3c2bfc 100644--- a/moli-renderer-v8/src/context_bootstrap/opfs.rs+++ b/moli-renderer-v8/src/context_bootstrap/opfs.rs@@ -814,7 +814,7 @@ struct FileSystemWritableFileStreamPrototypeDeclaration {}#[derive(WebApiObject)]-#[webapi(interface = "Object")]+#[webapi(prototype = "Object", interface = "FileSystemWritableSink")]struct FileSystemWritableSinkObjectDeclaration {#[webapi(slot, name = FILE_SYSTEM_WRITABLE_SINK_BRAND_SLOT, constructor_default = true)]brand: bool,@@ -859,7 +859,10 @@ struct FileSystemSyncAccessHandlePrototypeDeclaration {}#[derive(WebApiObject)]-#[webapi(interface = "Object")]+#[webapi(+ prototype = "Object",+ interface = "FileSystemDirectoryHandle AsyncIterator"+)]struct FileSystemDirectoryIteratorObjectDeclaration {#[webapi(slot = FILE_SYSTEM_ITERATOR_BRAND_SLOT, init = true)]brand: (),diff --git a/moli-renderer-v8/src/context_bootstrap/performance_runtime/entries.rs b/moli-renderer-v8/src/context_bootstrap/performance_runtime/entries.rsindex 36858b971..ac1b36c83 100644--- a/moli-renderer-v8/src/context_bootstrap/performance_runtime/entries.rs+++ b/moli-renderer-v8/src/context_bootstrap/performance_runtime/entries.rs@@ -758,6 +758,8 @@ pub(super) fn create_performance_entry<'s>("resource" => "PerformanceResourceTiming",_ => "PerformanceEntry",};+ moli_webapi_declare::initialize_web_api_object(scope, entry, prototype_name)+ .expect("PerformanceEntry primary interface should initialize");if let Ok(prototype) =crate::context_bootstrap::ensure_intrinsic_interface_prototype(scope, prototype_name){diff --git a/moli-renderer-v8/src/context_bootstrap/performance_runtime/memory.rs b/moli-renderer-v8/src/context_bootstrap/performance_runtime/memory.rsindex b8dd39f7c..58138f2a4 100644--- a/moli-renderer-v8/src/context_bootstrap/performance_runtime/memory.rs+++ b/moli-renderer-v8/src/context_bootstrap/performance_runtime/memory.rs@@ -30,7 +30,7 @@ struct MemoryInfoPrototypeDeclaration {}#[derive(WebApiObject)]-#[webapi(interface = "Object")]+#[webapi(prototype = "Object", interface = "MemoryInfo")]struct MemoryInfoObjectDeclaration<'scope> {#[webapi(prototype)]prototype: Option<v8::Local<'scope, v8::Object>>,diff --git a/moli-renderer-v8/src/context_bootstrap/runtime_state.rs b/moli-renderer-v8/src/context_bootstrap/runtime_state.rsindex f1caed23c..3c93c55c9 100644--- a/moli-renderer-v8/src/context_bootstrap/runtime_state.rs+++ b/moli-renderer-v8/src/context_bootstrap/runtime_state.rs@@ -418,7 +418,7 @@ struct ConsoleObjectDeclaration {}#[derive(WebApiObject)]-#[webapi(interface = "Object", scope_lifetime = 'scope)]+#[webapi(interface = "Window", prototype = "Object")]struct WindowBootstrapGlobalSlotsDeclaration<'scope> {#[webapi(slot = WINDOW_CONSOLE_SLOT)]console: v8::Local<'scope, v8::Object>,diff --git a/moli-renderer-v8/src/context_bootstrap/streams/compression.rs b/moli-renderer-v8/src/context_bootstrap/streams/compression.rsindex 7700d43df..6abcb994b 100644--- a/moli-renderer-v8/src/context_bootstrap/streams/compression.rs+++ b/moli-renderer-v8/src/context_bootstrap/streams/compression.rs@@ -72,6 +72,13 @@ pub(in crate::context_bootstrap) fn compression_stream_constructor_callback<None,);set_private_value(scope, args.this(), TRANSFORM_SLOT, transform_stream.into());+ let interface = if DECOMPRESS {+ "DecompressionStream"+ } else {+ "CompressionStream"+ };+ moli_webapi_declare::initialize_web_api_object(scope, args.this(), interface)+ .expect("compression stream identity should initialize");set_private_value(scope,args.this(),diff --git a/moli-renderer-v8/src/context_bootstrap/streams/readable.rs b/moli-renderer-v8/src/context_bootstrap/streams/readable.rsindex 9e39cc219..d0df48218 100644--- a/moli-renderer-v8/src/context_bootstrap/streams/readable.rs+++ b/moli-renderer-v8/src/context_bootstrap/streams/readable.rs@@ -15,7 +15,7 @@ use moli_streams::readable::{AcquireReaderPlan, CancelEntryPlan, ReadableKind, Ruse moli_webapi_declare::WebApiObject;#[derive(WebApiObject)]-#[webapi(interface = "Object")]+#[webapi(prototype = "Object", interface = "ReadableStream AsyncIterator")]struct ReadableStreamAsyncIteratorObjectDeclaration<'scope> {#[webapi(slot = READABLE_STREAM_ITERATOR_READER_SLOT)]reader: v8::Local<'scope, v8::Object>,diff --git a/moli-renderer-v8/src/context_bootstrap/trusted_types.rs b/moli-renderer-v8/src/context_bootstrap/trusted_types.rsindex 2e01e76aa..7317e4f0a 100644--- a/moli-renderer-v8/src/context_bootstrap/trusted_types.rs+++ b/moli-renderer-v8/src/context_bootstrap/trusted_types.rs@@ -29,7 +29,7 @@ const TRUSTED_TYPES_CREATE_SCRIPT_SLOT: &str = "__moliTrustedTypesCreateScript";const TRUSTED_TYPES_CREATE_SCRIPT_URL_SLOT: &str = "__moliTrustedTypesCreateScriptURL";#[derive(Default, WebApiObject)]-#[webapi(interface = "Object")]+#[webapi(prototype = "Object", interface = "TrustedTypePolicyFactory")]struct TrustedTypesFactoryDeclaration {#[webapi(method, callback = trusted_types_create_policy_callback, length = 2)]create_policy: (),@@ -62,7 +62,7 @@ struct TrustedTypePrototypeDeclaration {}#[derive(WebApiObject)]-#[webapi(interface = "Object")]+#[webapi(prototype = "Object", interface = "TrustedTypePolicy")]struct TrustedTypePolicyDeclaration<'scope> {#[webapi(data_property)]name: v8::Local<'scope, v8::String>,@@ -675,6 +675,7 @@ fn build_trusted_type_object<'s>(TrustedTypeObjectDeclaration::new(v8str(scope, kind.as_slot_value()), value).initialize(scope, object).expect("TrustedType object declaration should initialize");+ moli_webapi_declare::initialize_web_api_object(scope, object, kind.constructor_name()).ok()?;let _ = object.set_prototype(scope, prototype.into());Some(object)}diff --git a/moli-renderer-v8/src/context_bootstrap/url_search_params_runtime/iterators.rs b/moli-renderer-v8/src/context_bootstrap/url_search_params_runtime/iterators.rsindex de8b1194c..9df647439 100644--- a/moli-renderer-v8/src/context_bootstrap/url_search_params_runtime/iterators.rs+++ b/moli-renderer-v8/src/context_bootstrap/url_search_params_runtime/iterators.rs@@ -15,7 +15,7 @@ const URL_SEARCH_PARAMS_ITERATOR_KIND_SLOT: &str = "__moliUrlSearchParamsIteratoconst URL_SEARCH_PARAMS_ITERATOR_PROTOTYPE_SLOT: &str = "__moliUrlSearchParamsIteratorPrototype";#[derive(WebApiObject)]-#[webapi(interface = "Object")]+#[webapi(prototype = "Object", interface = "URLSearchParams Iterator")]struct UrlSearchParamsIteratorDeclaration<'scope> {#[webapi(slot = URL_SEARCH_PARAMS_ITERATOR_TARGET_SLOT)]target: v8::Local<'scope, v8::Object>,diff --git a/moli-renderer-v8/src/context_bootstrap/web_storage/install.rs b/moli-renderer-v8/src/context_bootstrap/web_storage/install.rsindex 95b609a74..f5e02a462 100644--- a/moli-renderer-v8/src/context_bootstrap/web_storage/install.rs+++ b/moli-renderer-v8/src/context_bootstrap/web_storage/install.rs@@ -132,6 +132,7 @@ fn install_named_storage_runtime_state<'s>(if let Some(prototype) = prototype {let _ = storage.set_prototype(scope, prototype.into());}+ moli_webapi_declare::initialize_web_api_object(scope, storage, "Storage")?;set_private_value(scope, global, slot_name, storage.into());Ok(storage)}diff --git a/moli-renderer-v8/src/context_bootstrap/window_runtime/navigator.rs b/moli-renderer-v8/src/context_bootstrap/window_runtime/navigator.rsindex b01ad2dba..98a2cb572 100644--- a/moli-renderer-v8/src/context_bootstrap/window_runtime/navigator.rs+++ b/moli-renderer-v8/src/context_bootstrap/window_runtime/navigator.rs@@ -78,7 +78,11 @@ pub(in crate::context_bootstrap) const PERMISSIONS_BRAND_SLOT: &str = "__moliPerconst NAVIGATOR_BATTERY_STATUS_BRAND_SLOT: &str = "__moliBatteryStatusBrand";#[derive(Default, WebApiObject)]-#[webapi(interface = "Object", own_to_string_tag = "CacheStorage")]+#[webapi(+ prototype = "Object",+ interface = "CacheStorage",+ own_to_string_tag = "CacheStorage"+)]struct StorageBucketCacheStorageObjectDeclaration {#[webapi(slot = STORAGE_BUCKET_CACHE_STORAGE_BRAND_SLOT, init = true)]brand: (),@@ -115,7 +119,7 @@ struct StorageBucketCacheStorageObjectDeclaration {}#[derive(WebApiObject)]-#[webapi(interface = "Object", own_to_string_tag = "Cache")]+#[webapi(prototype = "Object", interface = "Cache", own_to_string_tag = "Cache")]struct StorageBucketCacheObjectDeclaration {#[webapi(slot = STORAGE_BUCKET_CACHE_BRAND_SLOT, init = true)]brand: (),@@ -272,7 +276,7 @@ struct StorageUsageDetailsObjectDeclaration {}#[derive(WebApiObject)]-#[webapi(interface = "Object", data_properties)]+#[webapi(prototype = "Object", interface = "BatteryManager", data_properties)]struct NavigatorBatteryStatusObjectDeclaration {#[webapi(slot = NAVIGATOR_BATTERY_STATUS_BRAND_SLOT, init = true)]brand: (),diff --git a/moli-renderer-v8/src/context_bootstrap/window_runtime/navigator/legacy_storage_quota.rs b/moli-renderer-v8/src/context_bootstrap/window_runtime/navigator/legacy_storage_quota.rsindex 41589b1d5..078c43b4d 100644--- a/moli-renderer-v8/src/context_bootstrap/window_runtime/navigator/legacy_storage_quota.rs+++ b/moli-renderer-v8/src/context_bootstrap/window_runtime/navigator/legacy_storage_quota.rs@@ -30,7 +30,7 @@ const TEMPORARY_STORAGE_TYPE: f64 = 0.0;const PERSISTENT_STORAGE_TYPE: f64 = 1.0;#[derive(Default, WebApiObject)]-#[webapi(interface = "Object")]+#[webapi(prototype = "Object", interface = "DeprecatedStorageQuota")]struct LegacyStorageQuotaObjectDeclaration {#[webapi(method,@@ -50,7 +50,7 @@ struct LegacyStorageQuotaObjectDeclaration {}#[derive(WebApiObject)]-#[webapi(interface = "Object")]+#[webapi(prototype = "Object", interface = "DeprecatedStorageInfo")]struct LegacyStorageInfoObjectDeclaration {#[webapi(data_property = "TEMPORARY", enumerable)]temporary: f64,diff --git a/moli-renderer-v8/src/native_bridge/abort.rs b/moli-renderer-v8/src/native_bridge/abort.rsindex 3c2abb2fa..49b18a012 100644--- a/moli-renderer-v8/src/native_bridge/abort.rs+++ b/moli-renderer-v8/src/native_bridge/abort.rs@@ -95,7 +95,7 @@ struct AbortLinkedMessagePortListener {}#[derive(WebApiObject)]-#[webapi(interface = "Object")]+#[webapi(prototype = "Object", interface = "AbortSignal")]struct AbortSignalObjectDeclaration<'scope> {#[webapi(prototype)]prototype: v8::Local<'scope, v8::Object>,diff --git a/moli-renderer-v8/src/native_bridge/bindings.rs b/moli-renderer-v8/src/native_bridge/bindings.rsindex c20047415..ac143bd5d 100644--- a/moli-renderer-v8/src/native_bridge/bindings.rs+++ b/moli-renderer-v8/src/native_bridge/bindings.rs@@ -277,6 +277,8 @@ impl NativeBridgeBindings {"`{prototype_name}` wrapper must expose its reflector identity field");}+ moli_webapi_declare::initialize_web_api_object(scope, wrapper, prototype_name)+ .expect("native wrapper identity should initialize");set_named_constructor_prototype(scope, wrapper, prototype_name);self.sync_wrapper_owner_realm_prototype(scope, host_ptr, &handle, wrapper);if matches!(wrapper_kind, WrapperKind::Node) {diff --git a/moli-renderer-v8/src/native_bridge/document/detached_objects/builders/documents.rs b/moli-renderer-v8/src/native_bridge/document/detached_objects/builders/documents.rsindex 667220035..df2698cb8 100644--- a/moli-renderer-v8/src/native_bridge/document/detached_objects/builders/documents.rs+++ b/moli-renderer-v8/src/native_bridge/document/detached_objects/builders/documents.rs@@ -46,9 +46,17 @@ fn new_detached_document_object<'s>(.or_else(|| {bridge_prototype_object(scope, detached_document_bridge_prototype_name(kind))})?;- DetachedDocumentObjectDeclaration::new(prototype, to_string_tag, v8::null(scope).into())- .bind(scope)- .ok()+ let document =+ DetachedDocumentObjectDeclaration::new(prototype, to_string_tag, v8::null(scope).into())+ .bind(scope)+ .ok()?;+ moli_webapi_declare::initialize_web_api_object(+ scope,+ document,+ detached_document_constructor_name(kind),+ )+ .ok()?;+ Some(document)}fn create_native_detached_document_handle_with_url(diff --git a/moli-renderer-v8/src/native_bridge/document/detached_objects/builders/elements.rs b/moli-renderer-v8/src/native_bridge/document/detached_objects/builders/elements.rsindex 3f5c90d12..44a53e9d9 100644--- a/moli-renderer-v8/src/native_bridge/document/detached_objects/builders/elements.rs+++ b/moli-renderer-v8/src/native_bridge/document/detached_objects/builders/elements.rs@@ -99,6 +99,7 @@ pub(in crate::native_bridge::document) fn generic_html_element_proxy<'s>(.bind(scope).ok()?;let proxy = v8::Proxy::new(scope, target, handler)?;+ moli_webapi_declare::register_web_api_proxy(scope, proxy).ok()?;let proxy: v8::Local<'s, v8::Value> = proxy.into();v8::Local::<v8::Object>::try_from(proxy).ok()}@@ -115,6 +116,7 @@ pub(in crate::native_bridge::document) fn select_html_element_proxy<'s>(.bind(scope).ok()?;let proxy = v8::Proxy::new(scope, target, handler)?;+ moli_webapi_declare::register_web_api_proxy(scope, proxy).ok()?;let proxy: v8::Local<'s, v8::Value> = proxy.into();v8::Local::<v8::Object>::try_from(proxy).ok()}@@ -490,6 +492,8 @@ pub(in crate::native_bridge::document) fn build_detached_element_object<'s>(} else {new_detached_object_with_prototype(scope, "__detachedElementPrototype", to_string_tag)?};+ let interface = to_string_tag.unwrap_or("Element");+ moli_webapi_declare::initialize_web_api_object(scope, object, interface).ok()?;let state = new_detached_state_object(scope, "element", 1, &node_name)?;let _ = state.set(scope,diff --git a/moli-renderer-v8/src/native_bridge/document/detached_objects/prototypes.rs b/moli-renderer-v8/src/native_bridge/document/detached_objects/prototypes.rsindex b27a3e40b..2f7eaaa6d 100644--- a/moli-renderer-v8/src/native_bridge/document/detached_objects/prototypes.rs+++ b/moli-renderer-v8/src/native_bridge/document/detached_objects/prototypes.rs@@ -129,10 +129,14 @@ pub(in crate::native_bridge::document) fn set_string_tag<'s>(pub(in crate::native_bridge::document) fn new_detached_object_with_prototype<'s>(scope: &mut v8::PinScope<'s, '_>,prototype_name: &str,- to_string_tag: Option<&str>,+ to_string_tag: Option<&'static str>,) -> Option<v8::Local<'s, v8::Object>> {let prototype = bridge_prototype_object(scope, prototype_name)?;- DetachedObjectWithPrototypeDeclaration::new(prototype, to_string_tag)+ let object = DetachedObjectWithPrototypeDeclaration::new(prototype, to_string_tag).bind(scope)- .ok()+ .ok()?;+ if let Some(interface) = to_string_tag {+ moli_webapi_declare::initialize_web_api_object(scope, object, interface).ok()?;+ }+ Some(object)}diff --git a/moli-renderer-v8/src/native_bridge/element/shadow_dom/internals.rs b/moli-renderer-v8/src/native_bridge/element/shadow_dom/internals.rsindex db1cca392..85afef726 100644--- a/moli-renderer-v8/src/native_bridge/element/shadow_dom/internals.rs+++ b/moli-renderer-v8/src/native_bridge/element/shadow_dom/internals.rs@@ -467,7 +467,7 @@ struct ValidityStateValidUpdateDeclaration {}#[derive(WebApiObject)]-#[webapi(interface = "Object")]+#[webapi(prototype = "Object", interface = "CustomStateSet")]struct CustomStateSetObjectDeclaration<'s> {#[webapi(slot = CUSTOM_STATE_SET_BACKING_SLOT)]backing: v8::Local<'s, v8::Set>,diff --git a/moli-renderer-v8/src/network_host/fetch_surface.rs b/moli-renderer-v8/src/network_host/fetch_surface.rsindex f4296242a..659697f88 100644--- a/moli-renderer-v8/src/network_host/fetch_surface.rs+++ b/moli-renderer-v8/src/network_host/fetch_surface.rs@@ -48,21 +48,21 @@ pub(crate) const RESPONSE_BODY_USED_SLOT: &str = "__lmResponseBodyUsed";const RESPONSE_BRAND_SLOT: &str = "__lmResponseBrand";#[derive(Default, WebApiObject)]-#[webapi(interface = "Object")]+#[webapi(prototype = "Object", interface = "Request")]struct RequestBrandDeclaration {#[webapi(slot = REQUEST_BRAND_SLOT, init = true)]brand: (),}#[derive(Default, WebApiObject)]-#[webapi(interface = "Object")]+#[webapi(prototype = "Object", interface = "Response")]struct ResponseBrandDeclaration {#[webapi(slot = RESPONSE_BRAND_SLOT, init = true)]brand: (),}#[derive(WebApiObject)]-#[webapi(interface = "Object", prototype = "Response")]+#[webapi(interface = "Response", prototype = "Response")]struct ResponseCloneShellDeclaration<'scope> {#[webapi(slot = RESPONSE_BODY_USED_SLOT, init = false)]body_used: (),diff --git a/moli-renderer-v8/src/network_host/headers/methods/iteration.rs b/moli-renderer-v8/src/network_host/headers/methods/iteration.rsindex a978f3bd9..97211927c 100644--- a/moli-renderer-v8/src/network_host/headers/methods/iteration.rs+++ b/moli-renderer-v8/src/network_host/headers/methods/iteration.rs@@ -42,7 +42,7 @@ struct HeadersIteratorResultDeclaration<'scope> {}#[derive(WebApiObject)]-#[webapi(interface = "Object")]+#[webapi(prototype = "Object", interface = "Headers Iterator")]struct HeadersIteratorDeclaration<'scope> {#[webapi(slot = HEADERS_ITERATOR_TARGET_SLOT)]target: v8::Local<'scope, v8::Object>,diff --git a/moli-renderer-v8/src/webidl_iterator.rs b/moli-renderer-v8/src/webidl_iterator.rsindex 5b88d2b5e..0f3449fe2 100644--- a/moli-renderer-v8/src/webidl_iterator.rs+++ b/moli-renderer-v8/src/webidl_iterator.rs@@ -36,6 +36,15 @@ pub(crate) enum SnapshotWebIdlIteratorKind {}impl SnapshotWebIdlIteratorKind {+ const fn interface(self) -> &'static str {+ match self {+ Self::StylePropertyMapReadOnly => "StylePropertyMapReadOnly Iterator",+ Self::EventCounts => "EventCounts Iterator",+ Self::FontFaceSet => "FontFaceSet Iterator",+ Self::CssFontFeatureValuesMap => "CSSFontFeatureValuesMap Iterator",+ }+ }+const fn prototype_slot(self) -> &'static str {match self {Self::StylePropertyMapReadOnly => STYLE_PROPERTY_MAP_ITERATOR_PROTOTYPE_SLOT,@@ -69,6 +78,13 @@ pub(crate) enum SetlikeWebIdlIteratorKind {}impl SetlikeWebIdlIteratorKind {+ const fn interface(self) -> &'static str {+ match self {+ Self::ViewTransitionTypeSet => "ViewTransitionTypeSet Iterator",+ Self::CustomStateSet => "CustomStateSet Iterator",+ }+ }+const fn prototype_slot(self) -> &'static str {match self {Self::ViewTransitionTypeSet => VIEW_TRANSITION_TYPE_SET_ITERATOR_PROTOTYPE_SLOT,@@ -299,6 +315,7 @@ pub(crate) fn new_snapshot_webidl_iterator<'s>(let iterator = SnapshotWebIdlIteratorDeclaration::new(values, 0).bind(scope).ok()?;+ moli_webapi_declare::initialize_web_api_object(scope, iterator, kind.interface()).ok()?;let prototype = snapshot_webidl_iterator_prototype(scope, kind)?;(iterator.set_prototype(scope, prototype.into()) == Some(true)).then_some(iterator)}@@ -313,6 +330,7 @@ pub(crate) fn new_setlike_webidl_iterator<'s>(let iterator = NativeCollectionWebIdlIteratorDeclaration::new(native_iterator, next).bind(scope).ok()?;+ moli_webapi_declare::initialize_web_api_object(scope, iterator, kind.interface()).ok()?;let prototype = setlike_webidl_iterator_prototype(scope, kind)?;(iterator.set_prototype(scope, prototype.into()) == Some(true)).then_some(iterator)}diff --git a/moli-renderer-v8/src/worker/abort.rs b/moli-renderer-v8/src/worker/abort.rsindex a929e392a..ddc38c2f2 100644--- a/moli-renderer-v8/src/worker/abort.rs+++ b/moli-renderer-v8/src/worker/abort.rs@@ -52,7 +52,7 @@ struct WorkerAbortLinkedMessagePortListener {}#[derive(WebApiObject)]-#[webapi(interface = "Object")]+#[webapi(prototype = "Object", interface = "AbortSignal")]struct WorkerAbortSignalObjectDeclaration<'scope> {#[webapi(prototype)]prototype: v8::Local<'scope, v8::Object>,diff --git a/moli-renderer-v8/src/worker/global_scope/mod.rs b/moli-renderer-v8/src/worker/global_scope/mod.rsindex e6c473d22..0c83ad35a 100644--- a/moli-renderer-v8/src/worker/global_scope/mod.rs+++ b/moli-renderer-v8/src/worker/global_scope/mod.rs@@ -271,7 +271,7 @@ struct WorkerConsoleObjectDeclaration {}#[derive(WebApiObject)]-#[webapi(interface = "Object")]+#[webapi(prototype = "Object", interface = "Performance")]struct WorkerPerformanceObjectDeclaration {#[webapi(data_property, readonly)]time_origin: f64,@@ -649,7 +649,7 @@ struct WorkerPrototypeTagDeclaration {}#[derive(WebApiObject)]-#[webapi(interface = "ServiceWorkerRegistration")]+#[webapi(interface = "ServiceWorkerRegistration", parent = "EventTarget")]struct ServiceWorkerGlobalRegistrationDeclaration<'scope> {#[webapi(data_property, readonly)]scope: String,@@ -703,7 +703,7 @@ struct ServiceWorkerGlobalRegistrationDeclaration<'scope> {}#[derive(WebApiObject)]-#[webapi(interface = "ServiceWorker")]+#[webapi(interface = "ServiceWorker", parent = "EventTarget")]struct ServiceWorkerGlobalServiceWorkerDeclaration {#[webapi(data_property = "scriptURL", readonly)]script_url: String,@@ -859,7 +859,7 @@ struct WorkerNavigationPreloadStateDeclaration {}#[derive(WebApiObject)]-#[webapi(interface = "Object")]+#[webapi(interface = "ExtendableEvent", parent = "Event", prototype = "Object")]struct InitializedExtendableEventStateDeclaration<'scope> {#[webapi(data_property = "type", enumerable)]event_type: String,@@ -893,7 +893,11 @@ struct InitializedExtendableEventStateDeclaration<'scope> {}#[derive(WebApiObject)]-#[webapi(interface = "Object")]+#[webapi(+ interface = "ExtendableMessageEvent",+ parent = "ExtendableEvent",+ prototype = "Object"+)]struct ExtendableMessageEventStateDeclaration<'scope> {#[webapi(data_property, enumerable)]data: v8::Local<'scope, v8::Value>,@@ -5475,6 +5479,21 @@ fn install_worker_global_scope_constructors<'s>(global: v8::Local<'s, v8::Object>,global_kind: &super::thread::WorkerGlobalKind,) -> Result<()> {+ moli_webapi_declare::register_web_api_interfaces(+ scope,+ [+ ("WorkerGlobalScope", Some("EventTarget")),+ ("DedicatedWorkerGlobalScope", Some("WorkerGlobalScope")),+ ("SharedWorkerGlobalScope", Some("WorkerGlobalScope")),+ ("ServiceWorkerGlobalScope", Some("WorkerGlobalScope")),+ ],+ )?;+ let interface = match global_kind {+ super::thread::WorkerGlobalKind::Dedicated { .. } => "DedicatedWorkerGlobalScope",+ super::thread::WorkerGlobalKind::Shared { .. } => "SharedWorkerGlobalScope",+ super::thread::WorkerGlobalKind::Service { .. } => "ServiceWorkerGlobalScope",+ };+ moli_webapi_declare::initialize_web_api_object(scope, global, interface)?;let worker_ctor = worker_scope_constructor(scope, "WorkerGlobalScope")?;let worker_proto = constructor_prototype(scope, worker_ctor, "WorkerGlobalScope")?;set_worker_to_string_tag(scope, worker_proto, "WorkerGlobalScope");diff --git a/moli-webapi-declare-derive/src/attrs.rs b/moli-webapi-declare-derive/src/attrs.rsindex 95fe1630c..747d725a7 100644--- a/moli-webapi-declare-derive/src/attrs.rs+++ b/moli-webapi-declare-derive/src/attrs.rs@@ -48,6 +48,7 @@ pub(crate) enum RenameRule {pub(crate) struct ObjectAttrs {pub(crate) receiver: Option<Path>,pub(crate) interface: Option<LitStr>,+ pub(crate) parent: Option<LitStr>,pub(crate) prototype: Option<LitStr>,pub(crate) own_to_string_tag: Option<LitStr>,pub(crate) fallback_to_string_tag: Option<LitStr>,@@ -210,6 +211,10 @@ pub(crate) fn parse_object_attrs(attrs: &[syn::Attribute]) -> Result<ObjectAttrslet mut parsed = ObjectAttrs::default();for attr in attrs.iter().filter(|attr| attr.path().is_ident("webapi")) {attr.parse_nested_meta(|meta| {+ if meta.path.is_ident("parent") {+ parsed.parent = Some(meta.value()?.parse()?);+ return Ok(());+ }if meta.path.is_ident("unbranded") {parsed.unbranded = true;return Ok(());diff --git a/moli-webapi-declare-derive/src/expand.rs b/moli-webapi-declare-derive/src/expand.rsindex 22fed9e6b..8144222fe 100644--- a/moli-webapi-declare-derive/src/expand.rs+++ b/moli-webapi-declare-derive/src/expand.rs@@ -40,7 +40,9 @@ pub(crate) fn expand_webapi_interface(ConstructorAttr::Illegal => {quote!(::moli_webapi_declare::illegal_constructor_callback)}- ConstructorAttr::Callback(callback) => quote!(#callback),+ ConstructorAttr::Callback(callback) => {+ quote!(::moli_webapi_declare::web_api_constructor!(#interface_name, #callback))+ }};let constructor_length = attrs.constructor_length.unwrap_or(0);let fields = named_fields(&input.data)?;@@ -156,7 +158,9 @@ pub(crate) fn expand_webapi_function_template(ConstructorAttr::Illegal => {quote!(::moli_webapi_declare::illegal_constructor_callback)}- ConstructorAttr::Callback(callback) => quote!(#callback),+ ConstructorAttr::Callback(callback) => {+ quote!(::moli_webapi_declare::web_api_constructor!(#template_name, #callback))+ }};let constructor_length = attrs.constructor_length.unwrap_or(0);let initialize_intrinsic_prototype_parent =@@ -364,7 +368,11 @@ pub(crate) fn expand_webapi_object(input: DeriveInput) -> Result<proc_macro2::To::moli_webapi_declare::initialize_web_api_object(scope, object, #interface)?;}});+ let register_parent = attrs.parent.as_ref().map(|parent| quote! {+ ::moli_webapi_declare::register_web_api_interfaces(scope, [(#interface, Some(#parent))])?;+ });let initialize_body = quote! {+ #register_parent#(#fields)*#initialize_brand::std::result::Result::Ok(())diff --git a/moli-webapi-declare/src/__private.rs b/moli-webapi-declare/src/__private.rsindex 616c2d005..95575b88b 100644--- a/moli-webapi-declare/src/__private.rs+++ b/moli-webapi-declare/src/__private.rs@@ -1,4 +1,6 @@-pub use crate::callback::{invoke_promise_callback, throw_illegal_invocation};+pub use crate::callback::{+ invoke_promise_callback, invoke_web_api_constructor, throw_illegal_invocation,+};pub use moli_v8_util::{global_constructor_prototype, v8_string, v8str};/// Complete description of one function installed bydiff --git a/moli-webapi-declare/src/brand.rs b/moli-webapi-declare/src/brand.rsindex c5c2bc49d..915024ec8 100644--- a/moli-webapi-declare/src/brand.rs+++ b/moli-webapi-declare/src/brand.rs@@ -29,6 +29,7 @@ struct TypeEntry {struct TypeRegistry {key: v8::Global<v8::Private>,+ proxy_key: v8::Global<v8::Private>,entries: Vec<TypeEntry>,names: HashMap<&'static str, usize>,}@@ -70,7 +71,9 @@ fn registry(scope: &mut v8::PinScope<'_, '_, ()>) -> Rc<RefCell<TypeRegistry>> {}let name = v8str(scope, "__moliWebApiType");let key = v8::Private::new(scope, Some(name));+ let proxy_key = v8::Private::new(scope, None);let registry = Rc::new(RefCell::new(TypeRegistry {+ proxy_key: v8::Global::new(scope, proxy_key),key: v8::Global::new(scope, key),entries: Vec::new(),names: HashMap::new(),@@ -139,10 +142,7 @@ fn object_type_id<'s>(object: v8::Local<'s, v8::Object>,registry: &Rc<RefCell<TypeRegistry>>,) -> Option<usize> {- // In particular, do not forward identity checks through Proxy traps.- if object.is_proxy() {- return None;- }+ let object = native_identity_target(scope, object, registry)?;let key = v8::Local::new(scope, ®istry.borrow().key);let value = object.get_private(scope, key)?;let id = v8::Local::<v8::Uint32>::try_from(value).ok()?.value() as usize;@@ -187,12 +187,14 @@ pub fn initialize_web_api_object<'s>(object: v8::Local<'s, v8::Object>,interface: &'static str,) -> Result<(), BindError> {- if interface == "Object" || object.is_proxy() {+ if interface == "Object" {return Err(BindError::new("platform identity requires a native interface instance",));}let registry = registry(scope);+ let object = native_identity_target(scope, object, ®istry)+ .ok_or_else(|| BindError::new("author proxies cannot carry platform identity"))?;let id = registry.borrow_mut().intern(interface);if let Some(existing) = object_type_id(scope, object, ®istry) {let registry = registry.borrow();@@ -216,3 +218,54 @@ pub fn initialize_web_api_object<'s>(}Ok(())}++// A small number of native DOM wrappers use a JS Proxy to implement named+// properties. Only the factory can register one: the private handler value+// must be the very same proxy, so author proxies never inherit this permission.+fn native_identity_target<'s>(+ scope: &mut v8::PinScope<'s, '_>,+ object: v8::Local<'s, v8::Object>,+ registry: &Rc<RefCell<TypeRegistry>>,+) -> Option<v8::Local<'s, v8::Object>> {+ let Ok(proxy) = v8::Local::<v8::Proxy>::try_from(object) else {+ return Some(object);+ };+ if proxy.is_revoked() {+ return None;+ }+ let handler = v8::Local::<v8::Object>::try_from(proxy.get_handler(scope)).ok()?;+ if handler.is_proxy() {+ return None;+ }+ let key = v8::Local::new(scope, ®istry.borrow().proxy_key);+ if !handler.get_private(scope, key)?.strict_equals(proxy.into()) {+ return None;+ }+ let target = v8::Local::<v8::Object>::try_from(proxy.get_target(scope)).ok()?;+ (!target.is_proxy()).then_some(target)+}++/// Registers a Proxy created by a native wrapper factory. The target must+/// already have native identity and the handler must be a private ordinary+/// object. This never invokes traps or accepts a Proxy wrapping another Proxy.+pub fn register_web_api_proxy<'s>(+ scope: &mut v8::PinScope<'s, '_>,+ proxy: v8::Local<'s, v8::Proxy>,+) -> Result<(), BindError> {+ let registry = registry(scope);+ let target = v8::Local::<v8::Object>::try_from(proxy.get_target(scope))+ .map_err(|_| BindError::new("native proxy requires an object target"))?;+ if target.is_proxy() || object_type_id(scope, target, ®istry).is_none() {+ return Err(BindError::new("native proxy requires a branded target"));+ }+ let handler = v8::Local::<v8::Object>::try_from(proxy.get_handler(scope))+ .map_err(|_| BindError::new("native proxy requires an object handler"))?;+ if handler.is_proxy() {+ return Err(BindError::new("native proxy requires an ordinary handler"));+ }+ let key = v8::Local::new(scope, ®istry.borrow().proxy_key);+ if handler.set_private(scope, key, proxy.into()) != Some(true) {+ return Err(BindError::new("failed to register native proxy"));+ }+ Ok(())+}diff --git a/moli-webapi-declare/src/callback.rs b/moli-webapi-declare/src/callback.rsindex aca15e2d3..0e31c1ee2 100644--- a/moli-webapi-declare/src/callback.rs+++ b/moli-webapi-declare/src/callback.rs@@ -6,6 +6,43 @@ type MemberCallback = for<'s, 'i> fn(v8::ReturnValue<'s>,);+/// Completes native constructor identity only after a successful callback.+/// Callback data, subclass receivers, and replacement return objects retain+/// their original V8 semantics.+#[doc(hidden)]+pub fn invoke_web_api_constructor<'s>(+ scope: &mut v8::PinScope<'s, '_>,+ args: v8::FunctionCallbackArguments<'s>,+ rv: v8::ReturnValue<'s>,+ interface: &'static str,+ callback: MemberCallback,+) {+ let receiver = args.this();+ let construct = args.is_construct_call();+ v8::tc_scope!(let scope, scope);+ callback(scope, args, rv);+ if scope.has_caught() {+ scope.rethrow();+ return;+ }+ if !scope.can_continue() {+ return;+ }+ let result = rv.get(scope);+ let object = match v8::Local::<v8::Object>::try_from(result) {+ Ok(object) => object,+ Err(_) if construct => receiver,+ Err(_) => return,+ };+ if let Err(error) = crate::initialize_web_api_object(scope, object, interface) {+ let message =+ v8::String::new(scope, &error.to_string()).expect("constructor identity error");+ let exception = v8::Exception::type_error(scope, message);+ scope.throw_exception(exception);+ scope.rethrow();+ }+}+pub fn throw_illegal_invocation(scope: &mut v8::PinScope<'_, '_>) {let message = v8str(scope, "Illegal invocation");let exception = v8::Exception::type_error(scope, message);diff --git a/moli-webapi-declare/src/lib.rs b/moli-webapi-declare/src/lib.rsindex e874792ab..4e4c586b6 100644--- a/moli-webapi-declare/src/lib.rs+++ b/moli-webapi-declare/src/lib.rs@@ -190,9 +190,26 @@ pub mod __private;pub use moli_webapi_declare_derive::{WebApiFunctionTemplate, WebApiInterface, WebApiObject};pub use v8;+/// Adapts a manual native constructor to the same identity initialization used+/// by interface derives. The interface must be a native declaration literal,+/// never a name obtained from `new.target` or another JavaScript property.+#[macro_export]+macro_rules! web_api_constructor {+ ($interface:literal, $callback:path) => {{+ fn __moli_native_constructor_adapter<'s>(+ scope: &mut $crate::v8::PinScope<'s, '_>,+ args: $crate::v8::FunctionCallbackArguments<'s>,+ rv: $crate::v8::ReturnValue<'s>,+ ) {+ $crate::__private::invoke_web_api_constructor(scope, args, rv, $interface, $callback);+ }+ __moli_native_constructor_adapter+ }};+}+pub use brand::{WebApiType, implements_interface, initialize_web_api_object, register_web_api_interfaces,- web_api_object_type,+ register_web_api_proxy, web_api_object_type,};pub use declaration::{diff --git a/moli-webapi-declare/tests/brand.rs b/moli-webapi-declare/tests/brand.rsindex 21252a532..d313c2bfc 100644--- a/moli-webapi-declare/tests/brand.rs+++ b/moli-webapi-declare/tests/brand.rs@@ -135,3 +135,86 @@ fn inheritance_registration_is_atomic_and_rejects_conflicts_and_cycles() {// A rejected batch has not left conflicting declarations behind.register_web_api_interfaces(scope, [("A", None), ("B", Some("A"))]).unwrap();}++#[derive(moli_webapi_declare::WebApiFunctionTemplate)]+#[webapi(name = "NativeConstructor", constructor_callback = native_constructor)]+struct NativeConstructor {}++fn native_constructor<'s>(+ scope: &mut v8::PinScope<'s, '_>,+ args: v8::FunctionCallbackArguments<'s>,+ mut rv: v8::ReturnValue<'s>,+) {+ let key = v8::String::new(scope, "capturedReceiver").unwrap();+ scope+ .get_current_context()+ .global(scope)+ .set(scope, key.into(), args.this().into());+ if args.get(0).is_true() {+ let message = v8::String::new(scope, "construction failed").unwrap();+ let exception = v8::Exception::type_error(scope, message);+ scope.throw_exception(exception);+ } else if args.get(0).is_object() {+ rv.set(args.get(0));+ }+}++#[test]+fn native_constructors_brand_successful_receivers_and_replacement_objects() {+ ensure_v8();+ let mut isolate = v8::Isolate::new(Default::default());+ let scope = pin!(v8::HandleScope::new(&mut isolate));+ let scope = &mut scope.init();+ let template = NativeConstructor::build(scope);+ let context = v8::Context::new(scope, Default::default());+ let scope = &mut v8::ContextScope::new(scope, context);+ let constructor = template.get_function(scope).unwrap();+ let key = v8::String::new(scope, "NativeConstructor").unwrap();+ context+ .global(scope)+ .set(scope, key.into(), constructor.into());+ for source in [+ "new NativeConstructor()",+ "new (class Derived extends NativeConstructor {})()",+ "new NativeConstructor({replacement: true})",+ "NativeConstructor({replacement: true})",+ ] {+ let object = v8::Local::<v8::Object>::try_from(eval(scope, source)).unwrap();+ assert!(+ implements_interface(scope, object, "NativeConstructor"),+ "{source}"+ );+ }+ let failed = eval(+ scope,+ "try { new NativeConstructor(true); } catch (e) { if (e.message !== 'construction failed') throw e; } capturedReceiver",+ );+ let failed = v8::Local::<v8::Object>::try_from(failed).unwrap();+ assert_eq!(web_api_object_type(scope, failed), None);+}++#[test]+fn only_explicitly_registered_native_proxies_share_target_identity() {+ ensure_v8();+ let mut isolate = v8::Isolate::new(Default::default());+ let scope = pin!(v8::HandleScope::new(&mut isolate));+ let scope = &mut scope.init();+ let context = v8::Context::new(scope, Default::default());+ let scope = &mut v8::ContextScope::new(scope, context);+ let target = Base::new().bind(scope).unwrap();+ let handler = v8::Object::new(scope);+ let native = v8::Proxy::new(scope, target, handler).unwrap();+ let native_object = v8::Local::<v8::Object>::from(native);+ assert_eq!(web_api_object_type(scope, native_object), None);+ moli_webapi_declare::register_web_api_proxy(scope, native).unwrap();+ assert!(implements_interface(scope, native_object, "TestBase"));+ initialize_web_api_object(scope, native_object, "TestBase").unwrap();+ let impostor = v8::Proxy::new(scope, target, handler).unwrap();+ assert_eq!(web_api_object_type(scope, impostor.into()), None);+ let outer_handler = v8::Object::new(scope);+ let outer = v8::Proxy::new(scope, native_object, outer_handler).unwrap();+ assert_eq!(web_api_object_type(scope, outer.into()), None);+ assert!(moli_webapi_declare::register_web_api_proxy(scope, outer).is_err());+ native.revoke();+ assert_eq!(web_api_object_type(scope, native_object), None);+}