aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMisko Hevery2012-05-23 14:49:01 -0700
committerMisko Hevery2012-05-23 16:01:20 -0700
commit989446eceee697b15ecb5df1f491dfbcff352256 (patch)
treed9b22e53d9014924019f17c9fe3b2b5d85838592 /src
parent5214c1d0cbd8473e1f5dd3894f1fcbecd89bc8af (diff)
downloadangular.js-989446eceee697b15ecb5df1f491dfbcff352256.tar.bz2
fix($rootScope): TTL exception does not clear $$phase
When $digest() throws infinite digest exception it does not properly clear the $phase leaving the scope in an inconsistent state. Closes #979
Diffstat (limited to 'src')
-rw-r--r--src/ng/rootScope.js34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/ng/rootScope.js b/src/ng/rootScope.js
index bb12362b..81c9ee78 100644
--- a/src/ng/rootScope.js
+++ b/src/ng/rootScope.js
@@ -372,7 +372,7 @@ function $RootScopeProvider(){
watchLog = [],
logIdx, logMsg;
- flagPhase(target, '$digest');
+ beginPhase('$digest');
do {
dirty = false;
@@ -429,12 +429,13 @@ function $RootScopeProvider(){
} while ((current = next));
if(dirty && !(ttl--)) {
+ clearPhase();
throw Error(TTL + ' $digest() iterations reached. Aborting!\n' +
'Watchers fired in the last 5 iterations: ' + toJson(watchLog));
}
} while (dirty || asyncQueue.length);
- this.$root.$$phase = null;
+ clearPhase();
},
@@ -469,7 +470,7 @@ function $RootScopeProvider(){
* perform any necessary cleanup.
*/
$destroy: function() {
- if (this.$root == this) return; // we can't remove the root node;
+ if ($rootScope == this) return; // we can't remove the root node;
var parent = this.$parent;
this.$broadcast('$destroy');
@@ -586,13 +587,18 @@ function $RootScopeProvider(){
*/
$apply: function(expr) {
try {
- flagPhase(this, '$apply');
+ beginPhase('$apply');
return this.$eval(expr);
} catch (e) {
$exceptionHandler(e);
} finally {
- this.$root.$$phase = null;
- this.$root.$digest();
+ clearPhase();
+ try {
+ $rootScope.$digest();
+ } catch (e) {
+ $exceptionHandler(e);
+ throw e;
+ }
}
},
@@ -754,18 +760,22 @@ function $RootScopeProvider(){
}
};
+ var $rootScope = new Scope();
+
+ return $rootScope;
- function flagPhase(scope, phase) {
- var root = scope.$root;
- if (root.$$phase) {
- throw Error(root.$$phase + ' already in progress');
+ function beginPhase(phase) {
+ if ($rootScope.$$phase) {
+ throw Error($rootScope.$$phase + ' already in progress');
}
- root.$$phase = phase;
+ $rootScope.$$phase = phase;
}
- return new Scope();
+ function clearPhase() {
+ $rootScope.$$phase = null;
+ }
function compileToFn(exp, name) {
var fn = $parse(exp);