Skip to content

Commit

Permalink
Land: when Node#insertBefore should do nothing when both params are t…
Browse files Browse the repository at this point in the history
…he same node (Jason Davies)
  • Loading branch information
tmpvar committed Sep 21, 2011
2 parents a4ab554 + 00b278c commit 8bc448a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/jsdom/level1/core.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -481,6 +481,8 @@ core.Node.prototype = {
tmpNode = newChild.removeChild(newChild.firstChild); tmpNode = newChild.removeChild(newChild.firstChild);
this.insertBefore(tmpNode, refChild); this.insertBefore(tmpNode, refChild);
} }
} else if (newChild === refChild) {
return newChild;
} else { } else {
// if the newChild is already in the tree elsewhere, remove it first // if the newChild is already in the tree elsewhere, remove it first
if (newChild._parentNode) { if (newChild._parentNode) {
Expand Down
16 changes: 16 additions & 0 deletions test/level1/core.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13135,6 +13135,22 @@ exports.tests = {
test.done(); test.done();
}, },


/**
* If the "refChild" is the same as the "newChild" then don't do anything.
*/
hc_nodeinsertbeforerefchildequal: function(test) {
var doc = hc_staff.hc_staff();
var elementList = doc.getElementsByTagName("p");
var employeeNode = elementList.item(1);
var childList = employeeNode.childNodes;

var refChild = childList.item(3);

employeeNode.insertBefore(refChild, refChild);

test.done();
},

/** /**
* *
If the "refChild" is null then the If the "refChild" is null then the
Expand Down

0 comments on commit 8bc448a

Please sign in to comment.