To allow interop with scripts which depend on “root” xmldom.
export {
DOMImplementation,
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";
export { xhtmlNamespace } from "../names.js";
// 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/>.
// 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(
{ // Polyfill document.
globalThis.document = new DOMImplementation().createDocument(
}
{ // Apply patches to `Node.nodeType` and `Node.normalize`.
}
{ // 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",
const originalNodeTypeGetter = Object.getOwnPropertyDescriptor(
nodePrototype,
"nodeType",
* Nodes, check for inheritance first.
*/
get() {
* 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 {
// This is not a Node.
throw new TypeError("nodeType requires this be a Node.");
} else {
let child = this.firstChild;
while (child) {
const next = child.nextSibling;
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 {
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.removeChild(child);
} else {
child.normalize();