fix(angular.element): do not break on cleanData() if _data() returns undefined

This shouldn't happen in supported jQuery versions (2+), but if someone
uses the unsupported 1.x version the app will break. The change that
causes this new behavior was introduced in b7d396b8b.

Even though jQuery 1.x is not supported, it is worth avoiding the
unnecessary breakage (given how simple).

Fixes #16641

Closes #16642
This commit is contained in:
George Kalpakas
2018-07-22 22:11:02 +03:00
parent 204f9ffebe
commit e500fb6ddb
2 changed files with 7 additions and 1 deletions
+1 -1
View File
@@ -1909,7 +1909,7 @@ function bindJQuery() {
jqLite.cleanData = function(elems) {
var events;
for (var i = 0, elem; (elem = elems[i]) != null; i++) {
events = jqLite._data(elem).events;
events = (jqLite._data(elem) || {}).events;
if (events && events.$destroy) {
jqLite(elem).triggerHandler('$destroy');
}
+6
View File
@@ -501,6 +501,12 @@ describe('jqLite', function() {
expect(jqLite(c).data('prop')).toBeUndefined();
});
it('should not break on cleanData(), if element has no data', function() {
var selected = jqLite([a, b, c]);
spyOn(jqLite, '_data').and.returnValue(undefined);
expect(function() { jqLite.cleanData(selected); }).not.toThrow();
});
it('should add and remove data on SVGs', function() {
var svg = jqLite('<svg><rect></rect></svg>');