From: Lady <redacted>
Date: Sun, 7 Aug 2022 20:29:55 +0000 (-0700)
Subject: [window] Polyfill top‐level D·O·M interfaces
X-Git-Tag: 0.2.2^0
X-Git-Url: https://git.ladys.computer/Lemon/commitdiff_plain/refs/heads/current?ds=sidebyside

[window] Polyfill top‐level D·O·M interfaces
---

diff --git a/window/deps.js b/window/deps.js
index f78b74c..b7de3f4 100644
--- a/window/deps.js
+++ b/window/deps.js
@@ -9,5 +9,7 @@
 
 export {
   DOMImplementation,
+  DOMParser,
+  XMLSerializer,
 } from "https://esm.sh/@xmldom/xmldom@0.8.2";
 export { xhtmlNamespace } from "../names.js";
diff --git a/window/mod.js b/window/mod.js
index 9ddbf4b..82be590 100644
--- a/window/mod.js
+++ b/window/mod.js
@@ -7,7 +7,20 @@
 // 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, xhtmlNamespace } from "./deps.js";
+import {
+  DOMImplementation,
+  DOMParser,
+  xhtmlNamespace,
+  XMLSerializer,
+} from "./deps.js";
+
+{ // Polyfill global interfaces.
+  Object.assign(globalThis, {
+    DOMImplementation,
+    DOMParser,
+    XMLSerializer,
+  });
+}
 
 { // Polyfill document.
   globalThis.document = new DOMImplementation().createDocument(
@@ -24,7 +37,7 @@ import { DOMImplementation, xhtmlNamespace } from "./deps.js";
   );
 }
 
-{ // Polyfill `element.append`.
+{ // Polyfill Element::append.
   Object.getPrototypeOf(
     globalThis.document.documentElement,
   ).append = function (...children) {
@@ -38,7 +51,7 @@ import { DOMImplementation, xhtmlNamespace } from "./deps.js";
   };
 }
 
-{ // Apply patches to `Node.nodeType` and `Node.normalize`.
+{ // Apply patches to Node::nodeType and Node::normalize.
   const nodePrototype = Object.getPrototypeOf(
     Object.getPrototypeOf(document.createDocumentFragment()),
   );
@@ -46,7 +59,7 @@ import { DOMImplementation, xhtmlNamespace } from "./deps.js";
     nodePrototype,
     "nodeType",
   )?.get ?? (() => {
-    const originalNodeTypeValue = nodePrototype.nodeType;
+    const { nodeType: originalNodeTypeValue } = nodePrototype;
     return () => originalNodeTypeValue;
   })();
   Object.defineProperty(nodePrototype, "nodeType", {