diff --git a/src/ng/rootScope.js b/src/ng/rootScope.js index 77cba19968ab..5b3c0d3e7f75 100644 --- a/src/ng/rootScope.js +++ b/src/ng/rootScope.js @@ -130,12 +130,9 @@ function $RootScopeProvider(){ this.$$childHead = this.$$childTail = null; this['this'] = this.$root = this; this.$$destroyed = false; - this.$$asyncQueue = []; - this.$$postDigestQueue = []; this.$$listeners = {}; this.$$listenerCount = {}; this.$$isolateBindings = null; - this.$$applyAsyncQueue = []; } /** @@ -193,9 +190,6 @@ function $RootScopeProvider(){ if (isolate) { child = new Scope(); child.$root = this.$root; - // ensure that there is just one async queue per $rootScope and its children - child.$$asyncQueue = this.$$asyncQueue; - child.$$postDigestQueue = this.$$postDigestQueue; } else { // Only create a child scope class if somebody asks for one, // but cache it to allow the VM to optimize lookups. @@ -695,8 +689,6 @@ function $RootScopeProvider(){ $digest: function() { var watch, value, last, watchers, - asyncQueue = this.$$asyncQueue, - postDigestQueue = this.$$postDigestQueue, length, dirty, ttl = TTL, next, current, target = this, @@ -861,6 +853,10 @@ function $RootScopeProvider(){ if (this.$$prevSibling) this.$$prevSibling.$$nextSibling = this.$$nextSibling; if (this.$$nextSibling) this.$$nextSibling.$$prevSibling = this.$$prevSibling; + // Disable listeners, watchers and apply/digest methods + this.$destroy = this.$digest = this.$apply = this.$evalAsync = this.$applyAsync = noop; + this.$on = this.$watch = this.$watchGroup = function() { return noop; }; + this.$$listeners = {}; // All of the code below is bogus code that works around V8's memory leak via optimized code // and inline caches. @@ -871,15 +867,7 @@ function $RootScopeProvider(){ // - https://github.com/angular/angular.js/issues/1313#issuecomment-10378451 this.$parent = this.$$nextSibling = this.$$prevSibling = this.$$childHead = - this.$$childTail = this.$root = null; - - // don't reset these to null in case some async task tries to register a listener/watch/task - this.$$listeners = {}; - this.$$watchers = this.$$asyncQueue = this.$$postDigestQueue = []; - - // prevent NPEs since these methods have references to properties we nulled out - this.$destroy = this.$digest = this.$apply = noop; - this.$on = this.$watch = this.$watchGroup = function() { return noop; }; + this.$$childTail = this.$root = this.$$watchers = null; }, /** @@ -946,19 +934,19 @@ function $RootScopeProvider(){ $evalAsync: function(expr) { // if we are outside of an $digest loop and this is the first time we are scheduling async // task also schedule async auto-flush - if (!$rootScope.$$phase && !$rootScope.$$asyncQueue.length) { + if (!$rootScope.$$phase && !asyncQueue.length) { $browser.defer(function() { - if ($rootScope.$$asyncQueue.length) { + if (asyncQueue.length) { $rootScope.$digest(); } }); } - this.$$asyncQueue.push({scope: this, expression: expr}); + asyncQueue.push({scope: this, expression: expr}); }, $$postDigest : function(fn) { - this.$$postDigestQueue.push(fn); + postDigestQueue.push(fn); }, /** @@ -1042,7 +1030,7 @@ function $RootScopeProvider(){ */ $applyAsync: function(expr) { var scope = this; - expr && $rootScope.$$applyAsyncQueue.push($applyAsyncExpression); + expr && applyAsyncQueue.push($applyAsyncExpression); scheduleApplyAsync(); function $applyAsyncExpression() { @@ -1251,6 +1239,11 @@ function $RootScopeProvider(){ var $rootScope = new Scope(); + //The internal queues. Expose them on the $rootScope for debugging/testing purposes. + var asyncQueue = $rootScope.$$asyncQueue = []; + var postDigestQueue = $rootScope.$$postDigestQueue = []; + var applyAsyncQueue = $rootScope.$$applyAsyncQueue = []; + return $rootScope; @@ -1284,10 +1277,9 @@ function $RootScopeProvider(){ function initWatchVal() {} function flushApplyAsync() { - var queue = $rootScope.$$applyAsyncQueue; - while (queue.length) { + while (applyAsyncQueue.length) { try { - queue.shift()(); + applyAsyncQueue.shift()(); } catch(e) { $exceptionHandler(e); } diff --git a/test/ng/directive/ngBindSpec.js b/test/ng/directive/ngBindSpec.js index 5f65bfa907e1..943adaae9259 100644 --- a/test/ng/directive/ngBindSpec.js +++ b/test/ng/directive/ngBindSpec.js @@ -160,13 +160,13 @@ describe('ngBind*', function() { it('should NOT set html for untrusted values', inject(function($rootScope, $compile) { element = $compile('
')($rootScope); $rootScope.html = '