LibWeb/DOM: Implement Node.lookupPrefix

Adds https://dom.spec.whatwg.org/#dom-node-lookupprefix
This commit is contained in:
Ángel Carias 2024-07-27 12:51:36 -06:00 committed by Tim Ledbetter
commit 9624e0d2a2
Notes: github-actions[bot] 2024-07-27 23:52:45 +00:00
7 changed files with 109 additions and 1 deletions

View file

@ -0,0 +1,21 @@
<!DOCTYPE html>
<script src="../include.js"></script>
<script>
test(() => {
const xmlDoc = new DOMParser().parseFromString(`<root xmlns:ex="test"><!--abc--><child xmlns:abc="def" x="1"></child></root>`, "application/xml");
const fragment = document.createDocumentFragment();
println(`Prefix for namespace "test" on document: ${xmlDoc.lookupPrefix("test")}`);
println(`Prefix for namespace "test" on document fragment: ${fragment.lookupPrefix("test")}`);
println(`Prefix for namespace "test" on comment node 0: ${xmlDoc.childNodes[0].lookupPrefix("test")}`);
println(`Prefix null on document: ${xmlDoc.lookupPrefix(null)}`);
println(`Prefix for absent namespace "no" on document: ${xmlDoc.lookupPrefix("no")}`);
const child = xmlDoc.querySelector("child");
println(`Prefix for namespace "def" on child: ${child.lookupPrefix("def")}`);
println(`Prefix null on child: ${child.lookupPrefix(null)}`);
println(`Prefix for namespace "test" (in parent) on child: ${child.lookupPrefix("test")}`);
const attrX = child.getAttributeNode("x");
println(`Prefix for namespace "def" (from attribute "x") on child: ${attrX.lookupPrefix("def")}`);
});
</script>