mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-24 03:55:49 +08:00
fix($rootScope): $watchCollection should handle NaN in objects
This fixes a potential infinite digest in $watchCollection when one of the values is NaN. This was previously fixed for arrays, but needs to be handled for objects as well. Closes #7930
This commit is contained in:
@@ -498,7 +498,7 @@ function $RootScopeProvider(){
|
||||
|
||||
function $watchCollectionWatch() {
|
||||
newValue = objGetter(self);
|
||||
var newLength, key;
|
||||
var newLength, key, bothNaN;
|
||||
|
||||
if (!isObject(newValue)) { // if primitive
|
||||
if (oldValue !== newValue) {
|
||||
@@ -522,7 +522,7 @@ function $RootScopeProvider(){
|
||||
}
|
||||
// copy the items to oldValue and look for changes.
|
||||
for (var i = 0; i < newLength; i++) {
|
||||
var bothNaN = (oldValue[i] !== oldValue[i]) &&
|
||||
bothNaN = (oldValue[i] !== oldValue[i]) &&
|
||||
(newValue[i] !== newValue[i]);
|
||||
if (!bothNaN && (oldValue[i] !== newValue[i])) {
|
||||
changeDetected++;
|
||||
@@ -542,7 +542,9 @@ function $RootScopeProvider(){
|
||||
if (newValue.hasOwnProperty(key)) {
|
||||
newLength++;
|
||||
if (oldValue.hasOwnProperty(key)) {
|
||||
if (oldValue[key] !== newValue[key]) {
|
||||
bothNaN = (oldValue[key] !== oldValue[key]) &&
|
||||
(newValue[key] !== newValue[key]);
|
||||
if (!bothNaN && (oldValue[key] !== newValue[key])) {
|
||||
changeDetected++;
|
||||
oldValue[key] = newValue[key];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user