From f205c916fc5e11c1d6e69cf629a89407e133125c Mon Sep 17 00:00:00 2001 From: Sekib Omazic Date: Sun, 9 Feb 2014 17:58:11 +0100 Subject: [PATCH 1/2] fix($rootScope): ng-repeat can't handle NaN values. #4605 $watchCollection checks if oldValue !== newValue which does not work for NaN Closes #4605 --- src/ng/rootScope.js | 3 ++- test/ng/rootScopeSpec.js | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ng/rootScope.js b/src/ng/rootScope.js index c90d28a6cf24..02dbc42cf448 100644 --- a/src/ng/rootScope.js +++ b/src/ng/rootScope.js @@ -448,7 +448,8 @@ function $RootScopeProvider(){ } // copy the items to oldValue and look for changes. for (var i = 0; i < newLength; i++) { - if (oldValue[i] !== newValue[i]) { + var bothNaN = (oldValue[i] !== oldValue[i]) && (newValue[i] !== newValue[i]); + if (!bothNaN && (oldValue[i] !== newValue[i])) { changeDetected++; oldValue[i] = newValue[i]; } diff --git a/test/ng/rootScopeSpec.js b/test/ng/rootScopeSpec.js index f9cf9412c605..066078d2d343 100644 --- a/test/ng/rootScopeSpec.js +++ b/test/ng/rootScopeSpec.js @@ -579,6 +579,13 @@ describe('Scope', function() { log = []; $rootScope.$digest(); expect(log).toEqual([ '[{},[]]' ]); + + log = []; + $rootScope.obj[0] = NaN; + $rootScope.$digest(); + expect(isNaN(log.shift())).toBe(true); //jasmine's toBe and toEqual don't work well with NaNs + //expect(log).toEqual([ ]); + }); it('should watch array-like objects like arrays', function () { From 6cb083d5da68a1f9b393eaec33b210a71d0ff873 Mon Sep 17 00:00:00 2001 From: Sekib Omazic Date: Sun, 9 Feb 2014 18:04:49 +0100 Subject: [PATCH 2/2] remove unused code --- test/ng/rootScopeSpec.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/ng/rootScopeSpec.js b/test/ng/rootScopeSpec.js index 066078d2d343..a7522ab0824b 100644 --- a/test/ng/rootScopeSpec.js +++ b/test/ng/rootScopeSpec.js @@ -584,8 +584,6 @@ describe('Scope', function() { $rootScope.obj[0] = NaN; $rootScope.$digest(); expect(isNaN(log.shift())).toBe(true); //jasmine's toBe and toEqual don't work well with NaNs - //expect(log).toEqual([ ]); - }); it('should watch array-like objects like arrays', function () {