Skip to content

Commit

Permalink
Fixes #2081: make Polymer.dom(element).getDistributedNodes and Polyme…
Browse files Browse the repository at this point in the history
…r.dom(element).getDestinationInsertionPoints() always return at least an empty array (was generating exception under Shadow DOM); make element.getContentChildNodes and element.getContentChildren always return at least an empty array when a selector is passed that does not find a <content> (was generating exception under Shadow DOM)
  • Loading branch information
Steven Orvell committed Jul 14, 2015
1 parent c46ec11 commit f966381
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/lib/dom-api.html
Original file line number Diff line number Diff line change
Expand Up @@ -688,12 +688,14 @@
}

DomApi.prototype.getDestinationInsertionPoints = function() {
var n$ = this.node.getDestinationInsertionPoints();
var n$ = this.node.getDestinationInsertionPoints &&
this.node.getDestinationInsertionPoints();
return n$ ? Array.prototype.slice.call(n$) : [];
};

DomApi.prototype.getDistributedNodes = function() {
var n$ = this.node.getDistributedNodes();
var n$ = this.node.getDistributedNodes &&
this.node.getDistributedNodes();
return n$ ? Array.prototype.slice.call(n$) : [];
};

Expand Down
2 changes: 2 additions & 0 deletions test/runner.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
'unit/gestures.html',
'unit/utils.html',
'unit/utils-content.html',
'unit/utils.html?dom=shadow',
'unit/utils-content.html?dom=shadow',
'unit/resolveurl.html',
'unit/css-parse.html',
'unit/styling-scoped.html',
Expand Down
10 changes: 10 additions & 0 deletions test/unit/polymer-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -810,4 +810,14 @@ suite('Polymer.dom non-distributed elements', function() {
Polymer.dom(c1).appendChild(test);
assert.notOk(Polymer.dom(test).getOwnerRoot(), 'getOwnerRoot incorrect for child moved from a root to no root');
});

test('getDistributedNodes on non-content element', function() {
assert.equal(Polymer.dom(document.createElement('div')).getDistributedNodes().length, 0);
assert.equal(Polymer.dom().getDistributedNodes().length, 0);
});

test('getDestinationInsertionPoints on non-distributable element', function() {
assert.equal(Polymer.dom(document.createElement('div')).getDestinationInsertionPoints().length, 0);
assert.equal(Polymer.dom(document).getDestinationInsertionPoints().length, 0);
});
});
10 changes: 10 additions & 0 deletions test/unit/utils-content.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@
nodes = elt3.getContentChildren('[select=span]');
assert.equal(nodes.length, 4, 'should have 4 spans');
});

test('getContentChildNodes with non-existent selector', function() {
var nodes = elt3.getContentChildNodes('[dne]');
assert.equal(nodes.length, 0, 'should find 0 nodes');
});

test('getContentChildren with non-existent selector', function() {
var nodes = elt3.getContentChildren('[dne]');
assert.equal(nodes.length, 0, 'should find 0 nodes');
});

});

Expand Down

0 comments on commit f966381

Please sign in to comment.