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(forms): share bindings across native and detached wrappers
ldm0c2972bb9910e
diff --git a/moli-renderer-v8/src/context_bootstrap/assets/prototype_bindings.rs b/moli-renderer-v8/src/context_bootstrap/assets/prototype_bindings.rsindex 5bfe63fc3..cabf02ec2 100644--- a/moli-renderer-v8/src/context_bootstrap/assets/prototype_bindings.rs+++ b/moli-renderer-v8/src/context_bootstrap/assets/prototype_bindings.rs@@ -599,9 +599,6 @@ pub(super) fn install_constructor_template_bindings<'s>(scope, proto,);}- "HTMLFormElement" => {- element::install_html_form_element_prototype_bindings(scope, template);- }"HTMLSelectElement" => {element::install_html_select_element_prototype_bindings(scope, template);}diff --git a/moli-renderer-v8/src/native_bridge/bindings.rs b/moli-renderer-v8/src/native_bridge/bindings.rsindex 63a48a80e..fa829359a 100644--- a/moli-renderer-v8/src/native_bridge/bindings.rs+++ b/moli-renderer-v8/src/native_bridge/bindings.rs@@ -368,7 +368,7 @@ impl NativeBridgeBindings {open_object_template(&mut self.isolate_ptr, &self.bridge_template)}- fn node_wrapper_template(+ pub(super) fn node_wrapper_template(&mut self,prototype_name: &'static str,) -> Option<&v8::ObjectTemplate> {diff --git a/moli-renderer-v8/src/native_bridge/bridge/templates.rs b/moli-renderer-v8/src/native_bridge/bridge/templates.rsindex e1c3d275a..419f58cd6 100644--- a/moli-renderer-v8/src/native_bridge/bridge/templates.rs+++ b/moli-renderer-v8/src/native_bridge/bridge/templates.rs@@ -1,6 +1,13 @@use super::NativeDomBridge;impl NativeDomBridge {+ pub(crate) fn node_wrapper_template(+ &mut self,+ interface: &'static str,+ ) -> Option<&v8::ObjectTemplate> {+ self.bindings.node_wrapper_template(interface)+ }+pub(crate) fn collection_wrapper_template(&mut self) -> &v8::ObjectTemplate {self.bindings.collection_wrapper_template()}diff --git a/moli-renderer-v8/src/native_bridge/collections.rs b/moli-renderer-v8/src/native_bridge/collections.rsindex 888ff1fee..4aabe8fc9 100644--- a/moli-renderer-v8/src/native_bridge/collections.rs+++ b/moli-renderer-v8/src/native_bridge/collections.rs@@ -49,8 +49,8 @@ pub(in crate::native_bridge) use builders::{};pub(super) use builders::{build_collection_wrapper, build_live_child_node_list_for_node, build_live_collection_for_node,- build_live_collection_wrapper, build_live_html_children_collection_for_node,- build_node_list_from_handles,+ build_live_collection_wrapper, build_live_collection_wrapper_for_receiver,+ build_live_html_children_collection_for_node, build_node_list_from_handles,};pub(in crate::native_bridge) use shared::array_index_property_name;// Keep these re-exports visible only inside `collections`; sibling modules use `super::*`diff --git a/moli-renderer-v8/src/native_bridge/collections/builders.rs b/moli-renderer-v8/src/native_bridge/collections/builders.rsindex 10a0a9db4..1f80e97c9 100644--- a/moli-renderer-v8/src/native_bridge/collections/builders.rs+++ b/moli-renderer-v8/src/native_bridge/collections/builders.rs@@ -356,6 +356,22 @@ fn build_static_handle_node_list_wrapper<'s>(}/// Build a live-resolving NodeList or HTMLCollection V8 object (queries DOM on each access).+pub(in crate::native_bridge) fn build_live_collection_wrapper_for_receiver<'s>(+ scope: &mut v8::PinScope<'s, '_>,+ runtime_ptr: *mut JsContextHost,+ receiver: v8::Local<'_, v8::Object>,+ descriptor: LiveCollectionDescriptor,+) -> Option<v8::Local<'s, v8::Object>> {+ let context = receiver.get_creation_context(scope)?;+ let scope = &mut v8::ContextScope::new(scope, context);+ Some(build_live_collection_wrapper(+ scope,+ runtime_ptr,+ descriptor,+ ))+}++/// Build a live collection in the current realm, preserving that realm's cache.pub(in crate::native_bridge) fn build_live_collection_wrapper<'s>(scope: &mut v8::PinScope<'s, '_>,runtime_ptr: *mut JsContextHost,diff --git a/moli-renderer-v8/src/native_bridge/document.rs b/moli-renderer-v8/src/native_bridge/document.rsindex 141466f6d..b67c11694 100644--- a/moli-renderer-v8/src/native_bridge/document.rs+++ b/moli-renderer-v8/src/native_bridge/document.rs@@ -150,8 +150,7 @@ pub(crate) use detached_install::detached_iframe_current_content_document_handlepub(super) use detached_install::install_detached_bridge_methods;pub(in crate::native_bridge) use detached_install::{clear_detached_iframe_cached_context, clear_detached_iframe_cached_context_for_handle,- detached_form_owner_object, detached_form_reset_callback, detached_form_submit_callback,- detached_iframe_content_document, detached_iframe_content_window,+ detached_form_owner_object, detached_iframe_content_document, detached_iframe_content_window,detached_label_control_object, detached_shadow_root_for_host, set_detached_node_text_content,set_detached_text_replacement_value,};@@ -172,7 +171,6 @@ pub(crate) use detached_objects::{read_detached_native_has_attribute,remove_detached_native_attribute_appending_to_current_reaction_queue,remove_detached_native_attribute_ns_appending_to_current_reaction_queue,- with_detached_native_element_reaction_scope,write_detached_native_attribute_appending_to_current_reaction_queue,write_detached_native_attribute_ns_appending_to_current_reaction_queue,};diff --git a/moli-renderer-v8/src/native_bridge/document/detached_install.rs b/moli-renderer-v8/src/native_bridge/document/detached_install.rsindex 144b5b797..11f8f2675 100644--- a/moli-renderer-v8/src/native_bridge/document/detached_install.rs+++ b/moli-renderer-v8/src/native_bridge/document/detached_install.rs@@ -10,7 +10,6 @@ mod bridge_methods;mod instance_properties;pub(crate) use accessors::detached_iframe_current_content_document_handle;-pub(in crate::native_bridge::document) use accessors::*;pub(in crate::native_bridge) use accessors::{clear_detached_iframe_cached_context, clear_detached_iframe_cached_context_for_handle,detached_form_owner_object, detached_iframe_content_document, detached_iframe_content_window,@@ -18,9 +17,6 @@ pub(in crate::native_bridge) use accessors::{set_detached_text_replacement_value,};pub(in crate::native_bridge) use bridge_methods::install_detached_bridge_methods;-pub(in crate::native_bridge) use instance_properties::{- detached_form_reset_callback, detached_form_submit_callback,-};pub(in crate::native_bridge::document) use instance_properties::{install_detached_anchor_instance_properties,install_detached_character_data_instance_properties,@@ -28,10 +24,10 @@ pub(in crate::native_bridge::document) use instance_properties::{install_detached_document_type_instance_properties,install_detached_element_instance_properties,install_detached_form_associated_instance_properties,- install_detached_form_control_instance_properties, install_detached_form_instance_properties,- install_detached_iframe_instance_properties, install_detached_image_instance_properties,- install_detached_label_instance_properties, install_detached_node_core_instance_properties,- install_detached_option_instance_properties, install_detached_parent_node_instance_properties,+ install_detached_form_control_instance_properties, install_detached_iframe_instance_properties,+ install_detached_image_instance_properties, install_detached_label_instance_properties,+ install_detached_node_core_instance_properties, install_detached_option_instance_properties,+ install_detached_parent_node_instance_properties,install_detached_processing_instruction_instance_properties,install_detached_select_instance_properties,install_detached_text_replacement_instance_properties,diff --git a/moli-renderer-v8/src/native_bridge/document/detached_install/accessors.rs b/moli-renderer-v8/src/native_bridge/document/detached_install/accessors.rsindex 4c6abf110..457e640e8 100644--- a/moli-renderer-v8/src/native_bridge/document/detached_install/accessors.rs+++ b/moli-renderer-v8/src/native_bridge/document/detached_install/accessors.rs@@ -2,7 +2,6 @@ mod attributes;mod content;mod document_tree_scan;mod form_association;-mod iframe;mod iframe_content;mod iframe_content_cache;mod iframe_style;@@ -18,7 +17,6 @@ pub(in crate::native_bridge) use self::content::set_detached_text_replacement_vapub(in crate::native_bridge) use self::form_association::{detached_form_owner_object, detached_label_control_object,};-pub(in crate::native_bridge::document) use self::iframe::*;pub(in crate::native_bridge) use self::iframe_content::{detached_iframe_content_document, detached_iframe_content_window,};diff --git a/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/attributes.rs b/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/attributes.rsindex aa0aafbba..edc1b6c96 100644--- a/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/attributes.rs+++ b/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/attributes.rs@@ -1,8 +1,6 @@use super::super::super::{detached_attribute_name, detached_attributes_map, detached_map_get, detached_map_has,- detached_map_set, read_detached_native_attribute, read_detached_native_has_attribute,- with_detached_native_element_reaction_scope,- write_detached_native_attribute_appending_to_current_reaction_queue,+ read_detached_native_attribute, read_detached_native_has_attribute,};pub(super) fn detached_element_attribute_value<'s>(@@ -36,33 +34,3 @@ pub(super) fn detached_element_has_attribute<'s>(detached_attributes_map(scope, element).is_some_and(|attributes| detached_map_has(scope, attributes, &normalized))}--pub(super) fn set_detached_element_attribute_value<'s>(- scope: &mut v8::PinScope<'s, '_>,- element: v8::Local<'s, v8::Object>,- name: &str,- value: v8::Local<'s, v8::Value>,-) -> bool {- let normalized = detached_attribute_name(scope, element, name);- let Some(value) = value.to_string(scope) else {- return false;- };- let value = value.to_rust_string_lossy(scope);- if with_detached_native_element_reaction_scope(scope, element, |scope| {- write_detached_native_attribute_appending_to_current_reaction_queue(- scope,- element,- &normalized,- &value,- )- })- .unwrap_or(false)- {- return true;- }- let Some(attributes) = detached_attributes_map(scope, element) else {- return false;- };- detached_map_set(scope, attributes, &normalized, &value);- true-}diff --git a/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/iframe.rs b/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/iframe.rsdeleted file mode 100644index c5300d54c..000000000--- a/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/iframe.rs+++ /dev/null@@ -1,16 +0,0 @@-use crate::util::v8_string;--use super::attributes::set_detached_element_attribute_value;-use super::iframe_content_cache::clear_detached_iframe_cached_context;--pub(in crate::native_bridge::document) fn navigate_detached_iframe_to_url<'s>(- scope: &mut v8::PinScope<'s, '_>,- iframe: v8::Local<'s, v8::Object>,- url: &str,-) {- if let Some(url) = v8_string(scope, url)- && set_detached_element_attribute_value(scope, iframe, "src", url.into())- {- clear_detached_iframe_cached_context(scope, iframe);- }-}diff --git a/moli-renderer-v8/src/native_bridge/document/detached_install/instance_properties.rs b/moli-renderer-v8/src/native_bridge/document/detached_install/instance_properties.rsindex 73856c612..fb77c6a88 100644--- a/moli-renderer-v8/src/native_bridge/document/detached_install/instance_properties.rs+++ b/moli-renderer-v8/src/native_bridge/document/detached_install/instance_properties.rs@@ -3,7 +3,6 @@ use super::*;mod character_data;mod document;mod element;-mod element_form;mod node;pub(in crate::native_bridge::document) use character_data::{@@ -14,17 +13,11 @@ pub(in crate::native_bridge::document) use document::install_detached_document_ipub(in crate::native_bridge::document) use element::{install_detached_anchor_instance_properties, install_detached_element_instance_properties,install_detached_form_associated_instance_properties,- install_detached_iframe_instance_properties, install_detached_image_instance_properties,- install_detached_label_instance_properties, install_detached_option_instance_properties,- install_detached_select_instance_properties,+ install_detached_form_control_instance_properties, install_detached_iframe_instance_properties,+ install_detached_image_instance_properties, install_detached_label_instance_properties,+ install_detached_option_instance_properties, install_detached_select_instance_properties,install_detached_text_replacement_instance_properties,};-pub(in crate::native_bridge) use element_form::{- detached_form_reset_callback, detached_form_submit_callback,-};-pub(in crate::native_bridge::document) use element_form::{- install_detached_form_control_instance_properties, install_detached_form_instance_properties,-};pub(in crate::native_bridge::document) use node::{install_detached_document_type_instance_properties,install_detached_node_core_instance_properties,diff --git a/moli-renderer-v8/src/native_bridge/document/detached_install/instance_properties/element.rs b/moli-renderer-v8/src/native_bridge/document/detached_install/instance_properties/element.rsindex afa0f01a3..193dd042e 100644--- a/moli-renderer-v8/src/native_bridge/document/detached_install/instance_properties/element.rs+++ b/moli-renderer-v8/src/native_bridge/document/detached_install/instance_properties/element.rs@@ -194,3 +194,10 @@ pub(in crate::native_bridge::document) fn install_detached_iframe_instance_propelet _ = object.delete(scope, v8str(scope, name).into());}}++pub(in crate::native_bridge::document) fn install_detached_form_control_instance_properties<'s>(+ scope: &mut v8::PinScope<'s, '_>,+ object: v8::Local<'s, v8::Object>,+) {+ let _ = object.delete(scope, v8str(scope, "form").into());+}diff --git a/moli-renderer-v8/src/native_bridge/document/detached_install/instance_properties/element_form.rs b/moli-renderer-v8/src/native_bridge/document/detached_install/instance_properties/element_form.rsdeleted file mode 100644index 82945efde..000000000--- a/moli-renderer-v8/src/native_bridge/document/detached_install/instance_properties/element_form.rs+++ /dev/null@@ -1,379 +0,0 @@-use crate::document_runtime::DomHandle;-use crate::native_bridge::context_host::ChildBrowsingContextNavigationRequest;-use crate::util::{context_host_ptr_from_global_bridge, get_private_value, v8_string};-use moli_dom::forms::normalize_form_submission_newlines;-use moli_encoding::{form_submission_encoding, form_urlencoded_serialize_pairs};-use url::Url;--use super::*;--const CHILD_DOCUMENT_CONTEXT_HANDLE_SLOT: &str = "__lmChildDocumentContextHandle";--pub(in crate::native_bridge::document) fn install_detached_form_instance_properties(- scope: &mut v8::PinScope<'_, '_>,- object: v8::Local<'_, v8::Object>,-) {- for name in ["name", "elements", "length"] {- let _ = object.delete(scope, v8str(scope, name).into());- }- for name in ["submit", "reset"] {- let _ = object.delete(scope, v8str(scope, name).into());- }-}--pub(in crate::native_bridge) fn detached_form_submit_callback<'s>(- scope: &mut v8::PinScope<'s, '_>,- args: v8::FunctionCallbackArguments<'s>,- mut rv: v8::ReturnValue<'_, v8::Value>,-) {- let form = args.this();- let Some(runtime_ptr) = context_host_ptr_from_global_bridge(scope) else {- rv.set_undefined();- return;- };- let Some(form_handle) = detached_native_handle(scope, form) else {- rv.set_undefined();- return;- };- let Some(owner_document) = detached_owner_document_object(scope, form) else {- rv.set_undefined();- return;- };- let owner_urls =- detached_form_owner_urls(scope, runtime_ptr, owner_document).unwrap_or_else(|| {- let url = unsafe { &*runtime_ptr }.document_url().clone();- (url.clone(), url)- });- let action_attribute = read_detached_native_attribute(scope, form, "action");- let action = action_attribute- .as_deref()- .filter(|value| !value.is_empty())- .unwrap_or(owner_urls.0.as_str());- let method = read_detached_native_attribute(scope, form, "method").unwrap_or_default();- let Ok(mut url) = Url::parse(action).or_else(|_| owner_urls.1.join(action)) else {- rv.set_undefined();- return;- };- let submission_encoding =- detached_form_submission_encoding(scope, runtime_ptr, owner_document, form);- let mut entries = Vec::new();- for handle in detached_form_control_descendants(runtime_ptr, form_handle) {- let Some(control) = detached_native_object_for_handle(scope, runtime_ptr, handle) else {- continue;- };- let Some(name) = detached_control_submission_name(scope, control) else {- continue;- };- if name.is_empty() {- continue;- }- let mut value = detached_control_submission_value(scope, runtime_ptr, handle, control);- if moli_encoding::is_charset_sentinel_name(&name) {- value = submission_encoding.name().to_owned();- }- entries.push((- normalize_form_submission_newlines(&name),- normalize_form_submission_newlines(&value),- ));- }- let body = form_urlencoded_serialize_pairs(- entries- .iter()- .map(|(name, value)| (name.as_str(), value.as_str())),- submission_encoding,- );- if method.eq_ignore_ascii_case("post") {- let Some(child_handle) = detached_child_document_context_handle(scope, owner_document)- else {- rv.set_undefined();- return;- };- unsafe { &mut *runtime_ptr }.navigate_child_browsing_context_with_request(- scope,- child_handle,- ChildBrowsingContextNavigationRequest {- url,- method: "POST".to_owned(),- body: Some(body.into_bytes()),- request_headers: vec![(- "Content-Type".to_owned(),- "application/x-www-form-urlencoded".to_owned(),- )],- },- );- } else if let Some(target_iframe) =- detached_form_target_iframe(scope, runtime_ptr, owner_document, form)- {- url.set_query(Some(&body));- navigate_detached_iframe_to_url(scope, target_iframe, url.as_str());- let _ = crate::detached_event_target::dispatch_detached_simple_event(- scope,- target_iframe,- "load",- false,- false,- false,- );- } else {- let Some(child_handle) = detached_child_document_context_handle(scope, owner_document)- else {- rv.set_undefined();- return;- };- url.set_query(Some(&body));- let _ = unsafe { &mut *runtime_ptr }.navigate_child_browsing_context_to_url(- scope,- child_handle,- url.as_str(),- );- }- rv.set_undefined();-}--fn detached_child_document_context_handle<'s>(- scope: &mut v8::PinScope<'s, '_>,- owner_document: v8::Local<'s, v8::Object>,-) -> Option<DomHandle> {- let child_handle_value =- get_private_value(scope, owner_document, CHILD_DOCUMENT_CONTEXT_HANDLE_SLOT)?;- let child_handle_bigint = v8::Local::<v8::BigInt>::try_from(child_handle_value).ok()?;- let (child_handle_index, child_handle_lossless) = child_handle_bigint.u64_value();- child_handle_lossless.then(|| DomHandle::new(child_handle_index as usize))-}--fn detached_form_target_iframe<'s>(- scope: &mut v8::PinScope<'s, '_>,- runtime_ptr: *mut crate::native_bridge::JsContextHost,- owner_document: v8::Local<'s, v8::Object>,- form: v8::Local<'s, v8::Object>,-) -> Option<v8::Local<'s, v8::Object>> {- let target = read_detached_native_attribute(scope, form, "target")- .map(|value| value.trim().to_owned())- .filter(|value| !value.is_empty())?;- let document_handle = detached_native_handle(scope, owner_document)?;- let runtime = unsafe { &*runtime_ptr };- let target_handle = find_detached_iframe_by_name(runtime, document_handle, &target)?;- detached_native_object_for_handle(scope, runtime_ptr, target_handle)-}--fn detached_form_submission_encoding<'s>(- scope: &mut v8::PinScope<'s, '_>,- runtime_ptr: *mut JsContextHost,- _owner_document: v8::Local<'s, v8::Object>,- form: v8::Local<'s, v8::Object>,-) -> &'static encoding_rs::Encoding {- let accept_charset = read_detached_native_attribute(scope, form, "accept-charset");- form_submission_encoding(- accept_charset.as_deref(),- unsafe { &*runtime_ptr }.document_character_set(),- )-}--fn find_detached_iframe_by_name(- runtime: &crate::native_bridge::JsContextHost,- root: DomHandle,- target: &str,-) -> Option<DomHandle> {- let mut stack = vec![root];- while let Some(handle) = stack.pop() {- if runtime- .dom_host()- .node(handle)- .and_then(|node| node.as_element())- .is_some_and(|element| element.is_html_element("iframe"))- && runtime.dom_host().get_attribute(handle, "name").as_deref() == Some(target)- {- return Some(handle);- }- stack.extend(runtime.dom_host().child_handles_reversed(handle));- }- None-}--fn detached_form_owner_urls<'s>(- scope: &mut v8::PinScope<'s, '_>,- runtime_ptr: *mut JsContextHost,- owner_document: v8::Local<'s, v8::Object>,-) -> Option<(Url, Url)> {- let document_handle = detached_native_handle(scope, owner_document)?;- let runtime = unsafe { &*runtime_ptr };- runtime- .dom_host()- .node(document_handle)- .and_then(|node| node.as_document())- .map(|document| (document.url().clone(), document.base_url().clone()))-}--pub(in crate::native_bridge) fn detached_form_reset_callback<'s>(- scope: &mut v8::PinScope<'s, '_>,- args: v8::FunctionCallbackArguments<'s>,- mut rv: v8::ReturnValue<'_, v8::Value>,-) {- let form = args.this();- let Some(runtime_ptr) = context_host_ptr_from_global_bridge(scope) else {- rv.set_undefined();- return;- };- let Some(form_handle) = detached_native_handle(scope, form) else {- rv.set_undefined();- return;- };- let runtime = unsafe { &*runtime_ptr };- if runtime- .dom_host()- .node(form_handle)- .and_then(|node| node.as_element())- .is_none_or(|element| !element.is_html_form())- {- rv.set_undefined();- return;- }-- if let Some(event) =- crate::native_bridge::element::construct_simple_event(scope, "reset", true, true, false)- {- align_detached_form_reset_event_realm(scope, runtime_ptr, form, event);- if !crate::native_bridge::element::dispatch_public_event(- scope,- runtime_ptr,- form_handle,- event,- )- .allows_default()- {- rv.set_undefined();- return;- }- let _ = crate::native_bridge::element::reset_form_default_action(- scope,- runtime_ptr,- form_handle,- crate::native_bridge::element::FormAssociatedResetCallbackTiming::Sync,- );- }- rv.set_undefined();-}--fn align_detached_form_reset_event_realm<'s>(- scope: &mut v8::PinScope<'s, '_>,- _runtime_ptr: *mut crate::native_bridge::JsContextHost,- form: v8::Local<'s, v8::Object>,- event: v8::Local<'s, v8::Object>,-) {- let Some(owner_document) = detached_owner_document_object(scope, form) else {- crate::native_bridge::element::align_event_constructor_function_realm_with_target(- scope, event, form,- );- return;- };- let Some(default_view) = owner_document- .get(scope, v8str(scope, "defaultView").into())- .and_then(|value| v8::Local::<v8::Object>::try_from(value).ok())- else {- crate::native_bridge::element::align_event_constructor_function_realm_with_target(- scope, event, form,- );- return;- };- let Some(constructor_key) = v8_string(scope, "HTMLFormElement") else {- return;- };- let Some(constructor) = default_view- .get(scope, constructor_key.into())- .and_then(|value| v8::Local::<v8::Object>::try_from(value).ok())- else {- crate::native_bridge::element::align_event_constructor_function_realm_with_target(- scope, event, form,- );- return;- };- crate::native_bridge::element::align_event_constructor_function_realm_with_constructor(- scope,- event,- constructor,- );-}--fn detached_form_control_descendants(- runtime_ptr: *mut crate::native_bridge::JsContextHost,- form_handle: DomHandle,-) -> Vec<DomHandle> {- let mut controls = Vec::new();- let mut stack = unsafe { &*runtime_ptr }- .dom_host()- .child_handles_reversed(form_handle)- .collect::<Vec<_>>();- while let Some(handle) = stack.pop() {- if let Some(local_name) = unsafe { &*runtime_ptr }- .dom_host()- .node(handle)- .and_then(|node| node.as_element())- .map(|element| element.local_name())- && matches!(- local_name,- "button" | "fieldset" | "input" | "object" | "output" | "select" | "textarea"- )- {- controls.push(handle);- }- stack.extend(- unsafe { &*runtime_ptr }- .dom_host()- .child_handles_reversed(handle),- );- }- controls-}--fn detached_control_submission_name<'s>(- scope: &mut v8::PinScope<'s, '_>,- control: v8::Local<'s, v8::Object>,-) -> Option<String> {- read_detached_native_attribute(scope, control, "name").filter(|name| !name.is_empty())-}--fn detached_control_submission_value<'s>(- scope: &mut v8::PinScope<'s, '_>,- runtime_ptr: *mut crate::native_bridge::JsContextHost,- handle: DomHandle,- control: v8::Local<'s, v8::Object>,-) -> String {- let runtime = unsafe { &*runtime_ptr };- if let Some(element) = runtime- .dom_host()- .node(handle)- .and_then(|node| node.as_element())- {- if element.is_html_input() {- return crate::native_bridge::element::text_control_value(runtime, handle);- }- if element.is_html_textarea() {- let value = crate::native_bridge::element::text_control_value(runtime, handle);- if !element.input_value_dirty()- && value.is_empty()- && let Some(attribute_value) = element.attribute_ns("", "value")- {- return attribute_value.to_owned();- }- return value;- }- if element.is_html_button() {- return element- .attribute_ns("", "value")- .map(str::to_owned)- .unwrap_or_default();- }- }- control- .get(scope, v8str(scope, "value").into())- .and_then(|value| value.to_string(scope))- .map(|value| value.to_rust_string_lossy(scope))- .unwrap_or_default()-}--pub(in crate::native_bridge::document) fn install_detached_form_control_instance_properties<'s>(- scope: &mut v8::PinScope<'s, '_>,- object: v8::Local<'s, v8::Object>,-) {- let _ = object.delete(scope, v8str(scope, "form").into());-}diff --git a/moli-renderer-v8/src/native_bridge/document/detached_objects.rs b/moli-renderer-v8/src/native_bridge/document/detached_objects.rsindex c5b99dd2b..4733eef29 100644--- a/moli-renderer-v8/src/native_bridge/document/detached_objects.rs+++ b/moli-renderer-v8/src/native_bridge/document/detached_objects.rs@@ -42,7 +42,6 @@ pub(crate) use self::state_tree::{read_detached_native_has_attribute,remove_detached_native_attribute_appending_to_current_reaction_queue,remove_detached_native_attribute_ns_appending_to_current_reaction_queue,- with_detached_native_element_reaction_scope,write_detached_native_attribute_appending_to_current_reaction_queue,write_detached_native_attribute_ns_appending_to_current_reaction_queue,};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 c6d3981c9..443a56d2e 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@@ -12,9 +12,9 @@ use crate::{install_detached_anchor_instance_properties,install_detached_form_associated_instance_properties,install_detached_form_control_instance_properties,- install_detached_form_instance_properties, install_detached_iframe_instance_properties,- install_detached_image_instance_properties, install_detached_label_instance_properties,- install_detached_option_instance_properties, install_detached_select_instance_properties,+ install_detached_iframe_instance_properties, install_detached_image_instance_properties,+ install_detached_label_instance_properties, install_detached_option_instance_properties,+ install_detached_select_instance_properties,install_detached_text_replacement_instance_properties,},};@@ -489,9 +489,13 @@ pub(in crate::native_bridge::document) fn build_detached_element_object<'s>({let declaration = DetachedElementObjectDeclaration::new(proto, to_string_tag);if html_interface_like && local_name == "form" {- let template = v8::ObjectTemplate::new(scope);- crate::native_bridge::element::install_form_property_handlers(template);- let object = template.new_instance(scope)?;+ // Reuse the native interface template, including its property handlers.+ // The detached identity is attached below; the reflector slot stays empty.+ let runtime_ptr = context_host_ptr_from_global_bridge(scope)?;+ let object = unsafe { &mut *runtime_ptr }+ .native_bridge_mut()+ .node_wrapper_template("HTMLFormElement")?+ .new_instance(scope)?;declaration.bind_into(scope, object).ok()?;object} else {@@ -580,9 +584,11 @@ pub(in crate::native_bridge::document) fn build_detached_element_object<'s>(define_detached_native_handle(scope, object, handle);native_handle = Some((runtime_ptr, handle));}- install_detached_element_instance_properties(scope, object);+ if !(html_interface_like && local_name == "form") {+ install_detached_element_instance_properties(scope, object);+ remove_detached_element_instance_selector_matching_methods(scope, object);+ }copy_detached_element_bridge_members(scope, object);- remove_detached_element_instance_selector_matching_methods(scope, object);if html_interface_like && matches!(local_name.as_str(), "a" | "area") {install_detached_anchor_instance_properties(scope, object);}@@ -609,9 +615,6 @@ pub(in crate::native_bridge::document) fn build_detached_element_object<'s>(if html_like && local_name == "iframe" {install_detached_iframe_instance_properties(scope, object);}- if html_like && local_name == "form" {- install_detached_form_instance_properties(scope, object);- }if html_like&& matches!(local_name.as_str(),diff --git a/moli-renderer-v8/src/native_bridge/document/detached_objects/mutation.rs b/moli-renderer-v8/src/native_bridge/document/detached_objects/mutation.rsindex 0646764e9..3b6b3015f 100644--- a/moli-renderer-v8/src/native_bridge/document/detached_objects/mutation.rs+++ b/moli-renderer-v8/src/native_bridge/document/detached_objects/mutation.rs@@ -4,8 +4,8 @@ use crate::{install_detached_anchor_instance_properties,install_detached_form_associated_instance_properties,install_detached_form_control_instance_properties,- install_detached_form_instance_properties, install_detached_iframe_instance_properties,- install_detached_option_instance_properties, install_detached_select_instance_properties,+ install_detached_iframe_instance_properties, install_detached_option_instance_properties,+ install_detached_select_instance_properties,install_detached_text_replacement_instance_properties,},native_bridge::node::{remove_child_in_reaction_scope, remove_child_to_current_reaction_queue},@@ -486,7 +486,14 @@ fn adopt_live_node_as_detached_with_parent<'s>(// custom-element constructors that later receive the proxy through// the construction stack can still read/write id, style, and the// other own detached element surface.- install_detached_element_instance_properties(scope, node);+ let uses_native_form_bindings =+ local_name == "form" && raw_namespace_uri.as_deref() == Some(XHTML_NS);+ // Native form templates already keep interface members on prototypes.+ // Rebinding must preserve the user's own properties on the existing object.+ if !uses_native_form_bindings {+ install_detached_element_instance_properties(scope, node);+ remove_detached_element_instance_selector_matching_methods(scope, node);+ }if document_kind == "html"&& raw_namespace_uri.as_deref()@@ -513,7 +520,6 @@ fn adopt_live_node_as_detached_with_parent<'s>(set_string_tag(scope, node, "Element");}copy_detached_element_bridge_members(scope, node);- remove_detached_element_instance_selector_matching_methods(scope, node);if document_kind == "html" && matches!(local_name.as_str(), "a" | "area") {install_detached_anchor_instance_properties(scope, node);}@@ -526,9 +532,6 @@ fn adopt_live_node_as_detached_with_parent<'s>(if document_kind == "html" && local_name == "iframe" {install_detached_iframe_instance_properties(scope, node);}- if document_kind == "html" && local_name == "form" {- install_detached_form_instance_properties(scope, node);- }if document_kind == "html"&& matches!(local_name.as_str(),diff --git a/moli-renderer-v8/src/native_bridge/document/detached_objects/state_tree.rs b/moli-renderer-v8/src/native_bridge/document/detached_objects/state_tree.rsindex 97af9c4ec..3adbaec1e 100644--- a/moli-renderer-v8/src/native_bridge/document/detached_objects/state_tree.rs+++ b/moli-renderer-v8/src/native_bridge/document/detached_objects/state_tree.rs@@ -944,19 +944,6 @@ pub(in crate::native_bridge::document) fn detached_native_element_runtime_and_haSome((runtime_ptr, handle))}-pub(crate) fn with_detached_native_element_reaction_scope<'scope, 'pin, R>(- scope: &mut v8::PinScope<'scope, 'pin>,- element: v8::Local<'scope, v8::Object>,- op: impl FnOnce(&mut v8::PinScope<'scope, 'pin>) -> R,-) -> Option<R> {- let (runtime_ptr, _) = detached_native_element_runtime_and_handle(scope, element)?;- Some(custom_elements::with_custom_element_reaction_scope(- scope,- runtime_ptr,- op,- ))-}-pub(crate) fn read_detached_native_attribute<'s>(scope: &mut v8::PinScope<'s, '_>,element: v8::Local<'s, v8::Object>,diff --git a/moli-renderer-v8/src/native_bridge/element.rs b/moli-renderer-v8/src/native_bridge/element.rsindex a515eb59b..2121bd02a 100644--- a/moli-renderer-v8/src/native_bridge/element.rs+++ b/moli-renderer-v8/src/native_bridge/element.rs@@ -145,8 +145,7 @@ use self::table_elements::*;mod shadow_template;pub(in crate::native_bridge) use self::base_prototypes::BODY_LEGACY_PROTOTYPE_ACCESSORS;pub(crate) use self::base_prototypes::{- computed_style_property_for_handle, install_html_form_element_prototype_bindings,- install_html_select_element_prototype_bindings,+ computed_style_property_for_handle, install_html_select_element_prototype_bindings,};use self::shadow_template::*;@@ -292,14 +291,6 @@ pub(crate) use focus::{};use focus::{is_disabled_form_control, is_focusable};pub(super) use focus::{node_blur_callback, node_focus_callback};-pub(in crate::native_bridge) use forms::{- FormAssociatedResetCallbackTiming, reset_form_default_action, resize_select_options,- select_add_insertion_point, select_options_resize_target,-};-pub(crate) use forms::{- align_event_constructor_function_realm_with_constructor,- align_event_constructor_function_realm_with_target,-};pub(super) use forms::{button_command_for_element_getter_function, button_command_for_element_setter_function,button_disabled_getter_function, button_disabled_setter_function,@@ -410,6 +401,9 @@ pub(crate) use forms::{text_control_set_selection_range_internal,text_control_set_selection_range_with_direction_internal, text_control_value,};+pub(in crate::native_bridge) use forms::{+ resize_select_options, select_add_insertion_point, select_options_resize_target,+};use rendered_state::{node_check_visibility_callback, node_current_css_zoom_getter_function};pub use geometry::ClientRect;@@ -657,8 +651,7 @@ use stylesheets::{style_blocking_setter_function, style_disabled_getter_function, style_disabled_setter_function,};pub(super) use template_install::{- install_form_property_handlers, install_specialized_instance_properties,- install_specialized_template,+ install_specialized_instance_properties, install_specialized_template,};pub(super) use tree_mutation::{node_insert_adjacent_element_callback, node_insert_adjacent_html_callback,@@ -1578,12 +1571,7 @@ pub(crate) fn install_element_template_bindings<'s>("HTMLObjectElement" => install!(HtmlObjectElementPrototypeDeclaration),"HTMLLabelElement" => install!(HtmlLabelElementPrototypeDeclaration),"HTMLFormElement" => {- install!(HtmlFormElementPrototypeAccessorsDeclaration);- install_html_rel_template_bindings(- scope,- prototype,- ElementReflectionInterface::HtmlFormElement,- );+ install_html_form_element_prototype_bindings(scope, prototype);}"HTMLMediaElement" => install!(HtmlMediaElementPrototypeDeclaration,diff --git a/moli-renderer-v8/src/native_bridge/element/base_prototypes.rs b/moli-renderer-v8/src/native_bridge/element/base_prototypes.rsindex 826b8d577..4309bb966 100644--- a/moli-renderer-v8/src/native_bridge/element/base_prototypes.rs+++ b/moli-renderer-v8/src/native_bridge/element/base_prototypes.rs@@ -1,26 +1,5 @@use super::*;-#[derive(WebApiFunctionTemplate)]-#[webapi(interface = web_api_interfaces::HTMLFormElement, enumerable)]-struct HtmlFormElementTemplateMethodsDeclaration {- #[webapi(- intrinsic_data_property = v8::Intrinsic::ArrayProtoValues,- symbol = "iterator"- )]- iterator: (),-- #[webapi(method = "requestSubmit", length = 1, callback = form_request_submit_callback)]- request_submit: (),- #[webapi(method, length = 0, callback = form_submit_callback)]- submit: (),- #[webapi(method, length = 0, callback = form_reset_callback)]- reset: (),- #[webapi(method = "checkValidity", length = 0, callback = form_check_validity_callback)]- check_validity: (),- #[webapi(method = "reportValidity", length = 0, callback = form_report_validity_callback)]- report_validity: (),-}-#[derive(WebApiFunctionTemplate)]#[webapi(interface = web_api_interfaces::HTMLSelectElement)]struct HtmlSelectElementIndexedPropertiesDeclaration {@@ -31,14 +10,6 @@ struct HtmlSelectElementIndexedPropertiesDeclaration {iterator: (),}-pub(crate) fn install_html_form_element_prototype_bindings(- scope: &mut v8::PinScope<'_, '_, ()>,- template: v8::Local<'_, v8::FunctionTemplate>,-) {- let proto = template.prototype_template(scope);- HtmlFormElementTemplateMethodsDeclaration::initialize_prototype_template(scope, proto);-}-pub(crate) fn install_html_select_element_prototype_bindings(scope: &mut v8::PinScope<'_, '_, ()>,template: v8::Local<'_, v8::FunctionTemplate>,diff --git a/moli-renderer-v8/src/native_bridge/element/form_methods.rs b/moli-renderer-v8/src/native_bridge/element/form_methods.rsindex 195e0b438..a08b339f2 100644--- a/moli-renderer-v8/src/native_bridge/element/form_methods.rs+++ b/moli-renderer-v8/src/native_bridge/element/form_methods.rs@@ -2,7 +2,28 @@ use super::*;#[derive(WebApiFunctionTemplate)]#[webapi(interface = web_api_interfaces::HTMLFormElement, enumerable)]-pub(super) struct HtmlFormElementPrototypeAccessorsDeclaration {+struct HtmlFormElementTemplateMethodsDeclaration {+ #[webapi(+ intrinsic_data_property = v8::Intrinsic::ArrayProtoValues,+ symbol = "iterator"+ )]+ iterator: (),++ #[webapi(method = "requestSubmit", length = 1, callback = form_request_submit_callback)]+ request_submit: (),+ #[webapi(method, length = 0, callback = form_submit_callback)]+ submit: (),+ #[webapi(method, length = 0, callback = form_reset_callback)]+ reset: (),+ #[webapi(method = "checkValidity", length = 0, callback = form_check_validity_callback)]+ check_validity: (),+ #[webapi(method = "reportValidity", length = 0, callback = form_report_validity_callback)]+ report_validity: (),+}++#[derive(WebApiFunctionTemplate)]+#[webapi(interface = web_api_interfaces::HTMLFormElement, enumerable)]+struct HtmlFormElementPrototypeAccessorsDeclaration {#[webapi(accessor_property,getter = form_action_getter_function,@@ -233,3 +254,16 @@ pub(super) struct FormControlValidationPrototypeAccessorsDeclaration {#[webapi(accessor_property, getter = control_will_validate_getter_function)]will_validate: (),}++pub(super) fn install_html_form_element_prototype_bindings<'s>(+ scope: &mut v8::PinScope<'s, '_, ()>,+ prototype: v8::Local<'s, v8::ObjectTemplate>,+) {+ HtmlFormElementTemplateMethodsDeclaration::initialize_prototype_template(scope, prototype);+ HtmlFormElementPrototypeAccessorsDeclaration::initialize_prototype_template(scope, prototype);+ install_html_rel_template_bindings(+ scope,+ prototype,+ ElementReflectionInterface::HtmlFormElement,+ );+}diff --git a/moli-renderer-v8/src/native_bridge/element/forms.rs b/moli-renderer-v8/src/native_bridge/element/forms.rsindex 56f6bdc08..9097ffbe9 100644--- a/moli-renderer-v8/src/native_bridge/element/forms.rs+++ b/moli-renderer-v8/src/native_bridge/element/forms.rs@@ -17,8 +17,7 @@ use super::super::{append_child_in_reaction_scope, append_child_to_current_reaction_queue,current_or_live_delegate_node_arg_handle, insert_before_in_reaction_scope,insert_before_to_current_reaction_queue, node_is_element, node_or_foreign_arg_handle,- node_or_foreign_arg_handle_allow_detached, node_runtime_and_handle_from_args,- node_runtime_and_handle_from_args_or_detached,+ node_or_foreign_arg_handle_allow_detached, node_runtime_and_handle_from_args_or_detached,node_runtime_and_handle_from_object_or_detached, remove_child_in_reaction_scope,remove_child_to_current_reaction_queue, set_text_content_in_reaction_scope,set_wrapped_node_or_null,@@ -229,10 +228,6 @@ pub(in crate::native_bridge) use self::submission::{FormAssociatedResetCallbackTiming, form_request_submit_callback, form_reset_callback,form_submit_callback, reset_form_default_action,};-pub(crate) use self::submission::{- align_event_constructor_function_realm_with_constructor,- align_event_constructor_function_realm_with_target,-};pub(crate) use self::submission::{perform_implicit_submission_from_control, submit_form_with_submit_event,};diff --git a/moli-renderer-v8/src/native_bridge/element/forms/form_element.rs b/moli-renderer-v8/src/native_bridge/element/forms/form_element.rsindex 792d300df..741e0910d 100644--- a/moli-renderer-v8/src/native_bridge/element/forms/form_element.rs+++ b/moli-renderer-v8/src/native_bridge/element/forms/form_element.rs@@ -265,7 +265,15 @@ pub(in crate::native_bridge) fn form_elements_getter_function<'s>(tag_name_html_document: None,resolution_cache: Default::default(),};- let collection = collections::build_live_collection_wrapper(scope, runtime_ptr, descriptor);+ let Some(collection) = collections::build_live_collection_wrapper_for_receiver(+ scope,+ runtime_ptr,+ args.this(),+ descriptor,+ ) else {+ rv.set_null();+ return;+ };rv.set(collection.into());}@@ -479,7 +487,15 @@ pub(in crate::native_bridge) fn fieldset_elements_getter_function<'s>(tag_name_html_document: None,resolution_cache: Default::default(),};- let collection = collections::build_live_collection_wrapper(scope, runtime_ptr, descriptor);+ let Some(collection) = collections::build_live_collection_wrapper_for_receiver(+ scope,+ runtime_ptr,+ args.this(),+ descriptor,+ ) else {+ rv.set_null();+ return;+ };rv.set(collection.into());}@@ -573,31 +589,23 @@ pub(in crate::native_bridge) fn form_target_setter_function<'s>(rv.set_undefined();}-pub(in crate::native_bridge) fn form_named_getter<'s>(+// Getter and descriptor reads share value construction and identity policy. Queries,+// deletion, and definition keep their own property-operation rules below.+fn form_named_property_value<'s>(scope: &mut v8::PinScope<'s, '_>,+ receiver: v8::Local<'s, v8::Object>,key: v8::Local<'_, v8::Name>,- args: v8::PropertyCallbackArguments<'s>,- mut rv: v8::ReturnValue<'_, v8::Value>,-) -> v8::Intercepted {- let Ok((runtime_ptr, handle)) =- node_runtime_and_handle_from_object_or_detached(scope, args.holder())- else {- return v8::Intercepted::kNo;- };- let Ok(key) = v8::Local::<v8::String>::try_from(key) else {- return v8::Intercepted::kNo;- };- if object_has_expando_named_property(scope, args.holder(), key.into()) {- return v8::Intercepted::kNo;+) -> Option<v8::Local<'s, v8::Value>> {+ let (runtime_ptr, handle) =+ node_runtime_and_handle_from_object_or_detached(scope, receiver).ok()?;+ let key = v8::Local::<v8::String>::try_from(key).ok()?;+ if object_has_expando_named_property(scope, receiver, key.into()) {+ return None;}let key = key.to_rust_string_lossy(scope);if is_array_index_property_name(&key) {- return v8::Intercepted::kNo;+ return None;}- let Some(context) = args.holder().get_creation_context(scope) else {- return v8::Intercepted::kNo;- };- let scope = &mut v8::ContextScope::new(scope, context);let runtime = unsafe { &mut *runtime_ptr };let (query_kind, matches) = form_named_item_matches(runtime, handle, &key);if matches.len() > 1 {@@ -610,29 +618,33 @@ pub(in crate::native_bridge) fn form_named_getter<'s>(tag_name_html_document: None,resolution_cache: Default::default(),};- let list = collections::build_live_collection_wrapper(scope, runtime_ptr, descriptor);- rv.set(list.into());- return v8::Intercepted::kYes;+ return collections::build_live_collection_wrapper_for_receiver(+ scope,+ runtime_ptr,+ receiver,+ descriptor,+ )+ .map(Into::into);}- let Some(match_handle) = matches.first().copied() else {- let Some(past_handle) = runtime.form_past_named_item(handle, &key) else {- return v8::Intercepted::kNo;- };- let Some(node) =- wrapped_handle_value_for_receiver(scope, runtime_ptr, args.holder(), past_handle)- else {- return v8::Intercepted::kNo;- };- rv.set(node);- return v8::Intercepted::kYes;+ let match_handle = if let Some(match_handle) = matches.first().copied() {+ runtime.remember_form_past_named_item(handle, key, match_handle);+ match_handle+ } else {+ runtime.form_past_named_item(handle, &key)?};- runtime.remember_form_past_named_item(handle, key, match_handle);- let Some(node) =- wrapped_handle_value_for_receiver(scope, runtime_ptr, args.holder(), match_handle)- else {+ wrapped_handle_value_for_receiver(scope, runtime_ptr, receiver, match_handle)+}++pub(in crate::native_bridge) fn form_named_getter<'s>(+ scope: &mut v8::PinScope<'s, '_>,+ key: v8::Local<'_, v8::Name>,+ args: v8::PropertyCallbackArguments<'s>,+ mut rv: v8::ReturnValue<'_, v8::Value>,+) -> v8::Intercepted {+ let Some(value) = form_named_property_value(scope, args.holder(), key) else {return v8::Intercepted::kNo;};- rv.set(node);+ rv.set(value);v8::Intercepted::kYes}@@ -642,57 +654,8 @@ pub(in crate::native_bridge) fn form_named_descriptor<'s>(args: v8::PropertyCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) -> v8::Intercepted {- let Ok((runtime_ptr, handle)) =- node_runtime_and_handle_from_object_or_detached(scope, args.holder())- else {- return v8::Intercepted::kNo;- };- let Ok(key) = v8::Local::<v8::String>::try_from(key) else {- return v8::Intercepted::kNo;- };- if object_has_expando_named_property(scope, args.holder(), key.into()) {- return v8::Intercepted::kNo;- }- let key = key.to_rust_string_lossy(scope);- if is_array_index_property_name(&key) {+ let Some(value) = form_named_property_value(scope, args.holder(), key) else {return v8::Intercepted::kNo;- }- let Some(context) = args.holder().get_creation_context(scope) else {- return v8::Intercepted::kNo;- };- let scope = &mut v8::ContextScope::new(scope, context);- let runtime = unsafe { &mut *runtime_ptr };- let (query_kind, matches) = form_named_item_matches(runtime, handle, &key);- let value = if matches.len() > 1 {- let descriptor = LiveCollectionDescriptor {- collection_kind: CollectionKind::RadioNodeList,- query_kind,- root: handle,- query: Some(key),- include_root: false,- tag_name_html_document: None,- resolution_cache: Default::default(),- };- let list = collections::build_live_collection_wrapper(scope, runtime_ptr, descriptor);- list.into()- } else if let Some(match_handle) = matches.first().copied() {- runtime.remember_form_past_named_item(handle, key, match_handle);- let Some(node) =- wrapped_handle_value_for_receiver(scope, runtime_ptr, args.holder(), match_handle)- else {- return v8::Intercepted::kNo;- };- node- } else {- let Some(past_handle) = runtime.form_past_named_item(handle, &key) else {- return v8::Intercepted::kNo;- };- let Some(node) =- wrapped_handle_value_for_receiver(scope, runtime_ptr, args.holder(), past_handle)- else {- return v8::Intercepted::kNo;- };- node};let Ok(descriptor) = DataPropertyDescriptorDeclaration::new(value, false, false).bind(scope)else {diff --git a/moli-renderer-v8/src/native_bridge/element/forms/submission.rs b/moli-renderer-v8/src/native_bridge/element/forms/submission.rsindex 4e242017d..d8c3f568e 100644--- a/moli-renderer-v8/src/native_bridge/element/forms/submission.rs+++ b/moli-renderer-v8/src/native_bridge/element/forms/submission.rs@@ -169,19 +169,7 @@ fn wrap_handle_value<'s>(runtime_ptr: *mut JsContextHost,handle: Option<DomHandle>,) -> Option<v8::Local<'s, v8::Value>> {- let handle = handle?;- if let Some(detached) = crate::native_bridge::document::detached_native_object_for_handle(- scope,- runtime_ptr,- handle,- ) {- return Some(detached.into());- }- let runtime = unsafe { &mut *runtime_ptr };- let wrapped = runtime- .native_bridge_mut()- .wrap_handle(scope, runtime_ptr, handle)?;- Some(wrapped.into())+ crate::native_bridge::bridge::wrapped_handle_value(scope, runtime_ptr, handle?)}fn wrap_handle_object<'s>(@@ -189,10 +177,8 @@ fn wrap_handle_object<'s>(runtime_ptr: *mut JsContextHost,handle: DomHandle,) -> Option<v8::Local<'s, v8::Object>> {- let runtime = unsafe { &mut *runtime_ptr };- runtime- .native_bridge_mut()- .wrap_handle(scope, runtime_ptr, handle)+ crate::native_bridge::bridge::wrapped_handle_value(scope, runtime_ptr, handle)+ .and_then(|value| v8::Local::<v8::Object>::try_from(value).ok())}pub(crate) fn submit_form_with_submit_event(@@ -347,8 +333,10 @@ pub(in crate::native_bridge) fn form_reset_callback<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {- let Ok((runtime_ptr, form_handle)) = node_runtime_and_handle_from_args(scope, &args) else {- crate::native_bridge::document::detached_form_reset_callback(scope, args, rv);+ let Ok((runtime_ptr, form_handle)) =+ node_runtime_and_handle_from_args_or_detached(scope, &args)+ else {+ rv.set_undefined();return;};let runtime = unsafe { &*runtime_ptr };@@ -362,7 +350,7 @@ pub(in crate::native_bridge) fn form_reset_callback<'s>(return;}- if dispatch_form_reset_event(scope, runtime_ptr, form_handle).allows_default() {+ if dispatch_form_reset_event(scope, runtime_ptr, form_handle, args.this()).allows_default() {let _ = reset_form_default_action(scope,runtime_ptr,@@ -377,20 +365,26 @@ fn dispatch_form_reset_event<'s>(scope: &mut v8::PinScope<'s, '_>,runtime_ptr: *mut JsContextHost,form_handle: DomHandle,+ receiver: v8::Local<'s, v8::Object>,) -> NodePublicEventDispatchOutcome {+ let Some(context) = receiver.get_creation_context(scope) else {+ return NodePublicEventDispatchOutcome {+ default_prevented: true,+ had_exception: false,+ };+ };+ let scope = &mut v8::ContextScope::new(scope, context);let Some(event) = construct_simple_event(scope, "reset", true, true, false) else {return NodePublicEventDispatchOutcome {default_prevented: true,had_exception: false,};};- if let Some(form_wrapper) = wrap_handle_object(scope, runtime_ptr, form_handle) {- align_event_constructor_function_realm_with_target(scope, event, form_wrapper);- }+ align_event_constructor_function_realm_with_target(scope, event, receiver);dispatch_public_event(scope, runtime_ptr, form_handle, event)}-pub(crate) fn align_event_constructor_function_realm_with_target<'s>(+fn align_event_constructor_function_realm_with_target<'s>(scope: &mut v8::PinScope<'s, '_>,event: v8::Local<'s, v8::Object>,target: v8::Local<'s, v8::Object>,@@ -404,7 +398,7 @@ pub(crate) fn align_event_constructor_function_realm_with_target<'s>(align_event_constructor_function_realm_with_constructor(scope, event, target_constructor);}-pub(crate) fn align_event_constructor_function_realm_with_constructor<'s>(+fn align_event_constructor_function_realm_with_constructor<'s>(scope: &mut v8::PinScope<'s, '_>,event: v8::Local<'s, v8::Object>,target_constructor: v8::Local<'s, v8::Object>,@@ -455,8 +449,10 @@ pub(in crate::native_bridge) fn form_submit_callback<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {- let Ok((runtime_ptr, form_handle)) = node_runtime_and_handle_from_args(scope, &args) else {- crate::native_bridge::document::detached_form_submit_callback(scope, args, rv);+ let Ok((runtime_ptr, form_handle)) =+ node_runtime_and_handle_from_args_or_detached(scope, &args)+ else {+ rv.set_undefined();return;};let runtime = unsafe { &*runtime_ptr };@@ -575,6 +571,17 @@ pub(in crate::native_bridge) fn submit_form_default_action(source_document,)};+ // A parsed/detached Document has no browsing context to navigate. Resolve+ // that from the native document, independently of the form's wrapper kind.+ if source_document.is_none_or(|document| {+ let runtime = unsafe { &*runtime_ptr };+ document != runtime.document_handle()+ && runtime+ .child_browsing_context_handle_by_document_handle(scope, document)+ .is_none()+ }) {+ return false;+ }let Some(request) =build_form_submission_request(scope, runtime_ptr, form_handle, submitter, action)else {diff --git a/moli-renderer-v8/src/native_bridge/element/template_install.rs b/moli-renderer-v8/src/native_bridge/element/template_install.rsindex 743f497f4..412589a2b 100644--- a/moli-renderer-v8/src/native_bridge/element/template_install.rs+++ b/moli-renderer-v8/src/native_bridge/element/template_install.rs@@ -7,7 +7,6 @@ mod accessors_structural;mod instance;mod methods;-pub(in crate::native_bridge) use accessors_forms::install_form_property_handlers;use accessors_forms::install_form_template_accessors;use accessors_media::install_media_template_accessors;use accessors_resource::install_resource_template_accessors;diff --git a/moli-renderer-v8/src/native_bridge/element/template_install/accessors_forms.rs b/moli-renderer-v8/src/native_bridge/element/template_install/accessors_forms.rsindex dffba5af3..9d48775d6 100644--- a/moli-renderer-v8/src/native_bridge/element/template_install/accessors_forms.rs+++ b/moli-renderer-v8/src/native_bridge/element/template_install/accessors_forms.rs@@ -5,7 +5,6 @@ mod input;mod select;use self::controls::install_form_control_template_accessors;-pub(in crate::native_bridge) use self::controls::install_form_property_handlers;use self::input::install_input_template_accessors;use self::select::install_select_option_template_accessors;diff --git a/moli-renderer-v8/src/native_bridge/element/template_install/accessors_forms/controls.rs b/moli-renderer-v8/src/native_bridge/element/template_install/accessors_forms/controls.rsindex cce5cf648..37fd3557e 100644--- a/moli-renderer-v8/src/native_bridge/element/template_install/accessors_forms/controls.rs+++ b/moli-renderer-v8/src/native_bridge/element/template_install/accessors_forms/controls.rs@@ -29,9 +29,7 @@ pub(super) fn install_form_control_template_accessors<'s, 'i>(}}-pub(in crate::native_bridge) fn install_form_property_handlers(- template: v8::Local<'_, v8::ObjectTemplate>,-) {+fn install_form_property_handlers(template: v8::Local<'_, v8::ObjectTemplate>) {template.set_indexed_property_handler(v8::IndexedPropertyHandlerConfiguration::new().getter(form_indexed_getter)diff --git a/moli-renderer-v8/src/native_bridge/node.rs b/moli-renderer-v8/src/native_bridge/node.rsindex 396c93df7..8b107a7f4 100644--- a/moli-renderer-v8/src/native_bridge/node.rs+++ b/moli-renderer-v8/src/native_bridge/node.rs@@ -1326,15 +1326,6 @@ pub(super) fn node_runtime_and_handle_from_args_or_detached() -> std::result::Result<(*mut JsContextHost, DomHandle), String> {let this = v8::Global::new(scope, args.this());let this = v8::Local::new(scope, this);- if let Some(runtime_ptr) = context_host_ptr_from_global_bridge(scope)- && let Some(handle) =- super::document::detached_native_handle_for_runtime(scope, runtime_ptr, this)- {- return Ok((runtime_ptr, handle));- }- if let Ok(node) = node_runtime_and_handle_from_object(scope, this) {- return Ok(node);- }node_runtime_and_handle_from_object_or_detached(scope, this)}diff --git a/moli-renderer-v8/src/script_vm/tests/dom_xhr/forms.rs b/moli-renderer-v8/src/script_vm/tests/dom_xhr/forms.rsindex 60a453ce1..09623d45b 100644--- a/moli-renderer-v8/src/script_vm/tests/dom_xhr/forms.rs+++ b/moli-renderer-v8/src/script_vm/tests/dom_xhr/forms.rs@@ -3,6 +3,7 @@ use super::*;mod dialog;mod event_activation;mod named_lookup;+mod wrappers;#[test]fn object_set_custom_validity_updates_validity_state() {diff --git a/moli-renderer-v8/src/script_vm/tests/dom_xhr/forms/wrappers.rs b/moli-renderer-v8/src/script_vm/tests/dom_xhr/forms/wrappers.rsnew file mode 100644index 000000000..7c3403f12--- /dev/null+++ b/moli-renderer-v8/src/script_vm/tests/dom_xhr/forms/wrappers.rs@@ -0,0 +1,119 @@+use super::*;++#[test]+fn form_wrappers_preserve_own_properties_and_identity_across_adoption() {+ let mut vm = new_parsed_test_vm(+ "https://form-wrapper-adoption.test/",+ "<!doctype html><body></body>",+ );+ assert_eq!(vm.eval(r#"(() => {+ const detached = document.implementation.createHTMLDocument('forms');+ const parsed = new DOMParser().parseFromString('<form></form>', 'text/html');+ const frame = document.body.appendChild(document.createElement('iframe'));+ const child = frame.contentDocument;+ const forms = [document.createElement('form'), detached.createElement('form'),+ parsed.querySelector('form'), child.createElement('form')];+ const keys = ['name', 'elements', 'length', 'submit', 'reset', 'nodeType', 'nodeName', 'ownerDocument', 'matches'];+ for (const [mode, form] of forms.entries()) {+ const doc = form.ownerDocument;+ const values = keys.map(() => ({}));+ for (const [i, key] of keys.entries()) {+ if (Object.hasOwn(form, key)) throw Error(mode + ': native own ' + key);+ Object.defineProperty(form, key, {value: values[i], writable: true, configurable: true, enumerable: true});+ const control = form.appendChild(doc.createElement('input'));+ control.name = key;+ }+ const first = form[0];+ for (const target of [detached, child, document, parsed]) {+ if (target.adoptNode(form) !== form) throw Error('adopt replaced form');+ target.body.appendChild(form);+ if (form[0] !== first || Object.getOwnPropertyDescriptor(form, '0').value !== first) throw Error('control identity');+ for (const [i, key] of keys.entries()) {+ const d = Object.getOwnPropertyDescriptor(form, key);+ if (!d || d.value !== values[i] || !d.writable || !d.enumerable || !d.configurable || form[key] !== values[i])+ throw Error(mode + ': adoption changed own ' + key);+ }+ }+ for (const [i, key] of keys.entries()) {+ if (!delete form[key] || form[key] !== form[i]) throw Error('own deletion must reveal control: ' + key);+ }+ }+ return 'ok';+ })()"#).unwrap(), "ok");+}++#[test]+fn form_wrappers_return_collections_in_receiver_realm_for_borrowed_accessors() {+ let mut vm = new_parsed_test_vm(+ "https://form-wrapper-realms.test/",+ "<!doctype html><body></body>",+ );+ assert_eq!(vm.eval(r#"(() => {+ const frame = document.body.appendChild(document.createElement('iframe'));+ const realm = frame.contentWindow;+ const detached = realm.document.implementation.createHTMLDocument('forms');+ const source = detached.createElement('form');+ const markup = '<input name="group"><input name="group"><img name="photos"><img name="photos">';+ source.innerHTML = markup;+ const forms = [source, source.cloneNode(true), realm.document.importNode(source, true),+ realm.document.createElement('form')];+ const parentElements = Object.getOwnPropertyDescriptor(HTMLFormElement.prototype, 'elements').get;+ for (const [mode, form] of forms.entries()) {+ if (!form.firstChild) form.innerHTML = markup;+ const inputs = form.querySelectorAll('input');+ const photos = form.querySelectorAll('img');+ const elements = parentElements.call(form);+ if (elements !== form.elements || !(elements instanceof realm.HTMLFormControlsCollection) || elements[0] !== inputs[0])+ throw Error('borrowed elements accessor used caller realm');+ for (const [key, items] of [['group', inputs], ['photos', photos]]) {+ const list = form[key];+ const described = Object.getOwnPropertyDescriptor(form, key).value;+ if (list !== described || !(list instanceof realm.RadioNodeList) || list.length !== 2 || list[0] !== items[0])+ throw Error(mode + ':' + key + ': named result identity/realm ' + [list === described, list instanceof realm.RadioNodeList, list.length, list[0] === items[0]].join(','));+ }+ document.body.appendChild(document.adoptNode(form));+ if (parentElements.call(form) !== elements || form[0] !== inputs[0]) throw Error('adoption changed wrapper cache');+ inputs[1].remove();+ if (form.group !== inputs[0] || Object.getOwnPropertyDescriptor(form, 'group').value !== inputs[0]) throw Error('single identity');+ }+ return 'ok';+ })()"#).unwrap(), "ok");+}++#[test]+fn form_wrappers_share_reset_events_and_keep_inert_submissions_inert() {+ let mut vm = new_parsed_test_vm(+ "https://form-wrapper-methods.test/",+ "<!doctype html><body></body>",+ );+ assert_eq!(vm.eval(r#"(() => {+ const frame = document.body.appendChild(document.createElement('iframe'));+ const child = frame.contentWindow;+ const docs = [document.implementation.createHTMLDocument('forms'),+ new DOMParser().parseFromString('<body></body>', 'text/html'),+ child.document.implementation.createHTMLDocument('forms')];+ for (const [mode, doc] of docs.entries()) {+ const form = doc.body.appendChild(doc.createElement('form'));+ form.innerHTML = '<input name="field" value="initial">';+ const input = form.field;+ let resets = 0;+ form.addEventListener('reset', event => {+ if (event.target !== form || event.currentTarget !== form || !event.bubbles || !event.cancelable ||+ event.constructor.constructor !== form.constructor.constructor) throw Error(mode + ': reset identity/realm');+ if (++resets === 1) event.preventDefault();+ });+ input.value = 'edited';+ HTMLFormElement.prototype.reset.call(form);+ if (input.value !== 'edited' || resets !== 1) throw Error('reset cancellation');+ child.HTMLFormElement.prototype.reset.call(form);+ if (input.value !== 'initial' || resets !== 2) throw Error('shared reset default action');+ form.action = '/should-not-navigate';+ for (const method of ['get', 'post']) {+ form.method = method;+ HTMLFormElement.prototype.submit.call(form);+ }+ }+ return 'ok';+ })()"#).unwrap(), "ok");+ assert!(vm.take_pending_location_navigation_with_seed().is_none());+}