Skip to content

Commit 4f2191d

Browse files
committed
bringing back Dav's ownerDocument fixes...
2 parents abdc0df + 19d218a commit 4f2191d

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/jsdom/level2/events.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ core.Node.prototype.__proto__ = events.EventTarget.prototype;
287287
(function(level1) {
288288
core.Node.prototype.appendChild = function(newChild) {
289289
var ret = level1.call(this, newChild);
290-
if (this.nodeType == 1) {
290+
if (this.nodeType == 1 && this.ownerDocument) {
291291
var ev = this.ownerDocument.createEvent("MutationEvents");
292292
ev.initMutationEvent("DOMNodeInserted", true, false, this, null, null, null, null);
293293
newChild.dispatchEvent(ev);
@@ -299,9 +299,11 @@ core.Node.prototype.__proto__ = events.EventTarget.prototype;
299299
// Wrap the level-1 implementation of removeChild() to dispatch a DOMNodeRemoved event
300300
(function(level1) {
301301
core.Node.prototype.removeChild = function(oldChild) {
302-
var ev = this.ownerDocument.createEvent("MutationEvents");
303-
ev.initMutationEvent("DOMNodeRemoved", true, false, this, null, null, null, null);
304-
oldChild.dispatchEvent(ev);
302+
if (this.ownerDocument) {
303+
var ev = this.ownerDocument.createEvent("MutationEvents");
304+
ev.initMutationEvent("DOMNodeRemoved", true, false, this, null, null, null, null);
305+
oldChild.dispatchEvent(ev);
306+
}
305307
return level1.call(this, oldChild);
306308
};
307309
})(core.Node.prototype.removeChild);

0 commit comments

Comments
 (0)