mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-31 13:19:05 +00:00
LibWeb: Use correct factory function when cloning a Document node
Cloning an XMLDocument should produce a new XMLDocument. Same for HTMLDocument. This fixes at least one WPT test, which we're also importing. :^)
This commit is contained in:
parent
24a6fd3d76
commit
564dc0a434
Notes:
github-actions[bot]
2024-11-19 19:25:40 +00:00
Author: https://github.com/awesomekling
Commit: 564dc0a434
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2441
Reviewed-by: https://github.com/tcl3 ✅
3 changed files with 51 additions and 1 deletions
|
@ -32,8 +32,10 @@
|
||||||
#include <LibWeb/DOM/Range.h>
|
#include <LibWeb/DOM/Range.h>
|
||||||
#include <LibWeb/DOM/ShadowRoot.h>
|
#include <LibWeb/DOM/ShadowRoot.h>
|
||||||
#include <LibWeb/DOM/StaticNodeList.h>
|
#include <LibWeb/DOM/StaticNodeList.h>
|
||||||
|
#include <LibWeb/DOM/XMLDocument.h>
|
||||||
#include <LibWeb/HTML/CustomElements/CustomElementReactionNames.h>
|
#include <LibWeb/HTML/CustomElements/CustomElementReactionNames.h>
|
||||||
#include <LibWeb/HTML/HTMLAnchorElement.h>
|
#include <LibWeb/HTML/HTMLAnchorElement.h>
|
||||||
|
#include <LibWeb/HTML/HTMLDocument.h>
|
||||||
#include <LibWeb/HTML/HTMLImageElement.h>
|
#include <LibWeb/HTML/HTMLImageElement.h>
|
||||||
#include <LibWeb/HTML/HTMLInputElement.h>
|
#include <LibWeb/HTML/HTMLInputElement.h>
|
||||||
#include <LibWeb/HTML/HTMLSelectElement.h>
|
#include <LibWeb/HTML/HTMLSelectElement.h>
|
||||||
|
@ -1021,7 +1023,16 @@ WebIDL::ExceptionOr<GC::Ref<Node>> Node::clone_node(Document* document, bool clo
|
||||||
else if (is<Document>(this)) {
|
else if (is<Document>(this)) {
|
||||||
// Document
|
// Document
|
||||||
auto document_ = verify_cast<Document>(this);
|
auto document_ = verify_cast<Document>(this);
|
||||||
auto document_copy = Document::create(this->realm(), document_->url());
|
auto document_copy = [&] -> GC::Ref<Document> {
|
||||||
|
switch (document_->document_type()) {
|
||||||
|
case Document::Type::XML:
|
||||||
|
return XMLDocument::create(realm(), document_->url());
|
||||||
|
case Document::Type::HTML:
|
||||||
|
return HTML::HTMLDocument::create(realm(), document_->url());
|
||||||
|
default:
|
||||||
|
return Document::create(realm(), document_->url());
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
|
||||||
// Set copy’s encoding, content type, URL, origin, type, and mode to those of node.
|
// Set copy’s encoding, content type, URL, origin, type, and mode to those of node.
|
||||||
document_copy->set_encoding(document_->encoding());
|
document_copy->set_encoding(document_->encoding());
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
Summary
|
||||||
|
|
||||||
|
Harness status: OK
|
||||||
|
|
||||||
|
Rerun
|
||||||
|
|
||||||
|
Found 1 tests
|
||||||
|
|
||||||
|
1 Pass
|
||||||
|
Details
|
||||||
|
Result Test Name MessagePass Created with createDocument
|
|
@ -0,0 +1,28 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Cloning of an XMLDocument</title>
|
||||||
|
<link rel="help" href="https://dom.spec.whatwg.org/#dom-node-clonenode">
|
||||||
|
<link rel="help" href="https://dom.spec.whatwg.org/#concept-node-clone">
|
||||||
|
|
||||||
|
<!-- This is testing in particular "that implements the same interfaces as node" -->
|
||||||
|
|
||||||
|
<script src="../../resources/testharness.js"></script>
|
||||||
|
<script src="../../resources/testharnessreport.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
test(() => {
|
||||||
|
const doc = document.implementation.createDocument("namespace", "");
|
||||||
|
|
||||||
|
assert_equals(
|
||||||
|
doc.constructor, XMLDocument,
|
||||||
|
"Precondition check: document.implementation.createDocument() creates an XMLDocument"
|
||||||
|
);
|
||||||
|
|
||||||
|
const clone = doc.cloneNode(true);
|
||||||
|
|
||||||
|
assert_equals(clone.constructor, XMLDocument);
|
||||||
|
}, "Created with createDocument");
|
||||||
|
|
||||||
|
</script>
|
Loading…
Add table
Add a link
Reference in a new issue