]> Lady’s Gitweb - Lemon/commitdiff
[window] Don’t use xmldom/lib/dom.js 0.2.1
authorLady <redacted>
Sun, 7 Aug 2022 06:09:03 +0000 (23:09 -0700)
committerLady <redacted>
Sat, 29 Apr 2023 03:36:54 +0000 (20:36 -0700)
To allow interop with scripts which depend on “root” xmldom.

window/deps.js
window/mod.js

index f1d423778c81330a8df591dae3626226f3a40a45..f78b74cd5990e1741a802423639a62c6e9b6cb2a 100644 (file)
@@ -9,6 +9,5 @@
 
 export {
   DOMImplementation,
-  Node,
-} from "https://esm.sh/@xmldom/xmldom@0.8.2/lib/dom.js";
+} from "https://esm.sh/@xmldom/xmldom@0.8.2";
 export { xhtmlNamespace } from "../names.js";
index 5e97d4f2af8e289dc45496f943192f12056db703..9ddbf4bd6055ddbedfd50140a1dc8c946b9de367 100644 (file)
@@ -7,7 +7,7 @@
 // License, v. 2.0. If a copy of the MPL was not distributed with this
 // file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
 
-import { DOMImplementation, Node, xhtmlNamespace } from "./deps.js";
+import { DOMImplementation, xhtmlNamespace } from "./deps.js";
 
 { // Polyfill document.
   globalThis.document = new DOMImplementation().createDocument(
@@ -39,7 +39,9 @@ import { DOMImplementation, Node, xhtmlNamespace } from "./deps.js";
 }
 
 { // Apply patches to `Node.nodeType` and `Node.normalize`.
-  const { TEXT_NODE, prototype: nodePrototype } = Node;
+  const nodePrototype = Object.getPrototypeOf(
+    Object.getPrototypeOf(document.createDocumentFragment()),
+  );
   const originalNodeTypeGetter = Object.getOwnPropertyDescriptor(
     nodePrototype,
     "nodeType",
@@ -55,7 +57,28 @@ import { DOMImplementation, Node, xhtmlNamespace } from "./deps.js";
      * Nodes, check for inheritance first.
      */
     get() {
-      if (!(this instanceof Node)) {
+      if (
+        !(() => {
+          // Test whether this object has the node prototype in its
+          // prototype chain.
+          for (
+            let prototype = this === Object(this)
+              ? Object.getPrototypeOf(this)
+              : null;
+            prototype != null;
+            prototype = Object.getPrototypeOf(prototype)
+          ) {
+            if (prototype === nodePrototype) {
+              // This object inherits from the Node prototype.
+              return true;
+            } else {
+              // This object is not yet known to inherits from the Node
+              // prototype.
+              continue;
+            }
+          }
+        })()
+      ) {
         // This is not a Node.
         throw new TypeError("nodeType requires this be a Node.");
       } else {
@@ -82,14 +105,11 @@ import { DOMImplementation, Node, xhtmlNamespace } from "./deps.js";
     let child = this.firstChild;
     while (child) {
       const next = child.nextSibling;
-      if (
-        next && next.nodeType == TEXT_NODE &&
-        child.nodeType == TEXT_NODE
-      ) {
+      if (next && next.nodeType == 3 && child.nodeType == 3) {
         this.removeChild(next);
         child.appendData(next.data);
       } else {
-        if (child.nodeType == TEXT_NODE && !child.data) {
+        if (child.nodeType == 3 && !child.data) {
           this.removeChild(child);
         } else {
           child.normalize();
This page took 0.022784 seconds and 4 git commands to generate.