Skip to content
Browse files

Fixes #2081: make Polymer.dom(element).getDistributedNodes and Polyme…

…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...
1 parent c46ec11 commit f9663815edef8877ba2747afa10d05d55f347da1 @sorvell sorvell committed
Showing with 26 additions and 2 deletions.
  1. +4 −2 src/lib/dom-api.html
  2. +2 −0 test/runner.html
  3. +10 −0 test/unit/polymer-dom.js
  4. +10 −0 test/unit/utils-content.html
View
6 src/lib/dom-api.html
@@ -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$) : [];
};
View
2 test/runner.html
@@ -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',
View
10 test/unit/polymer-dom.js
@@ -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);
+ });
});
View
10 test/unit/utils-content.html
@@ -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');
+ });
});

0 comments on commit f966381

Please sign in to comment.
Something went wrong with that request. Please try again.