Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Merge pull request #234 from arv/fix-owner-document-for-ie
Browse files Browse the repository at this point in the history
Fix issue with ensureSameOwnerDocument when parent is a document
  • Loading branch information
dfreedm committed Aug 29, 2013
2 parents b3891e3 + f2e7d5c commit 4c1b65e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/wrappers/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
}

function ensureSameOwnerDocument(parent, child) {
var ownerDoc = parent.ownerDocument;
var ownerDoc = parent.nodeType === Node.DOCUMENT_NODE ?
parent : parent.ownerDocument;
if (ownerDoc !== child.ownerDocument)
ownerDoc.adoptNode(child);
}
Expand Down Expand Up @@ -278,7 +279,6 @@
childWrapper.previousSibling_ = childWrapper.nextSibling_ =
childWrapper.parentNode_ = undefined;
} else {
ensureSameOwnerDocument(this, childWrapper);
originalRemoveChild.call(this.impl, childNode);
}

Expand Down
11 changes: 11 additions & 0 deletions test/js/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ suite('Node', function() {
doc.body.removeChild(host);
});

test('ownerDocument when appending to document', function() {
var doc1 = document.implementation.createHTMLDocument('');
var comment = doc1.createComment('');
doc1.appendChild(comment);
assert.equal(doc1, comment.ownerDocument);

var doc2 = document.implementation.createHTMLDocument('');
doc2.appendChild(comment);
assert.equal(doc2, comment.ownerDocument);
});

test('removeChild resets pointers', function() {
var host = document.createElement('div');
host.innerHTML = '<a></a>';
Expand Down

0 comments on commit 4c1b65e

Please sign in to comment.