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

Commit 20fb626

Browse files
HeberLZpetebacondarwin
authored andcommitted
fix(rootScope): add support for watchCollection to watch an object which does not inherit from Object
Closes #9964
1 parent 7ea2c7f commit 20fb626

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/ng/rootScope.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ function $RootScopeProvider() {
605605
// copy the items to oldValue and look for changes.
606606
newLength = 0;
607607
for (key in newValue) {
608-
if (newValue.hasOwnProperty(key)) {
608+
if (hasOwnProperty.call(newValue, key)) {
609609
newLength++;
610610
newItem = newValue[key];
611611
oldItem = oldValue[key];
@@ -627,7 +627,7 @@ function $RootScopeProvider() {
627627
// we used to have more keys, need to find them and destroy them.
628628
changeDetected++;
629629
for (key in oldValue) {
630-
if (!newValue.hasOwnProperty(key)) {
630+
if (!hasOwnProperty.call(newValue, key)) {
631631
oldLength--;
632632
delete oldValue[key];
633633
}

test/ng/rootScopeSpec.js

+13
Original file line numberDiff line numberDiff line change
@@ -822,13 +822,26 @@ describe('Scope', function() {
822822
expect(log.empty()).toEqual([{newVal: {b: {}, c: 'B'}, oldVal: {a: [], b: {}, c: 'B'}}]);
823823
});
824824

825+
825826
it('should not infinitely digest when current value is NaN', function() {
826827
$rootScope.obj = {a: NaN};
827828
expect(function() {
828829
$rootScope.$digest();
829830
}).not.toThrow();
830831
});
831832

833+
834+
it('should handle objects created using `Object.create(null)`', function() {
835+
$rootScope.obj = Object.create(null);
836+
$rootScope.obj.a = 'a';
837+
$rootScope.obj.b = 'b';
838+
$rootScope.$digest();
839+
expect(log.empty()[0].newVal).toEqual({a: 'a', b: 'b'});
840+
841+
delete $rootScope.obj.b;
842+
$rootScope.$digest();
843+
expect(log.empty()[0].newVal).toEqual({a: 'a'});
844+
});
832845
});
833846
});
834847

0 commit comments

Comments
 (0)