mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-06 16:19:23 +00:00
LibWeb: Implement Node.isDefaultNamespace()
This method accepts a namespace URI as an argument and returns true if the given URI is the default namespace on the given node, false otherwise.
This commit is contained in:
parent
27d429a85f
commit
055c902a37
Notes:
sideshowbarker
2024-07-18 23:46:11 +09:00
Author: https://github.com/tcl3
Commit: 055c902a37
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/693
5 changed files with 59 additions and 1 deletions
12
Tests/LibWeb/Text/expected/DOM/Node-isDefaultNamespace.txt
Normal file
12
Tests/LibWeb/Text/expected/DOM/Node-isDefaultNamespace.txt
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
documentFragment.isDefaultNamespace(null): true
|
||||||
|
documentFragment.isDefaultNamespace(""): true
|
||||||
|
documentFragment.isDefaultNamespace("foo"): false
|
||||||
|
documentFragment.isDefaultNamespace("xmlms"): false
|
||||||
|
docType.isDefaultNamespace(null): true
|
||||||
|
docType.isDefaultNamespace(""): true
|
||||||
|
docType.isDefaultNamespace("foo"): false
|
||||||
|
docType.isDefaultNamespace("xmlms"): false
|
||||||
|
element.isDefaultNamespace(null): true
|
||||||
|
element.isDefaultNamespace(""): true
|
||||||
|
element.isDefaultNamespace("foo"): false
|
||||||
|
element.isDefaultNamespace("xmlms"): false
|
31
Tests/LibWeb/Text/input/DOM/Node-isDefaultNamespace.html
Normal file
31
Tests/LibWeb/Text/input/DOM/Node-isDefaultNamespace.html
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<script>
|
||||||
|
function testIsDefaultNamespace(node, prefix, name) {
|
||||||
|
let prefixName = prefix;
|
||||||
|
if (prefixName !== null)
|
||||||
|
prefixName = `"${prefix}"`;
|
||||||
|
|
||||||
|
println(`${name}.isDefaultNamespace(${prefixName}): ${node.isDefaultNamespace(prefix)}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
test(() => {
|
||||||
|
const documentFragment = document.createDocumentFragment();
|
||||||
|
testIsDefaultNamespace(documentFragment, null, "documentFragment");
|
||||||
|
testIsDefaultNamespace(documentFragment, "", "documentFragment");
|
||||||
|
testIsDefaultNamespace(documentFragment, "foo", "documentFragment");
|
||||||
|
testIsDefaultNamespace(documentFragment, "xmlms", "documentFragment");
|
||||||
|
|
||||||
|
const docType = document.doctype;
|
||||||
|
testIsDefaultNamespace(docType, null, "docType");
|
||||||
|
testIsDefaultNamespace(docType, "", "docType");
|
||||||
|
testIsDefaultNamespace(docType, "foo", "docType");
|
||||||
|
testIsDefaultNamespace(docType, "xmlms", "docType");
|
||||||
|
|
||||||
|
const element = document.createElementNS("namespace", "prefix:element");
|
||||||
|
testIsDefaultNamespace(element, null, "element");
|
||||||
|
testIsDefaultNamespace(element, "", "element");
|
||||||
|
testIsDefaultNamespace(element, "foo", "element");
|
||||||
|
testIsDefaultNamespace(element, "xmlms", "element");
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -1733,6 +1733,20 @@ Optional<String> Node::lookup_namespace_uri(Optional<String> prefix) const
|
||||||
return locate_a_namespace(prefix);
|
return locate_a_namespace(prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://dom.spec.whatwg.org/#dom-node-isdefaultnamespace
|
||||||
|
bool Node::is_default_namespace(Optional<String> namespace_) const
|
||||||
|
{
|
||||||
|
// 1. If namespace is the empty string, then set it to null.
|
||||||
|
if (namespace_.has_value() && namespace_->is_empty())
|
||||||
|
namespace_ = {};
|
||||||
|
|
||||||
|
// 2. Let defaultNamespace be the result of running locate a namespace for this using null.
|
||||||
|
auto default_namespace = locate_a_namespace({});
|
||||||
|
|
||||||
|
// 3. Return true if defaultNamespace is the same as namespace; otherwise false.
|
||||||
|
return default_namespace == namespace_;
|
||||||
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#in-a-document-tree
|
// https://dom.spec.whatwg.org/#in-a-document-tree
|
||||||
bool Node::in_a_document_tree() const
|
bool Node::in_a_document_tree() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -697,6 +697,7 @@ public:
|
||||||
|
|
||||||
Optional<String> locate_a_namespace(Optional<String> const& prefix) const;
|
Optional<String> locate_a_namespace(Optional<String> const& prefix) const;
|
||||||
Optional<String> lookup_namespace_uri(Optional<String> prefix) const;
|
Optional<String> lookup_namespace_uri(Optional<String> prefix) const;
|
||||||
|
bool is_default_namespace(Optional<String> namespace_) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Node(JS::Realm&, Document&, NodeType);
|
Node(JS::Realm&, Document&, NodeType);
|
||||||
|
|
|
@ -56,7 +56,7 @@ interface Node : EventTarget {
|
||||||
|
|
||||||
[FIXME] DOMString? lookupPrefix(DOMString? namespace);
|
[FIXME] DOMString? lookupPrefix(DOMString? namespace);
|
||||||
DOMString? lookupNamespaceURI(DOMString? prefix);
|
DOMString? lookupNamespaceURI(DOMString? prefix);
|
||||||
[FIXME] boolean isDefaultNamespace(DOMString? namespace);
|
boolean isDefaultNamespace(DOMString? namespace);
|
||||||
|
|
||||||
[ImplementedAs=pre_insert, CEReactions] Node insertBefore(Node node, Node? child);
|
[ImplementedAs=pre_insert, CEReactions] Node insertBefore(Node node, Node? child);
|
||||||
[CEReactions] Node appendChild(Node node);
|
[CEReactions] Node appendChild(Node node);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue