LibWeb: Add implementation of Node.compareDocumentPosition()

While looking into getting Duck Duck Go loading further in the
Browser, I noticed that it was complaining about the missing
method Node.compareDocumentPosition.

This change implements as much of the DOM spec as possible
with the current implementation of the DOM to date. The
implementation is validated by new tests in the Node.js.
This commit is contained in:
Brian Gianforcaro 2021-04-10 17:21:22 -07:00 committed by Andreas Kling
commit 988c23fff0
Notes: sideshowbarker 2024-07-18 20:33:23 +09:00
4 changed files with 69 additions and 0 deletions

View file

@ -36,4 +36,27 @@ afterInitialPageLoad(() => {
document.body.removeChild(element);
expect(element.isConnected).toBeFalse();
});
test("Node.compareDocumentPosition()", () => {
const head = document.head;
const body = document.body;
expect(head.compareDocumentPosition(head)).toBe(0);
// FIXME: Can be uncommented once the IDL parser correctly implements nullable paramaters.
// expect(head.compareDocumentPosition(null) & Node.DOCUMENT_POSITION_DISCONNECTED | Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC).
// toBe(Node.DOCUMENT_POSITION_DISCONNECTED | Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC);
expect(head.compareDocumentPosition(body)).toBe(Node.DOCUMENT_POSITION_FOLLOWING);
expect(body.compareDocumentPosition(head)).toBe(Node.DOCUMENT_POSITION_PRECEDING);
const source = document.getElementById("source");
expect(source.compareDocumentPosition(body)).toBe(
Node.DOCUMENT_POSITION_CONTAINS | Node.DOCUMENT_POSITION_PRECEDING
);
expect(body.compareDocumentPosition(source)).toBe(
Node.DOCUMENT_POSITION_CONTAINED_BY | Node.DOCUMENT_POSITION_FOLLOWING
);
expect(source.compareDocumentPosition(head)).toBe(Node.DOCUMENT_POSITION_PRECEDING);
});
});