fix(dom): preserve document content types for element creation

Resolve the default element namespace from internal Document metadata instead
of the current root element. Initialize native and detached MIME state together
and preserve it when cloning, without reading overwritten public properties.

Cover parser MIME types, root replacement, shallow/deep clones, explicit
namespaces and getter overrides with 689 shared browser/Rust assertions.
Document-createElement-namespace.html now passes all 51 subtests; all 13
related upstream cases pass (1438 subtests).

Validation: cargo fmt --all; workspace/all-targets/all-features Clippy with
-D warnings; cargo nextest run --no-fail-fast (19463 passed, 13 skipped).
This commit is contained in:
ldm0
2026-09-23 09:18:27 +08:00
parent 65252693ef
commit fd2aef664b
3 changed files with 17 additions and 0 deletions
@@ -4354,6 +4354,7 @@ dom/nodes/Document-contentType/contentType/xhr_responseType_document.html
dom/nodes/Document-createAttribute.html
dom/nodes/Document-createCDATASection.html
dom/nodes/Document-createComment.html
dom/nodes/Document-createElement-namespace.html
dom/nodes/Document-createElement.html
dom/nodes/Document-createElementNS.html
dom/nodes/Document-createProcessingInstruction.html
@@ -263,6 +263,9 @@ pub(super) use detached_surface::{
detached_character_data_value, detached_text_split_text_callback,
detached_text_whole_text_value, set_detached_character_data_value,
};
pub(in crate::native_bridge::document) use detached_surface::{
detached_document_content_type_value, set_detached_document_content_type,
};
pub(in crate::native_bridge) use detached_surface::{
detached_element_local_name, detached_element_namespace_uri, detached_element_prefix,
};
@@ -12,6 +12,19 @@ fn detached_document_shallow_clones_are_empty_and_accept_a_new_root() {
assert_eq!(result["checks"], 245);
}
#[test]
fn detached_document_content_type_controls_element_creation_after_root_mutations_and_cloning() {
let mut vm = new_storage_test_vm("https://document-create-element-content-type.test/");
let fixture =
include_str!("../../../../tests/fixtures/document-create-element-content-type.js");
let result = vm
.eval(&format!("JSON.stringify({fixture})"))
.expect("Document content type and element creation probe should evaluate");
let result: serde_json::Value = serde_json::from_str(&result).unwrap();
assert_eq!(result["failures"], serde_json::json!([]), "{result}");
assert_eq!(result["checks"], 689);
}
#[test]
fn detached_domparser_parses_noscript_with_scripting_disabled() {
let mut vm = new_storage_test_vm("https://detached-domparser-noscript.test/");