Skip to content

Commit

Permalink
Merge pull request #2082 from Polymer/fix-2081
Browse files Browse the repository at this point in the history
Fixes #2081
  • Loading branch information
kevinpschaaf committed Jul 15, 2015
2 parents 7606f24 + a6bd5a5 commit a230ffb
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 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
4 changes: 2 additions & 2 deletions src/standard/utils.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@
* @return {Array<Node>} List of distributed nodes for the `<content>`.
*/
getContentChildNodes: function(slctr) {
return Polymer.dom(Polymer.dom(this.root).querySelector(
slctr || 'content')).getDistributedNodes();
var content = Polymer.dom(this.root).querySelector(slctr || 'content');
return content ? Polymer.dom(content).getDistributedNodes() : [];
},

/**
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 a230ffb

Please sign in to comment.