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

Commit

Permalink
fix(rootScope): add support for watchCollection to watch an object wh…
Browse files Browse the repository at this point in the history
…ich does not inherit from Object

Closes #9964
  • Loading branch information
HeberLZ authored and petebacondarwin committed Sep 7, 2015
1 parent 7ea2c7f commit 20fb626
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ng/rootScope.js
Expand Up @@ -605,7 +605,7 @@ function $RootScopeProvider() {
// copy the items to oldValue and look for changes.
newLength = 0;
for (key in newValue) {
if (newValue.hasOwnProperty(key)) {
if (hasOwnProperty.call(newValue, key)) {
newLength++;
newItem = newValue[key];
oldItem = oldValue[key];
Expand All @@ -627,7 +627,7 @@ function $RootScopeProvider() {
// we used to have more keys, need to find them and destroy them.
changeDetected++;
for (key in oldValue) {
if (!newValue.hasOwnProperty(key)) {
if (!hasOwnProperty.call(newValue, key)) {
oldLength--;
delete oldValue[key];
}
Expand Down
13 changes: 13 additions & 0 deletions test/ng/rootScopeSpec.js
Expand Up @@ -822,13 +822,26 @@ describe('Scope', function() {
expect(log.empty()).toEqual([{newVal: {b: {}, c: 'B'}, oldVal: {a: [], b: {}, c: 'B'}}]);
});


it('should not infinitely digest when current value is NaN', function() {
$rootScope.obj = {a: NaN};
expect(function() {
$rootScope.$digest();
}).not.toThrow();
});


it('should handle objects created using `Object.create(null)`', function() {
$rootScope.obj = Object.create(null);
$rootScope.obj.a = 'a';
$rootScope.obj.b = 'b';
$rootScope.$digest();
expect(log.empty()[0].newVal).toEqual({a: 'a', b: 'b'});

delete $rootScope.obj.b;
$rootScope.$digest();
expect(log.empty()[0].newVal).toEqual({a: 'a'});
});
});
});

Expand Down

0 comments on commit 20fb626

Please sign in to comment.