@@ -287,7 +287,7 @@ core.Node.prototype.__proto__ = events.EventTarget.prototype;
287
287
( function ( level1 ) {
288
288
core . Node . prototype . appendChild = function ( newChild ) {
289
289
var ret = level1 . call ( this , newChild ) ;
290
- if ( this . nodeType == 1 ) {
290
+ if ( this . nodeType == 1 && this . ownerDocument ) {
291
291
var ev = this . ownerDocument . createEvent ( "MutationEvents" ) ;
292
292
ev . initMutationEvent ( "DOMNodeInserted" , true , false , this , null , null , null , null ) ;
293
293
newChild . dispatchEvent ( ev ) ;
@@ -299,9 +299,11 @@ core.Node.prototype.__proto__ = events.EventTarget.prototype;
299
299
// Wrap the level-1 implementation of removeChild() to dispatch a DOMNodeRemoved event
300
300
( function ( level1 ) {
301
301
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
+ }
305
307
return level1 . call ( this , oldChild ) ;
306
308
} ;
307
309
} ) ( core . Node . prototype . removeChild ) ;
0 commit comments