fix(ng_zone): updated zone not to run onTurnDown when invoking run synchronously from onTurnDone

This commit is contained in:
vsavkin
2015-06-10 17:21:11 -07:00
parent 37f8fd6551
commit 15dab7c5b2
3 changed files with 35 additions and 2 deletions

View File

@ -39,6 +39,8 @@ class NgZone {
// }); // we should only check for the end of a turn once the top-level run ends
int _nestedRun = 0;
bool _inVmTurnDone = false;
/**
* Associates with this
*
@ -143,12 +145,14 @@ class NgZone {
} finally {
_nestedRun--;
// If there are no more pending microtasks and we are not in a recursive call, this is the end of a turn
if (_pendingMicrotasks == 0 && _nestedRun == 0) {
if (_pendingMicrotasks == 0 && _nestedRun == 0 && !_inVmTurnDone) {
if (_onTurnDone != null && _hasExecutedCodeInInnerZone) {
// Trigger onTurnDone at the end of a turn if _innerZone has executed some code
try {
_inVmTurnDone = true;
parent.run(_innerZone, _onTurnDone);
} finally {
_inVmTurnDone = false;
_hasExecutedCodeInInnerZone = false;
}
}

View File

@ -39,6 +39,8 @@ export class NgZone {
// This disabled flag is only here to please cjs tests
_disabled: boolean;
_inVmTurnDone: boolean = false;
/**
* Associates with this
*
@ -166,11 +168,14 @@ export class NgZone {
// _nestedRun will be 0 at the end of a macrotasks (it could be > 0 when there are
// nested calls
// to run()).
if (ngZone._pendingMicrotasks == 0 && ngZone._nestedRun == 0) {
if (ngZone._pendingMicrotasks == 0 && ngZone._nestedRun == 0 &&
!this._inVmTurnDone) {
if (ngZone._onTurnDone && ngZone._hasExecutedCodeInInnerZone) {
try {
this._inVmTurnDone = true;
parentRun.call(ngZone._innerZone, ngZone._onTurnDone);
} finally {
this._inVmTurnDone = false;
ngZone._hasExecutedCodeInInnerZone = false;
}
}