fix(dom): validate Document pre-insertion before mutation

Use existing pre-insert validation before appendChild enters the native
mutation pipeline. Keep existing Document roots and doctypes in the
validation sequence for appendChild and insertBefore, including the
detached bridge, so rejected insertions have no removal/adoption effects.

Cover main, child, windowless HTML/XML and parsed documents through
ordinary and borrowed methods, invalid fragments and root reinsertion,
allowed comment/PI/empty-fragment insertion, unchanged live ranges,
MutationObserver records and custom-element reactions. Extend the prior
fragment regression to main/iframe Document validation.

Initialize affected legacy fixtures with a legal HTML document shell
and reuse existing roots in page fixtures. Preserve their feature
assertions while removing reliance on multiple Document elements.

Validation: cargo fmt --all; strict workspace/all-targets/all-features
clippy; cargo nextest run --no-fail-fast (32 threads, CI retry profile).
Summary [ 238.939s] 20631 tests run: 20631 passed (20 slow, 2 flaky), 16 skipped
This commit is contained in:
ldm0
2026-11-24 14:36:21 +08:00
parent 542f450315
commit 5e46ccae53
3 changed files with 6 additions and 10 deletions
@@ -1848,10 +1848,8 @@ async fn form_target_blank_preserves_source_referrer_and_relations() {
globalThis.results = [];
globalThis.channel = new BroadcastChannel("form-popup-relations");
channel.onmessage = event => results.push(event.data);
const html = document.createElement("html");
const body = document.createElement("body");
html.appendChild(body);
document.appendChild(html);
const html = document.documentElement || document.appendChild(document.createElement("html"));
const body = document.body || html.appendChild(document.createElement("body"));
if ({child_document}) {{
globalThis.frame = document.createElement("iframe");
frame.src = {child_url:?};
@@ -1967,10 +1965,8 @@ async fn popup_navigation_applies_referrer_policy_and_link_overrides() {
r#"
globalThis.results = [];
onmessage = event => results.push(event.data);
const html = document.createElement("html");
const body = document.createElement("body");
html.appendChild(body);
document.appendChild(html);
const html = document.documentElement || document.appendChild(document.createElement("html"));
const body = document.body || html.appendChild(document.createElement("body"));
const element = document.createElement({tag:?});
element.target = "_blank";
element.rel = "opener";
@@ -4158,7 +4158,7 @@ fn reattaching_iframe_does_not_resurrect_retired_window_relations() {
#[test]
fn explicit_about_blank_iframe_variants_reuse_initial_empty_document_synchronously() {
let mut vm = new_storage_test_vm("https://iframe-explicit-initial-blank.test/page.html");
let mut vm = new_storage_html_test_vm("https://iframe-explicit-initial-blank.test/page.html");
let result = vm
.eval(
@@ -2263,7 +2263,7 @@ fn location_ancestor_origins_is_a_stable_document_list_with_a_detached_empty_lis
#[test]
fn location_ancestor_origins_snapshots_frame_referrer_policy_per_navigation() {
let mut vm = new_storage_test_vm("https://ancestor-policy.test/page.html");
let mut vm = new_storage_html_test_vm("https://ancestor-policy.test/page.html");
let initial = vm
.eval(