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:
Tim Ledbetter 2024-07-17 14:42:45 +01:00 committed by Alexander Kalenik
commit 055c902a37
Notes: sideshowbarker 2024-07-18 23:46:11 +09:00
5 changed files with 59 additions and 1 deletions

View file

@ -1733,6 +1733,20 @@ Optional<String> Node::lookup_namespace_uri(Optional<String> prefix) const
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
bool Node::in_a_document_tree() const
{