Skip to content
Browse files

bringing back Dav's ownerDocument fixes...

  • Loading branch information...
2 parents abdc0df + 19d218a commit 4f2191df8da743669b68f2a2894ce94f2a541e1c @tmpvar committed
Showing with 6 additions and 4 deletions.
  1. +6 −4 lib/jsdom/level2/events.js
View
10 lib/jsdom/level2/events.js
@@ -287,7 +287,7 @@ core.Node.prototype.__proto__ = events.EventTarget.prototype;
(function(level1) {
core.Node.prototype.appendChild = function(newChild) {
var ret = level1.call(this, newChild);
- if (this.nodeType == 1) {
+ if (this.nodeType == 1 && this.ownerDocument) {
var ev = this.ownerDocument.createEvent("MutationEvents");
ev.initMutationEvent("DOMNodeInserted", true, false, this, null, null, null, null);
newChild.dispatchEvent(ev);
@@ -299,9 +299,11 @@ core.Node.prototype.__proto__ = events.EventTarget.prototype;
// Wrap the level-1 implementation of removeChild() to dispatch a DOMNodeRemoved event
(function(level1) {
core.Node.prototype.removeChild = function(oldChild) {
- var ev = this.ownerDocument.createEvent("MutationEvents");
- ev.initMutationEvent("DOMNodeRemoved", true, false, this, null, null, null, null);
- oldChild.dispatchEvent(ev);
+ if (this.ownerDocument) {
+ var ev = this.ownerDocument.createEvent("MutationEvents");
+ ev.initMutationEvent("DOMNodeRemoved", true, false, this, null, null, null, null);
+ oldChild.dispatchEvent(ev);
+ }
return level1.call(this, oldChild);
};
})(core.Node.prototype.removeChild);

0 comments on commit 4f2191d

Please sign in to comment.
Something went wrong with that request. Please try again.