Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit bec614f

Browse files
committed
fix($compile): handle elements with no childNodes property
see the test for more details
1 parent 509ec74 commit bec614f

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/ng/compile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ function $CompileProvider($provide) {
433433
? applyDirectivesToNode(directives, nodeList[i], attrs, transcludeFn, $rootElement)
434434
: null;
435435

436-
childLinkFn = (nodeLinkFn && nodeLinkFn.terminal || !nodeList[i].childNodes.length)
436+
childLinkFn = (nodeLinkFn && nodeLinkFn.terminal || !nodeList[i].childNodes || !nodeList[i].childNodes.length)
437437
? null
438438
: compileNodes(nodeList[i].childNodes,
439439
nodeLinkFn ? nodeLinkFn.transclude : transcludeFn);

test/ng/compileSpec.js

+22
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,28 @@ describe('$compile', function() {
178178
expect(calcCacheSize()).toEqual(0);
179179
});
180180

181+
182+
it('should not blow up when elements with no childNodes property are compiled', inject(
183+
function($compile, $rootScope) {
184+
// it turns out that when a browser plugin is bound to an DOM element (typically <object>),
185+
// the plugin's context rather than the usual DOM apis are exposed on this element, so
186+
// childNodes might not exist.
187+
if (msie < 9) return;
188+
189+
element = jqLite('<div>{{1+2}}</div>');
190+
element[0].childNodes[1] = {nodeType: 3, nodeName: 'OBJECT', textContent: 'fake node'};
191+
192+
if (!element[0].childNodes[1]) return; //browser doesn't support this kind of mocking
193+
expect(element[0].childNodes[1].textContent).toBe('fake node');
194+
195+
$compile(element)($rootScope);
196+
$rootScope.$apply();
197+
198+
// object's children can't be compiled in this case, so we expect them to be raw
199+
expect(element.html()).toBe("3");
200+
}));
201+
202+
181203
describe('multiple directives per element', function() {
182204
it('should allow multiple directives per element', inject(function($compile, $rootScope, log){
183205
element = $compile(

0 commit comments

Comments
 (0)