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

Commit 2db66f5

Browse files
committed
fix(Scope): revert the __proto__ cleanup as that could cause regressions
When a async task interacts with a scope that has been destroyed already and if it interacts with a property that is prototypically inherited from some parent scope then resetting proto would make these inherited properties inaccessible and would result in NPEs
1 parent 55fe6d6 commit 2db66f5

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/ng/rootScope.js

-8
Original file line numberDiff line numberDiff line change
@@ -757,14 +757,6 @@ function $RootScopeProvider(){
757757
// prevent NPEs since these methods have references to properties we nulled out
758758
this.$destroy = this.$digest = this.$apply = noop;
759759
this.$on = this.$watch = function() { return noop; };
760-
761-
762-
/* jshint -W103 */
763-
// not all browsers have __proto__ so check first
764-
if (this.__proto__) {
765-
this.__proto__ = null;
766-
}
767-
/* jshint +W103 */
768760
},
769761

770762
/**

test/ng/rootScopeSpec.js

+19
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,25 @@ describe('Scope', function() {
898898
var fn = child.$watch('somePath', function() {});
899899
expect(fn).toBe(noop);
900900
}));
901+
902+
903+
it("should preserve all (own and inherited) model properties on a destroyed scope",
904+
inject(function($rootScope) {
905+
// This test simulates an async task (xhr response) interacting with the scope after the scope
906+
// was destroyed. Since we can't abort the request, we should ensure that the task doesn't
907+
// throw NPEs because the scope was cleaned up during destruction.
908+
909+
var parent = $rootScope.$new(),
910+
child = parent.$new();
911+
912+
parent.parentModel = 'parent';
913+
child.childModel = 'child';
914+
915+
child.$destroy();
916+
917+
expect(child.parentModel).toBe('parent');
918+
expect(child.childModel).toBe('child');
919+
}));
901920
});
902921

903922

0 commit comments

Comments
 (0)