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

Commit

Permalink
fix(Scope): revert the __proto__ cleanup as that could cause regressions
Browse files Browse the repository at this point in the history
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
  • Loading branch information
IgorMinar committed Apr 3, 2014
1 parent c967792 commit 71c11e9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
8 changes: 0 additions & 8 deletions src/ng/rootScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -757,14 +757,6 @@ function $RootScopeProvider(){
// prevent NPEs since these methods have references to properties we nulled out
this.$destroy = this.$digest = this.$apply = noop;
this.$on = this.$watch = function() { return noop; };


/* jshint -W103 */
// not all browsers have __proto__ so check first
if (this.__proto__) {
this.__proto__ = null;
}
/* jshint +W103 */
},

/**
Expand Down
19 changes: 19 additions & 0 deletions test/ng/rootScopeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,25 @@ describe('Scope', function() {
var fn = child.$watch('somePath', function() {});
expect(fn).toBe(noop);
}));


it("should preserve all (own and inherited) model properties on a destroyed scope",
inject(function($rootScope) {
// This test simulates an async task (xhr response) interacting with the scope after the scope
// was destroyed. Since we can't abort the request, we should ensure that the task doesn't
// throw NPEs because the scope was cleaned up during destruction.

var parent = $rootScope.$new(),
child = parent.$new();

parent.parentModel = 'parent';
child.childModel = 'child';

child.$destroy();

expect(child.parentModel).toBe('parent');
expect(child.childModel).toBe('child');
}));
});


Expand Down

0 comments on commit 71c11e9

Please sign in to comment.