Skip to content

armgit / moli

Public Imported from GitHub
0

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

refactor(dom): share native Node argument conversion

ldm087652d4369a7
diff --git a/moli-renderer-v8/src/native_bridge/bindings/native_template/detached_node_surface.rs b/moli-renderer-v8/src/native_bridge/bindings/native_template/detached_node_surface.rs
index 3f1902741..8a7db9fd2 100644
--- a/moli-renderer-v8/src/native_bridge/bindings/native_template/detached_node_surface.rs
+++ b/moli-renderer-v8/src/native_bridge/bindings/native_template/detached_node_surface.rs
@@ -148,18 +148,6 @@ struct NativeBridgeDetachedNodeSurfaceDeclaration {
)]
detached_has_child_nodes: (),
- #[webapi(
- method = "__detachedContains",
- callback = document::bridge_detached_contains_callback
- )]
- detached_contains: (),
-
- #[webapi(
- method = "__detachedIsSameNode",
- callback = document::bridge_detached_is_same_node_callback
- )]
- detached_is_same_node: (),
-
#[webapi(
method = "__detachedChildren",
callback = document::bridge_detached_children_callback
@@ -196,12 +184,6 @@ struct NativeBridgeDetachedNodeSurfaceDeclaration {
)]
detached_next_element_sibling: (),
- #[webapi(
- method = "__detachedIsEqualNode",
- callback = document::bridge_detached_is_equal_node_callback
- )]
- detached_is_equal_node: (),
-
#[webapi(
method = "__detachedCloneNode",
callback = document::bridge_detached_clone_node_callback
diff --git a/moli-renderer-v8/src/native_bridge/document.rs b/moli-renderer-v8/src/native_bridge/document.rs
index 3d698fdd7..4a6f6becb 100644
--- a/moli-renderer-v8/src/native_bridge/document.rs
+++ b/moli-renderer-v8/src/native_bridge/document.rs
@@ -218,9 +218,8 @@ pub(super) use detached_surface::{
bridge_detached_character_data_getter_callback, bridge_detached_character_data_setter_callback,
bridge_detached_child_element_count_callback, bridge_detached_child_nodes_callback,
bridge_detached_children_callback, bridge_detached_clone_node_callback,
- bridge_detached_contains_callback, bridge_detached_create_cdata_section_callback,
- bridge_detached_create_comment_callback, bridge_detached_create_document_fragment_callback,
- bridge_detached_create_element_callback,
+ bridge_detached_create_cdata_section_callback, bridge_detached_create_comment_callback,
+ bridge_detached_create_document_fragment_callback, bridge_detached_create_element_callback,
bridge_detached_create_processing_instruction_callback, bridge_detached_create_text_callback,
bridge_detached_doctype_name_callback, bridge_detached_doctype_public_id_callback,
bridge_detached_doctype_system_id_callback, bridge_detached_document_base_uri_callback,
@@ -238,8 +237,7 @@ pub(super) use detached_surface::{
bridge_detached_get_attribute_names_callback, bridge_detached_get_attribute_ns_callback,
bridge_detached_has_attribute_callback, bridge_detached_has_attribute_ns_callback,
bridge_detached_has_child_nodes_callback, bridge_detached_insert_before_callback,
- bridge_detached_is_connected_callback, bridge_detached_is_equal_node_callback,
- bridge_detached_is_same_node_callback, bridge_detached_last_child_callback,
+ bridge_detached_is_connected_callback, bridge_detached_last_child_callback,
bridge_detached_last_element_child_callback, bridge_detached_move_before_callback,
bridge_detached_next_element_sibling_callback, bridge_detached_next_sibling_callback,
bridge_detached_node_name_callback, bridge_detached_node_type_callback,
diff --git a/moli-renderer-v8/src/native_bridge/document/attributes/attr_object/instance/install.rs b/moli-renderer-v8/src/native_bridge/document/attributes/attr_object/instance/install.rs
index f96fc7154..ed0b6fa78 100644
--- a/moli-renderer-v8/src/native_bridge/document/attributes/attr_object/instance/install.rs
+++ b/moli-renderer-v8/src/native_bridge/document/attributes/attr_object/instance/install.rs
@@ -17,8 +17,6 @@ use moli_webapi_declare::WebApiObject;
#[derive(WebApiObject)]
#[webapi(interface = web_api_interfaces::Attr)]
struct AttrInstanceMethodsDeclaration {
- #[webapi(method, length = 0, callback = attr_instance_is_same_node_callback)]
- is_same_node: (),
#[webapi(method, length = 0, callback = attr_instance_clone_node_callback)]
clone_node: (),
#[webapi(
@@ -65,14 +63,6 @@ fn attr_instance_clone_node_callback<'a>(
}
}
-fn attr_instance_is_same_node_callback<'a>(
- _scope: &mut v8::PinScope<'a, '_>,
- args: v8::FunctionCallbackArguments<'a>,
- mut rv: v8::ReturnValue<'_, v8::Value>,
-) {
- rv.set_bool(args.this().strict_equals(args.get(0)));
-}
-
fn attr_instance_lookup_namespace_uri_callback<'a>(
scope: &mut v8::PinScope<'a, '_>,
args: v8::FunctionCallbackArguments<'a>,
diff --git a/moli-renderer-v8/src/native_bridge/document/detached_install/bridge_methods/node.rs b/moli-renderer-v8/src/native_bridge/document/detached_install/bridge_methods/node.rs
index a1ed72ea4..6190c555a 100644
--- a/moli-renderer-v8/src/native_bridge/document/detached_install/bridge_methods/node.rs
+++ b/moli-renderer-v8/src/native_bridge/document/detached_install/bridge_methods/node.rs
@@ -1,4 +1,9 @@
use super::*;
+use crate::native_bridge::node::{
+ node_compare_document_position_callback, node_contains_callback, node_is_equal_node_callback,
+ node_is_same_node_callback,
+};
+use crate::web_api_interfaces;
use moli_webapi_declare::WebApiObject;
#[derive(Default, WebApiObject)]
@@ -10,7 +15,7 @@ struct DetachedNodeMethodsDeclaration {
#[webapi(method, callback = detached_insert_before_method_callback)]
insert_before: (),
- #[webapi(method, callback = detached_remove_child_method_callback)]
+ #[webapi(method, length = 1, callback = detached_remove_child_method_callback, receiver = web_api_interfaces::Node::is_instance)]
remove_child: (),
#[webapi(method, callback = detached_remove_method_callback)]
@@ -31,16 +36,16 @@ struct DetachedNodeMethodsDeclaration {
)]
lookup_namespace_uri: (),
- #[webapi(method, callback = detached_contains_method_callback)]
+ #[webapi(method, length = 1, callback = node_contains_callback, receiver = web_api_interfaces::Node::is_instance)]
contains: (),
- #[webapi(method, callback = detached_is_same_node_method_callback)]
+ #[webapi(method, length = 1, callback = node_is_same_node_callback, receiver = web_api_interfaces::Node::is_instance)]
is_same_node: (),
- #[webapi(method, callback = detached_is_equal_node_method_callback)]
+ #[webapi(method, length = 1, callback = node_is_equal_node_callback, receiver = web_api_interfaces::Node::is_instance)]
is_equal_node: (),
- #[webapi(method, callback = detached_compare_document_position_method_callback)]
+ #[webapi(method, length = 1, callback = node_compare_document_position_callback, receiver = web_api_interfaces::Node::is_instance)]
compare_document_position: (),
#[webapi(method, callback = detached_clone_node_method_callback)]
diff --git a/moli-renderer-v8/src/native_bridge/document/detached_objects.rs b/moli-renderer-v8/src/native_bridge/document/detached_objects.rs
index 4733eef29..d025bc68d 100644
--- a/moli-renderer-v8/src/native_bridge/document/detached_objects.rs
+++ b/moli-renderer-v8/src/native_bridge/document/detached_objects.rs
@@ -5,13 +5,13 @@ mod builders;
mod clone;
mod collections;
mod document_state;
-mod equality;
mod method_forwarders;
mod mutation;
mod object_access;
mod prototypes;
mod shadow_dom;
mod state_tree;
+mod text_content;
pub(in crate::native_bridge::document) use self::attributes::*;
pub(in crate::native_bridge::document) use self::builders::*;
@@ -23,7 +23,6 @@ pub(crate) use self::builders::{
pub(in crate::native_bridge::document) use self::clone::*;
pub(in crate::native_bridge::document) use self::collections::*;
pub(in crate::native_bridge::document) use self::document_state::*;
-pub(in crate::native_bridge::document) use self::equality::*;
pub(crate) use self::method_forwarders::ensure_detached_document_implementation;
pub(in crate::native_bridge) use self::method_forwarders::*;
pub(in crate::native_bridge::document) use self::mutation::*;
@@ -55,3 +54,4 @@ pub(crate) use self::state_tree::{
detached_native_handle_for_runtime, detached_native_object_for_handle,
detached_record_native_tree_mutations, paired_detached_native_object_for_handle,
};
+pub(in crate::native_bridge::document) use self::text_content::*;
diff --git a/moli-renderer-v8/src/native_bridge/document/detached_objects/equality.rs b/moli-renderer-v8/src/native_bridge/document/detached_objects/equality.rs
deleted file mode 100644
index 84094a52f..000000000
--- a/moli-renderer-v8/src/native_bridge/document/detached_objects/equality.rs
+++ /dev/null
@@ -1,183 +0,0 @@
-use super::*;
-use crate::util::context_host_ptr_from_global_bridge;
-
-fn detached_read_child_node_objects<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- node: v8::Local<'s, v8::Object>,
-) -> Vec<v8::Local<'s, v8::Object>> {
- detached_child_node_objects(scope, node)
-}
-
-fn detached_native_nodes_equal<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- left: v8::Local<'s, v8::Object>,
- right: v8::Local<'s, v8::Object>,
-) -> Option<bool> {
- let runtime_ptr = context_host_ptr_from_global_bridge(scope)?;
- let left_handle = detached_native_handle_for_runtime(scope, runtime_ptr, left)?;
- let right_handle = detached_native_handle_for_runtime(scope, runtime_ptr, right)?;
- let dom_host = unsafe { &*runtime_ptr }.dom_host();
- let left_node = dom_host.node(left_handle)?;
- let right_node = dom_host.node(right_handle)?;
- Some(left_node.is_equal_node(dom_host, right_node))
-}
-
-struct DetachedAttributeSnapshot {
- names: Vec<String>,
- native_backed: bool,
-}
-
-fn detached_attribute_snapshot<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- element: v8::Local<'s, v8::Object>,
-) -> DetachedAttributeSnapshot {
- if let Some(names) = read_detached_native_attribute_names(scope, element) {
- return DetachedAttributeSnapshot {
- names,
- native_backed: true,
- };
- }
-
- let names = call_object_method(scope, element, "getAttributeNames", &[])
- .and_then(|value| v8::Local::<v8::Object>::try_from(value).ok())
- .map(|names| {
- let mut out = Vec::new();
- let length = names
- .get(scope, v8str(scope, "length").into())
- .and_then(|value| value.uint32_value(scope))
- .unwrap_or(0);
- for index in 0..length {
- let Some(name) = names.get_index(scope, index) else {
- continue;
- };
- let Some(name) = name.to_string(scope) else {
- continue;
- };
- out.push(name.to_rust_string_lossy(scope));
- }
- out
- })
- .unwrap_or_default();
-
- DetachedAttributeSnapshot {
- names,
- native_backed: false,
- }
-}
-
-fn detached_attribute_snapshot_value<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- element: v8::Local<'s, v8::Object>,
- snapshot: &DetachedAttributeSnapshot,
- name: &str,
-) -> Option<String> {
- if snapshot.native_backed {
- return read_detached_native_attribute(scope, element, name);
- }
-
- let name_value = v8_string(scope, name)?;
- call_object_method(scope, element, "getAttribute", &[name_value.into()])
- .and_then(|value| value.to_string(scope))
- .map(|value| value.to_rust_string_lossy(scope))
-}
-
-pub(in crate::native_bridge::document) fn detached_nodes_equal<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- left: v8::Local<'s, v8::Object>,
- right: v8::Local<'s, v8::Object>,
-) -> bool {
- if let Some(equal) = detached_native_nodes_equal(scope, left, right) {
- return equal;
- }
-
- let left_type = detached_node_type(scope, left);
- let right_type = detached_node_type(scope, right);
- if left_type.is_none() || right_type.is_none() {
- return left == right;
- }
- if left_type != right_type
- || object_string_property(scope, left, "nodeName")
- != object_string_property(scope, right, "nodeName")
- {
- return false;
- }
-
- match left_type.unwrap_or_default() {
- 10 => {
- return object_string_property(scope, left, "name")
- == object_string_property(scope, right, "name")
- && object_string_property(scope, left, "publicId")
- == object_string_property(scope, right, "publicId")
- && object_string_property(scope, left, "systemId")
- == object_string_property(scope, right, "systemId");
- }
- 3 | 8 | 7 => {
- return detached_character_data_value(scope, left)
- == detached_character_data_value(scope, right);
- }
- 1 => {
- let left_attributes = detached_attribute_snapshot(scope, left);
- let right_attributes = detached_attribute_snapshot(scope, right);
- if left_attributes.names.len() != right_attributes.names.len() {
- return false;
- }
- for name in &left_attributes.names {
- let left_value =
- detached_attribute_snapshot_value(scope, left, &left_attributes, name);
- let right_value =
- detached_attribute_snapshot_value(scope, right, &right_attributes, name);
- if left_value != right_value {
- return false;
- }
- }
- }
- _ => {}
- }
-
- let left_children = detached_read_child_node_objects(scope, left);
- let right_children = detached_read_child_node_objects(scope, right);
- if left_children.len() != right_children.len() {
- return false;
- }
- for (left_child, right_child) in left_children.into_iter().zip(right_children) {
- if !detached_nodes_equal(scope, left_child, right_child) {
- return false;
- }
- }
- true
-}
-
-pub(in crate::native_bridge::document) fn detached_text_content<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- node: v8::Local<'s, v8::Object>,
-) -> Option<String> {
- match detached_node_type(scope, node) {
- Some(9 | 10) => None,
- Some(3 | 4 | 8 | 7) => Some(detached_character_data_value(scope, node)),
- Some(_) => Some(
- detached_read_child_node_objects(scope, node)
- .into_iter()
- .fold(String::new(), |mut out, child| {
- append_detached_text_content(scope, child, &mut out);
- out
- }),
- ),
- None => Some(String::new()),
- }
-}
-
-fn append_detached_text_content<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- node: v8::Local<'s, v8::Object>,
- out: &mut String,
-) {
- match detached_node_type(scope, node) {
- Some(3 | 4) => out.push_str(&detached_character_data_value(scope, node)),
- Some(7..=10) | None => {}
- Some(_) => {
- for child in detached_read_child_node_objects(scope, node) {
- append_detached_text_content(scope, child, out);
- }
- }
- }
-}
diff --git a/moli-renderer-v8/src/native_bridge/document/detached_objects/method_forwarders.rs b/moli-renderer-v8/src/native_bridge/document/detached_objects/method_forwarders.rs
index 4db528cbe..1a15f6277 100644
--- a/moli-renderer-v8/src/native_bridge/document/detached_objects/method_forwarders.rs
+++ b/moli-renderer-v8/src/native_bridge/document/detached_objects/method_forwarders.rs
@@ -104,10 +104,19 @@ pub(in crate::native_bridge::document) fn detached_move_before_method_callback<'
) {
let _ = detached_method_forward(scope, args, "__detachedMoveBefore");
}
-detached_bridge_method_forwarder!(
- detached_remove_child_method_callback,
- "__detachedRemoveChild"
-);
+pub(in crate::native_bridge) fn detached_remove_child_method_callback<'s>(
+ scope: &mut v8::PinScope<'s, '_>,
+ args: v8::FunctionCallbackArguments<'s>,
+ mut rv: v8::ReturnValue<'_, v8::Value>,
+) {
+ if webidl::parse_args::<crate::native_bridge::node::RequiredNodeArgs>(scope, &args).is_none() {
+ return;
+ }
+ match detached_method_forward(scope, args, "__detachedRemoveChild") {
+ Some(value) => rv.set(value),
+ None => rv.set_undefined(),
+ }
+}
detached_bridge_method_forwarder!(
detached_replace_child_method_callback,
"__detachedReplaceChild"
@@ -239,15 +248,6 @@ pub(in crate::native_bridge::document) fn detached_lookup_namespace_uri_method_c
None => rv.set_null(),
}
}
-detached_bridge_method_forwarder!(detached_contains_method_callback, "__detachedContains");
-detached_bridge_method_forwarder!(
- detached_is_same_node_method_callback,
- "__detachedIsSameNode"
-);
-detached_bridge_method_forwarder!(
- detached_is_equal_node_method_callback,
- "__detachedIsEqualNode"
-);
pub(in crate::native_bridge) fn detached_clone_node_method_callback<'a>(
scope: &mut v8::PinScope<'a, '_>,
args: v8::FunctionCallbackArguments<'a>,
@@ -686,74 +686,6 @@ pub(in crate::native_bridge) fn detached_click_method_callback<'s>(
}
}
-pub(in crate::native_bridge::document) fn detached_compare_document_position_method_callback<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- args: v8::FunctionCallbackArguments<'s>,
- mut rv: v8::ReturnValue<'_, v8::Value>,
-) {
- const DOCUMENT_POSITION_DISCONNECTED: u32 = 0x01;
- const DOCUMENT_POSITION_PRECEDING: u32 = 0x02;
- const DOCUMENT_POSITION_FOLLOWING: u32 = 0x04;
- const DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC: u32 = 0x20;
-
- let Some(runtime_ptr) = context_host_ptr_from_global_bridge(scope) else {
- rv.set(v8::Integer::new_from_unsigned(scope, 0).into());
- return;
- };
- let this = args.this();
- let Some(handle) = detached_native_handle_for_runtime(scope, runtime_ptr, this) else {
- rv.set(v8::Integer::new_from_unsigned(scope, 0).into());
- return;
- };
- let other_value = args.get(0);
- let Ok(other) = v8::Local::<v8::Object>::try_from(other_value) else {
- throw_type_error(
- scope,
- "Failed to execute 'compareDocumentPosition' on 'Node': parameter 1 is not of type 'Node'.",
- );
- return;
- };
- if let Some(other_handle) = detached_native_handle_for_runtime(scope, runtime_ptr, other)
- .or_else(|| {
- crate::native_bridge::node_runtime_and_handle_from_object(scope, other)
- .ok()
- .and_then(|(other_runtime_ptr, other_handle)| {
- (other_runtime_ptr == runtime_ptr).then_some(other_handle)
- })
- })
- {
- let runtime = unsafe { &*runtime_ptr };
- let relation = runtime
- .dom_host()
- .node(handle)
- .map(|node| node.compare_document_position(runtime.dom_host().dom(), other_handle))
- .unwrap_or(0);
- rv.set(v8::Integer::new_from_unsigned(scope, relation as u32).into());
- return;
- }
- if get_private_object(scope, other, DETACHED_STATE_SLOT).is_none() {
- throw_type_error(
- scope,
- "Failed to execute 'compareDocumentPosition' on 'Node': parameter 1 is not of type 'Node'.",
- );
- return;
- }
- let this_hash = this.get_identity_hash().get() as i64;
- let other_hash = other.get_identity_hash().get() as i64;
- let order_bit = if other_hash > this_hash {
- DOCUMENT_POSITION_FOLLOWING
- } else {
- DOCUMENT_POSITION_PRECEDING
- };
- rv.set(
- v8::Integer::new_from_unsigned(
- scope,
- DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | order_bit,
- )
- .into(),
- );
-}
-
pub(in crate::native_bridge::document) fn detached_remove_method_callback<'a>(
scope: &mut v8::PinScope<'a, '_>,
args: v8::FunctionCallbackArguments<'a>,
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.rs
index c8cab077d..142fcf279 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
@@ -622,23 +622,6 @@ fn detached_native_element_child_objects<'s>(
)
}
-fn detached_native_contains<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- node: v8::Local<'s, v8::Object>,
- other: v8::Local<'s, v8::Object>,
-) -> Option<bool> {
- let runtime_ptr = context_host_ptr_from_global_bridge(scope)?;
- let handle = detached_native_handle_for_runtime(scope, runtime_ptr, node)?;
- let other_handle = detached_native_handle_for_runtime(scope, runtime_ptr, other)?;
- Some(
- handle == other_handle
- || unsafe { &*runtime_ptr }
- .dom_host()
- .dom()
- .contains(handle, other_handle),
- )
-}
-
fn detached_native_is_connected_to_tree_root<'s>(
scope: &mut v8::PinScope<'s, '_>,
node: v8::Local<'s, v8::Object>,
@@ -1383,32 +1366,6 @@ pub(crate) fn detached_is_connected<'s>(
false
}
-pub(in crate::native_bridge::document) fn detached_contains<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- node: v8::Local<'s, v8::Object>,
- other: v8::Local<'s, v8::Object>,
-) -> bool {
- if node.strict_equals(other.into()) {
- return true;
- }
- if let Some(contains) = detached_native_contains(scope, node, other) {
- return contains;
- }
- if let Some(delegate) = detached_live_delegate_object(scope, node) {
- let candidate = detached_live_delegate_object(scope, other).unwrap_or(other);
- return call_object_method(scope, delegate, "contains", &[candidate.into()])
- .is_some_and(|value| value.boolean_value(scope));
- }
- let mut current = detached_parent_node_object(scope, other);
- while let Some(candidate) = current {
- if candidate.strict_equals(node.into()) {
- return true;
- }
- current = detached_parent_node_object(scope, candidate);
- }
- false
-}
-
pub(in crate::native_bridge::document) fn detached_element_children_objects<'s>(
scope: &mut v8::PinScope<'s, '_>,
node: v8::Local<'s, v8::Object>,
diff --git a/moli-renderer-v8/src/native_bridge/document/detached_objects/text_content.rs b/moli-renderer-v8/src/native_bridge/document/detached_objects/text_content.rs
new file mode 100644
index 000000000..ceed1fd02
--- /dev/null
+++ b/moli-renderer-v8/src/native_bridge/document/detached_objects/text_content.rs
@@ -0,0 +1,35 @@
+use super::*;
+
+pub(in crate::native_bridge::document) fn detached_text_content<'s>(
+ scope: &mut v8::PinScope<'s, '_>,
+ node: v8::Local<'s, v8::Object>,
+) -> Option<String> {
+ match detached_node_type(scope, node) {
+ Some(9 | 10) => None,
+ Some(3 | 4 | 8 | 7) => Some(detached_character_data_value(scope, node)),
+ Some(_) => Some(detached_child_node_objects(scope, node).into_iter().fold(
+ String::new(),
+ |mut out, child| {
+ append_detached_text_content(scope, child, &mut out);
+ out
+ },
+ )),
+ None => Some(String::new()),
+ }
+}
+
+fn append_detached_text_content<'s>(
+ scope: &mut v8::PinScope<'s, '_>,
+ node: v8::Local<'s, v8::Object>,
+ out: &mut String,
+) {
+ match detached_node_type(scope, node) {
+ Some(3 | 4) => out.push_str(&detached_character_data_value(scope, node)),
+ Some(7..=10) | None => {}
+ Some(_) => {
+ for child in detached_child_node_objects(scope, node) {
+ append_detached_text_content(scope, child, out);
+ }
+ }
+ }
+}
diff --git a/moli-renderer-v8/src/native_bridge/document/detached_surface/node_metadata.rs b/moli-renderer-v8/src/native_bridge/document/detached_surface/node_metadata.rs
index 7165128a3..0501f6577 100644
--- a/moli-renderer-v8/src/native_bridge/document/detached_surface/node_metadata.rs
+++ b/moli-renderer-v8/src/native_bridge/document/detached_surface/node_metadata.rs
@@ -142,36 +142,3 @@ pub(in crate::native_bridge) fn bridge_detached_processing_instruction_target_ca
let target = detached_processing_instruction_target(scope, node).unwrap_or_default();
set_string_return_value(scope, &mut rv, &target);
}
-
-pub(in crate::native_bridge) fn bridge_detached_is_same_node_callback<'a>(
- scope: &mut v8::PinScope<'a, '_>,
- args: v8::FunctionCallbackArguments<'a>,
- mut rv: v8::ReturnValue<'_, v8::Value>,
-) {
- let Ok(left) = v8::Local::<v8::Object>::try_from(args.get(0)) else {
- rv.set(v8::Boolean::new(scope, false).into());
- return;
- };
- let Ok(right) = v8::Local::<v8::Object>::try_from(args.get(1)) else {
- rv.set(v8::Boolean::new(scope, false).into());
- return;
- };
- rv.set(v8::Boolean::new(scope, left == right).into());
-}
-
-pub(in crate::native_bridge) fn bridge_detached_is_equal_node_callback<'a>(
- scope: &mut v8::PinScope<'a, '_>,
- args: v8::FunctionCallbackArguments<'a>,
- mut rv: v8::ReturnValue<'_, v8::Value>,
-) {
- let Ok(left) = v8::Local::<v8::Object>::try_from(args.get(0)) else {
- rv.set(v8::Boolean::new(scope, false).into());
- return;
- };
- let Ok(right) = v8::Local::<v8::Object>::try_from(args.get(1)) else {
- rv.set(v8::Boolean::new(scope, false).into());
- return;
- };
- let equal = detached_nodes_equal(scope, left, right);
- rv.set(v8::Boolean::new(scope, equal).into());
-}
diff --git a/moli-renderer-v8/src/native_bridge/document/detached_surface/tree.rs b/moli-renderer-v8/src/native_bridge/document/detached_surface/tree.rs
index fe469d071..d3809acac 100644
--- a/moli-renderer-v8/src/native_bridge/document/detached_surface/tree.rs
+++ b/moli-renderer-v8/src/native_bridge/document/detached_surface/tree.rs
@@ -234,22 +234,6 @@ pub(in crate::native_bridge) fn bridge_detached_has_child_nodes_callback<'a>(
rv.set_bool(!detached_child_node_objects(scope, node).is_empty());
}
-pub(in crate::native_bridge) fn bridge_detached_contains_callback<'a>(
- scope: &mut v8::PinScope<'a, '_>,
- args: v8::FunctionCallbackArguments<'a>,
- mut rv: v8::ReturnValue<'_, v8::Value>,
-) {
- let Ok(node) = v8::Local::<v8::Object>::try_from(args.get(0)) else {
- rv.set_bool(false);
- return;
- };
- let Ok(other) = v8::Local::<v8::Object>::try_from(args.get(1)) else {
- rv.set_bool(false);
- return;
- };
- rv.set_bool(detached_contains(scope, node, other));
-}
-
pub(in crate::native_bridge) fn bridge_detached_children_callback<'a>(
scope: &mut v8::PinScope<'a, '_>,
args: v8::FunctionCallbackArguments<'a>,
diff --git a/moli-renderer-v8/src/native_bridge/node.rs b/moli-renderer-v8/src/native_bridge/node.rs
index de7580513..fe21bfc4f 100644
--- a/moli-renderer-v8/src/native_bridge/node.rs
+++ b/moli-renderer-v8/src/native_bridge/node.rs
@@ -20,6 +20,7 @@ use super::{
throw_dom_exception,
};
+mod arguments;
mod bridge_callbacks;
mod character_data;
mod errors;
@@ -28,6 +29,7 @@ mod metadata;
mod mutation;
mod tree;
+pub(super) use self::arguments::*;
pub(super) use self::bridge_callbacks::*;
pub(crate) use self::character_data::install_character_data_template_bindings;
pub(super) use self::character_data::*;
@@ -85,21 +87,21 @@ struct NodePrototypeReflectionDeclaration {
append_child: (),
#[webapi(method, length = 2, callback = node_insert_before_prototype_callback)]
insert_before: (),
- #[webapi(method, length = 1, callback = node_remove_child_prototype_callback)]
+ #[webapi(method, length = 1, callback = node_remove_child_prototype_callback, receiver = web_api_interfaces::Node::is_instance)]
remove_child: (),
#[webapi(method, length = 2, callback = node_replace_child_prototype_callback)]
replace_child: (),
#[webapi(method, length = 0, callback = node_clone_node_callback)]
clone_node: (),
- #[webapi(method, length = 1, callback = node_contains_callback)]
+ #[webapi(method, length = 1, callback = node_contains_callback, receiver = web_api_interfaces::Node::is_instance)]
contains: (),
#[webapi(method, length = 0, callback = node_has_child_nodes_callback)]
has_child_nodes: (),
- #[webapi(method, length = 1, callback = node_is_same_node_callback)]
+ #[webapi(method, length = 1, callback = node_is_same_node_callback, receiver = web_api_interfaces::Node::is_instance)]
is_same_node: (),
- #[webapi(method, length = 1, callback = node_is_equal_node_callback)]
+ #[webapi(method, length = 1, callback = node_is_equal_node_callback, receiver = web_api_interfaces::Node::is_instance)]
is_equal_node: (),
- #[webapi(method, length = 1, callback = node_compare_document_position_callback)]
+ #[webapi(method, length = 1, callback = node_compare_document_position_callback, receiver = web_api_interfaces::Node::is_instance)]
compare_document_position: (),
#[webapi(method, length = 0, callback = node_get_root_node_callback)]
get_root_node: (),
diff --git a/moli-renderer-v8/src/native_bridge/node/arguments.rs b/moli-renderer-v8/src/native_bridge/node/arguments.rs
new file mode 100644
index 000000000..ae43805c0
--- /dev/null
+++ b/moli-renderer-v8/src/native_bridge/node/arguments.rs
@@ -0,0 +1,15 @@
+use super::*;
+
+#[derive(webidl::WebIdlArgs)]
+#[webidl(prefix = "Node")]
+pub(in crate::native_bridge) struct RequiredNodeArgs<'s> {
+ #[webidl(required, interface = web_api_interfaces::Node)]
+ pub node: v8::Local<'s, v8::Object>,
+}
+
+#[derive(webidl::WebIdlArgs)]
+#[webidl(prefix = "Node")]
+pub(in crate::native_bridge) struct NullableNodeArgs<'s> {
+ #[webidl(required, nullable, interface = web_api_interfaces::Node)]
+ pub node: Option<v8::Local<'s, v8::Object>>,
+}
diff --git a/moli-renderer-v8/src/native_bridge/node/mutation/core.rs b/moli-renderer-v8/src/native_bridge/node/mutation/core.rs
index 5e63cc823..a92ed6b4a 100644
--- a/moli-renderer-v8/src/native_bridge/node/mutation/core.rs
+++ b/moli-renderer-v8/src/native_bridge/node/mutation/core.rs
@@ -525,7 +525,10 @@ pub(in crate::native_bridge) fn node_remove_child_callback<'s>(
rv.set_null();
return;
};
- let child = match existing_node_arg(scope, runtime_ptr, args.get(0)) {
+ let Some(parsed) = webidl::parse_args::<RequiredNodeArgs>(scope, &args) else {
+ return;
+ };
+ let child = match existing_node_arg(scope, runtime_ptr, parsed.node.into()) {
ExistingNodeArgument::Handle(child) => child,
ExistingNodeArgument::ForeignNode => {
throw_dom_exception(
diff --git a/moli-renderer-v8/src/native_bridge/node/tree/methods.rs b/moli-renderer-v8/src/native_bridge/node/tree/methods.rs
index efe97a8b5..3decae967 100644
--- a/moli-renderer-v8/src/native_bridge/node/tree/methods.rs
+++ b/moli-renderer-v8/src/native_bridge/node/tree/methods.rs
@@ -1,18 +1,24 @@
use super::*;
-use crate::web_api_interfaces;
-pub(in crate::native_bridge) fn node_contains_callback(
- scope: &mut v8::PinScope<'_, '_>,
- args: v8::FunctionCallbackArguments<'_>,
+pub(in crate::native_bridge) fn node_contains_callback<'s>(
+ scope: &mut v8::PinScope<'s, '_>,
+ args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'_, v8::Value>,
) {
+ let Some(parsed) = webidl::parse_args::<NullableNodeArgs>(scope, &args) else {
+ return;
+ };
+ let Some(other) = parsed.node else {
+ rv.set_bool(false);
+ return;
+ };
let Ok((runtime_ptr, handle)) = node_runtime_and_handle_from_args_or_detached(scope, &args)
else {
throw_incompatible_method_receiver(scope, "Node", "contains");
rv.set_bool(false);
return;
};
- let Some(other) = node_or_existing_detached_arg_handle(scope, runtime_ptr, args.get(0)) else {
+ let Some(other) = node_or_existing_detached_arg_handle(scope, runtime_ptr, other.into()) else {
rv.set_bool(false);
return;
};
@@ -42,34 +48,47 @@ pub(in crate::native_bridge) fn node_has_child_nodes_callback(
rv.set_bool(has_children);
}
-pub(in crate::native_bridge) fn node_is_same_node_callback(
- scope: &mut v8::PinScope<'_, '_>,
- args: v8::FunctionCallbackArguments<'_>,
+pub(in crate::native_bridge) fn node_is_same_node_callback<'s>(
+ scope: &mut v8::PinScope<'s, '_>,
+ args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'_, v8::Value>,
) {
- let Ok((runtime_ptr, handle)) = node_runtime_and_handle_from_args_or_detached(scope, &args)
- else {
- throw_incompatible_method_receiver(scope, "Node", "isSameNode");
+ let Some(parsed) = webidl::parse_args::<NullableNodeArgs>(scope, &args) else {
+ return;
+ };
+ let Some(other) = parsed.node else {
rv.set_bool(false);
return;
};
- rv.set_bool(
- node_or_existing_detached_arg_handle(scope, runtime_ptr, args.get(0)) == Some(handle),
- );
+ let same = args.this().strict_equals(other.into())
+ || node_runtime_and_handle_from_args_or_detached(scope, &args).is_ok_and(
+ |(runtime_ptr, handle)| {
+ node_or_existing_detached_arg_handle(scope, runtime_ptr, other.into())
+ == Some(handle)
+ },
+ );
+ rv.set_bool(same);
}
-pub(in crate::native_bridge) fn node_is_equal_node_callback(
- scope: &mut v8::PinScope<'_, '_>,
- args: v8::FunctionCallbackArguments<'_>,
+pub(in crate::native_bridge) fn node_is_equal_node_callback<'s>(
+ scope: &mut v8::PinScope<'s, '_>,
+ args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'_, v8::Value>,
) {
+ let Some(parsed) = webidl::parse_args::<NullableNodeArgs>(scope, &args) else {
+ return;
+ };
+ let Some(other) = parsed.node else {
+ rv.set_bool(false);
+ return;
+ };
let Ok((runtime_ptr, handle)) = node_runtime_and_handle_from_args_or_detached(scope, &args)
else {
throw_incompatible_method_receiver(scope, "Node", "isEqualNode");
rv.set_bool(false);
return;
};
- let Some(other_handle) = node_or_existing_detached_arg_handle(scope, runtime_ptr, args.get(0))
+ let Some(other_handle) = node_or_existing_detached_arg_handle(scope, runtime_ptr, other.into())
else {
rv.set_bool(false);
return;
@@ -95,6 +114,10 @@ pub(in crate::native_bridge) fn node_compare_document_position_callback<'s>(
const DOCUMENT_POSITION_DISCONNECTED: u32 = 0x01;
const DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC: u32 = 0x20;
+ let Some(parsed) = webidl::parse_args::<RequiredNodeArgs>(scope, &args) else {
+ return;
+ };
+
let Ok((runtime_ptr, handle)) = node_runtime_and_handle_from_args_or_detached(scope, &args)
else {
throw_incompatible_method_receiver(scope, "Node", "compareDocumentPosition");
@@ -104,7 +127,7 @@ pub(in crate::native_bridge) fn node_compare_document_position_callback<'s>(
// Fast path: argument is a Node attached to the same runtime tree.
if let Some(other_handle) =
- node_or_existing_detached_arg_handle(scope, runtime_ptr, args.get(0))
+ node_or_existing_detached_arg_handle(scope, runtime_ptr, parsed.node.into())
{
let runtime = unsafe { &*runtime_ptr };
let relation = match (
@@ -122,29 +145,14 @@ pub(in crate::native_bridge) fn node_compare_document_position_callback<'s>(
// A native Node from another realm or detached document still compares as
// disconnected even when this runtime cannot resolve its live tree handle.
- let other_value = args.get(0);
- if let Ok(other_object) = v8::Local::<v8::Object>::try_from(other_value)
- && web_api_interfaces::Node::is_instance(scope, other_object)
- {
- let order_bit = disconnected_order_bit(args.this(), other_object);
- rv.set(
- v8::Integer::new_from_unsigned(
- scope,
- DOCUMENT_POSITION_DISCONNECTED
- | DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC
- | order_bit,
- )
- .into(),
- );
- return;
- }
-
- // Truly not a Node-like value — throw TypeError per WebIDL.
- let message = v8str(
- scope,
- "Failed to execute 'compareDocumentPosition' on 'Node': parameter 1 is not of type 'Node'.",
+ let order_bit = disconnected_order_bit(args.this(), parsed.node);
+ rv.set(
+ v8::Integer::new_from_unsigned(
+ scope,
+ DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | order_bit,
+ )
+ .into(),
);
- scope.throw_exception(v8::Exception::type_error(scope, message));
}
/// Stable PRECEDING/FOLLOWING choice for two disconnected nodes.
diff --git a/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface/extracted/elements_and_mutations.rs b/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface/extracted/elements_and_mutations.rs
index 30f59bd3a..2add59db7 100644
--- a/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface/extracted/elements_and_mutations.rs
+++ b/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface/extracted/elements_and_mutations.rs
@@ -721,10 +721,16 @@ fn attr_clone_node_copies_attribute_metadata_without_owner() {
liveClone.value
],
methods: [
- methodShape(attr, "isSameNode"),
+ methodShape(Node.prototype, "isSameNode"),
methodShape(attr, "cloneNode"),
methodShape(attr, "lookupNamespaceURI")
],
+ methodInheritance: [
+ Object.hasOwn(attr, "isSameNode"),
+ Object.hasOwn(attrClone, "isSameNode"),
+ attr.isSameNode === Node.prototype.isSameNode,
+ attrClone.isSameNode === Node.prototype.isSameNode
+ ],
methodBehavior: [
attr.isSameNode(attr),
attr.isSameNode(attrClone),
@@ -738,7 +744,7 @@ fn attr_clone_node_copies_attribute_metadata_without_owner() {
assert_eq!(
result,
- r#"{"attr":[true,true,"[object Attr]",2,"data-value","data-value","one",true,"function","one"],"namespaced":[true,"lm:flag","flag","lm","urn:moli:test","two",true],"live":[true,"after",true,true,"lm:item","item","lm","urn:moli:live","after"],"methods":["true:function:isSameNode:0:false:true:true","true:function:cloneNode:0:false:true:true","true:function:lookupNamespaceURI:0:false:true:true"],"methodBehavior":[true,false,"http://www.w3.org/XML/1998/namespace"]}"#
+ r#"{"attr":[true,true,"[object Attr]",2,"data-value","data-value","one",true,"function","one"],"namespaced":[true,"lm:flag","flag","lm","urn:moli:test","two",true],"live":[true,"after",true,true,"lm:item","item","lm","urn:moli:live","after"],"methods":["true:function:isSameNode:1:true:true:true","true:function:cloneNode:0:false:true:true","true:function:lookupNamespaceURI:0:false:true:true"],"methodInheritance":[false,false,true,true],"methodBehavior":[true,false,"http://www.w3.org/XML/1998/namespace"]}"#
);
}
#[test]
diff --git a/moli-renderer-v8/src/script_vm/tests/webidl_receivers/dom.rs b/moli-renderer-v8/src/script_vm/tests/webidl_receivers/dom.rs
index e568a49ca..d67b11625 100644
--- a/moli-renderer-v8/src/script_vm/tests/webidl_receivers/dom.rs
+++ b/moli-renderer-v8/src/script_vm/tests/webidl_receivers/dom.rs
@@ -1,5 +1,33 @@
use super::*;
+#[test]
+fn legacy_node_arguments_use_native_brands_and_callee_realms() {
+ let mut vm = new_parsed_test_vm(
+ "https://node-arguments.test/",
+ "<!doctype html><body><iframe id=child></iframe></body>",
+ );
+ vm.eval(include_str!("node_arguments.js")).unwrap();
+ assert_eq!(
+ vm.eval("JSON.stringify(globalThis.__nodeArgumentResults.failures)")
+ .unwrap(),
+ "[]"
+ );
+}
+
+#[test]
+fn legacy_node_relations_share_native_trees_across_documents() {
+ let mut vm = new_parsed_test_vm(
+ "https://node-relations.test/",
+ "<!doctype html><body><iframe id=child></iframe></body>",
+ );
+ vm.eval(include_str!("node_relations.js")).unwrap();
+ assert_eq!(
+ vm.eval("JSON.stringify(globalThis.__nodeArgumentResults.failures)")
+ .unwrap(),
+ "[]"
+ );
+}
+
#[test]
fn detached_child_window_event_methods_preserve_receiver_identity() {
let mut vm = new_parsed_test_vm(
diff --git a/moli-renderer-v8/src/script_vm/tests/webidl_receivers/node_arguments.js b/moli-renderer-v8/src/script_vm/tests/webidl_receivers/node_arguments.js
new file mode 100644
index 000000000..924ca0769
--- /dev/null
+++ b/moli-renderer-v8/src/script_vm/tests/webidl_receivers/node_arguments.js
@@ -0,0 +1,61 @@
+(() => {
+ const rows = [];
+ const other = document.getElementById('child').contentWindow;
+ const contexts = [
+ ['main', document], ['iframe', other.document],
+ ['windowless', document.implementation.createHTMLDocument('')],
+ ['parsed-html', new DOMParser().parseFromString('<!doctype html><p>x</p>', 'text/html')],
+ ['xml', document.implementation.createDocument('urn:test', 'root')]
+ ];
+ function record(name, expected, run, ErrorClass = TypeError, reads = () => 0) {
+ let value, error;
+ try { value = run(); } catch (e) { error = e; }
+ const actual = error ? {error: error.name, correctRealm: error instanceof ErrorClass} : {value};
+ const pass = expected === 'TypeError' ? !!error && error instanceof ErrorClass && reads() === 0
+ : !error && value === expected && reads() === 0;
+ rows.push({name, expected, actual, reads: reads(), pass});
+ }
+ for (const [context, d] of contexts) {
+ for (const [kind, receiver] of [['element', d.createElement('div')], ['select', d.createElement('select')], ['text', d.createTextNode('x')], ['document', d]]) {
+ for (const method of ['contains', 'isSameNode', 'isEqualNode', 'compareDocumentPosition', 'removeChild']) {
+ for (const [surface, fn, ErrorClass] of [
+ ['own', receiver[method], context === 'iframe' ? other.TypeError : TypeError],
+ ['top-prototype', Node.prototype[method], TypeError],
+ ['iframe-prototype', other.Node.prototype[method], other.TypeError]
+ ]) {
+ const prefix = context + '/' + kind + '/' + method + '/' + surface;
+ record(prefix+'/missing', 'TypeError', () => Reflect.apply(fn, receiver, []), ErrorClass);
+ for (const [label, value] of [['null', null], ['undefined', undefined]]) {
+ record(prefix+'/'+label, method === 'compareDocumentPosition' || method === 'removeChild' ? 'TypeError' : false,
+ () => Reflect.apply(fn, receiver, [value]), ErrorClass);
+ }
+ let reads = 0;
+ const handler = {get() { reads++; throw new Error('author get'); }, getPrototypeOf() { reads++; throw new Error('author prototype'); }};
+ const revoked = Proxy.revocable(receiver, {}); revoked.revoke();
+ const lookalike = {get nodeType() { reads++; return 1; }, get parentNode() { reads++; return receiver; }};
+ const invalids = [['object', {}], ['number', 1], ['string', 'x'], ['symbol', Symbol('x')], ['bigint', 1n],
+ ['prototype', Object.create(Node.prototype)], ['inherited-instance', Object.create(receiver)],
+ ['proxy', new Proxy(receiver, handler)], ['revoked', revoked.proxy], ['lookalike', lookalike]];
+ for (const [label, value] of invalids) {
+ reads = 0;
+ record(prefix+'/'+label, 'TypeError', () => Reflect.apply(fn, receiver, [value]), ErrorClass, () => reads);
+ }
+ if (method !== 'removeChild') {
+ record(prefix+'/self', method === 'compareDocumentPosition' ? 0 : true, () => Reflect.apply(fn, receiver, [receiver]), ErrorClass);
+ record(prefix+'/foreign-node', method === 'compareDocumentPosition' ? true : false,
+ () => { const r = Reflect.apply(fn, receiver, [other.document.createComment('foreign')]); return method === 'compareDocumentPosition' ? (r & 33) === 33 : r; }, ErrorClass);
+ }
+ }
+ }
+ }
+ const attr = d.createAttribute('x');
+ for (const [surface, fn, ErrorClass] of [['own', attr.isSameNode, context === 'iframe' ? other.TypeError : TypeError], ['top-prototype', Node.prototype.isSameNode, TypeError], ['iframe-prototype', other.Node.prototype.isSameNode, other.TypeError]]) {
+ record(context+'/attr/isSameNode/'+surface+'/self', true, () => Reflect.apply(fn, attr, [attr]), ErrorClass);
+ record(context+'/attr/isSameNode/'+surface+'/null', false, () => Reflect.apply(fn, attr, [null]), ErrorClass);
+ record(context+'/attr/isSameNode/'+surface+'/invalid', 'TypeError', () => Reflect.apply(fn, attr, [{}]), ErrorClass);
+ record(context+'/attr/isSameNode/'+surface+'/missing', 'TypeError', () => Reflect.apply(fn, attr, []), ErrorClass);
+ }
+ }
+ globalThis.__nodeArgumentResults = {total: rows.length, passed: rows.filter(r => r.pass).length, failures: rows.filter(r => !r.pass), rows};
+ return rows.every(r => r.pass);
+})()
diff --git a/moli-renderer-v8/src/script_vm/tests/webidl_receivers/node_relations.js b/moli-renderer-v8/src/script_vm/tests/webidl_receivers/node_relations.js
new file mode 100644
index 000000000..d6fa23824
--- /dev/null
+++ b/moli-renderer-v8/src/script_vm/tests/webidl_receivers/node_relations.js
@@ -0,0 +1,64 @@
+(() => {
+ const childWindow = document.getElementById('child').contentWindow;
+ const documents = [document, childWindow.document, document.implementation.createHTMLDocument(''), new DOMParser().parseFromString('<p></p>', 'text/html'), document.implementation.createDocument('urn:root', 'root')];
+ const rows = [];
+ const check = (name, expected, run) => {
+ try { const actual = run(); rows.push({name, expected, actual, pass: actual === expected}); }
+ catch (e) { rows.push({name, expected, error: e.name, pass: false}); }
+ };
+ function tree(d) {
+ const root = d.createElementNS('urn:test', 'p:item');
+ root.setAttributeNS('urn:attribute', 'a:key', 'value');
+ root.appendChild(d.createTextNode('text'));
+ root.appendChild(d.createComment('comment'));
+ return root;
+ }
+ for (let i = 0; i < documents.length; i++) {
+ for (let j = 0; j < documents.length; j++) {
+ const left = tree(documents[i]), right = tree(documents[j]);
+ let reads = 0;
+ for (const node of [left, right]) {
+ for (const key of ['nodeType', 'nodeName', 'parentNode', 'childNodes', 'ownerDocument']) {
+ Object.defineProperty(node, key, {get() { reads++; throw new Error('public property read'); }, configurable: true});
+ }
+ }
+ for (const [realm, methods] of [['own', left], ['top', Node.prototype], ['iframe', childWindow.Node.prototype]]) {
+ const prefix = i+'/'+j+'/'+realm;
+ check(prefix+'/equal', true, () => methods.isEqualNode.call(left, right));
+ check(prefix+'/same', false, () => methods.isSameNode.call(left, right));
+ check(prefix+'/contains', false, () => methods.contains.call(left, right));
+ check(prefix+'/disconnected', true, () => (methods.compareDocumentPosition.call(left, right) & 33) === 33);
+ check(prefix+'/child-contains', true, () => methods.contains.call(left, left.firstChild));
+ check(prefix+'/child-position', 20, () => methods.compareDocumentPosition.call(left, left.firstChild));
+ check(prefix+'/no-public-property-reads', 0, () => reads);
+ }
+ right.firstChild.data = 'changed';
+ check(i+'/'+j+'/changed-child', false, () => left.isEqualNode(right));
+ }
+ const parent = documents[i].createElement('div');
+ const child = parent.appendChild(documents[i].createElement('span'));
+ const observer = new MutationObserver(() => {});
+ observer.observe(parent, {childList:true});
+ check(i+'/remove-return', child, () => parent.removeChild(child));
+ check(i+'/remove-parent', null, () => child.parentNode);
+ const records = observer.takeRecords();
+ check(i+'/remove-record-count', 1, () => records.length);
+ check(i+'/remove-record-node', child, () => records[0].removedNodes[0]);
+ observer.disconnect();
+ }
+ for (const [realm, w] of [['top', window], ['iframe', childWindow]]) {
+ for (const method of ['contains', 'isSameNode', 'isEqualNode', 'compareDocumentPosition', 'removeChild']) {
+ const node = document.createElement('div');
+ const revoked = Proxy.revocable(node, {}); revoked.revoke();
+ for (const [kind, receiver] of [['object', {}], ['prototype', Object.create(Node.prototype)], ['inherited', Object.create(node)], ['proxy', new Proxy(node,{})], ['revoked',revoked.proxy], ['null',null]]) {
+ check(realm+'/'+method+'/receiver-'+kind, true, () => {
+ try { Reflect.apply(w.Node.prototype[method], receiver, [node]); return false; }
+ catch(e) { return e instanceof w.TypeError; }
+ });
+ }
+ }
+ }
+ // Store boolean results for identity checks so the evidence does not retain DOM objects.
+ globalThis.__nodeArgumentResults = {total:rows.length, passed:rows.filter(r=>r.pass).length, failures:rows.filter(r=>!r.pass).map(({name,error})=>({name,error})), rows:rows.map(({name,pass,error})=>({name,pass,error}))};
+ return rows.every(r=>r.pass);
+})()