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 #439 from arv/node-append-child
Browse files Browse the repository at this point in the history
appendChild from a tree with a rendered causes failures
  • Loading branch information
Steve Orvell committed May 20, 2014
2 parents e25f9a7 + 9fb2203 commit 9d2bdaa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/wrappers/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,11 @@
} else {
if (!previousNode)
this.firstChild_ = nodes[0];
if (!refWrapper)
if (!refWrapper) {
this.lastChild_ = nodes[nodes.length - 1];
if (this.firstChild_ === undefined)
this.firstChild_ = this.firstChild;
}

var parentNode = refNode ? refNode.parentNode : this.impl;

Expand Down
21 changes: 21 additions & 0 deletions test/js/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,4 +392,25 @@ suite('Node', function() {
assert.equal(sr.firstChild.nextSibling.textContent, 'quux');
});

test('appendChild last and first', function() {
var a = document.createElement('a');
a.innerHTML = '<b></b>';
var b = a.firstChild;
var sr = a.createShadowRoot();

var c = document.createElement('c');
c.innerHTML = '<d></d>';
var d = c.firstChild;
c.appendChild(b);

var cs = c.childNodes;
assert.equal(cs.length, 2);
assert.equal(cs[0], d);
assert.equal(cs[1], b);

c.removeChild(b);
cs = c.childNodes;
assert.equal(cs.length, 1);
assert.equal(cs[0], d);
});
});

0 comments on commit 9d2bdaa

Please sign in to comment.