aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2023-09-03 07:54:34 +0200
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2023-09-03 07:54:34 +0200
commit9ed85cff5eb3783efc25c070f07b6bcf71c44e07 (patch)
treef9ebf93af733e9fb165e0d3bf32b37b9f6d906d3
parent93f2298510c46d4453e182bd244d07e46f818bd6 (diff)
downloadsvg.js-9ed85cff5eb3783efc25c070f07b6bcf71c44e07.tar.gz
svg.js-9ed85cff5eb3783efc25c070f07b6bcf71c44e07.zip
allow nodes that are not imported yet (fixes #1252)
-rw-r--r--spec/spec/utils/adopter.js13
-rw-r--r--src/utils/adopter.js5
2 files changed, 16 insertions, 2 deletions
diff --git a/spec/spec/utils/adopter.js b/spec/spec/utils/adopter.js
index 3c12790..b158be5 100644
--- a/spec/spec/utils/adopter.js
+++ b/spec/spec/utils/adopter.js
@@ -22,6 +22,7 @@ import {
import { mockAdopt, assignNewId, adopt } from '../../../src/utils/adopter.js'
import { buildFixtures } from '../../helpers.js'
import { globals, getWindow } from '../../../src/utils/window.js'
+import { svg } from '../../../src/modules/core/namespaces.js'
const { any, createSpy, objectContaining } = jasmine
@@ -172,6 +173,18 @@ describe('adopter.js', () => {
// jasmine chucks on this when using the node directly
expect(node.outerHTML).toBe(div.outerHTML)
})
+
+ it('gracefully handles nodes that are not yet imported into the document', () => {
+ const otherDoc = globals.document.implementation.createDocument(
+ svg,
+ 'svg'
+ )
+ const rect = otherDoc.createElementNS(svg, 'rect')
+
+ const node = nodeOrNew('rect', rect)
+
+ expect(node).toEqual(rect)
+ })
})
describe('register()/getClass()', () => {
diff --git a/src/utils/adopter.js b/src/utils/adopter.js
index 48814ec..962412f 100644
--- a/src/utils/adopter.js
+++ b/src/utils/adopter.js
@@ -43,8 +43,9 @@ export function makeInstance(element, isHTML = false) {
export function nodeOrNew(name, node) {
return node &&
- node.ownerDocument &&
- node instanceof node.ownerDocument.defaultView.Node
+ (node instanceof globals.window.Node ||
+ (node.ownerDocument &&
+ node instanceof node.ownerDocument.defaultView.Node))
? node
: create(name)
}