fix(zone.js): hook should set correct current zone (#31642)

Close #31641

PR Close #31642
This commit is contained in:
JiaLiPassion 2019-07-19 12:20:07 +09:00 committed by Miško Hevery
parent 29e1c53a31
commit 17b32b5fd4
2 changed files with 26 additions and 8 deletions

View File

@ -1021,47 +1021,49 @@ const Zone: ZoneType = (function(global: any) {
this._forkZS =
zoneSpec && (zoneSpec && zoneSpec.onFork ? zoneSpec : parentDelegate !._forkZS);
this._forkDlgt = zoneSpec && (zoneSpec.onFork ? parentDelegate : parentDelegate !._forkDlgt);
this._forkCurrZone = zoneSpec && (zoneSpec.onFork ? this.zone : parentDelegate !.zone);
this._forkCurrZone =
zoneSpec && (zoneSpec.onFork ? this.zone : parentDelegate !._forkCurrZone);
this._interceptZS =
zoneSpec && (zoneSpec.onIntercept ? zoneSpec : parentDelegate !._interceptZS);
this._interceptDlgt =
zoneSpec && (zoneSpec.onIntercept ? parentDelegate : parentDelegate !._interceptDlgt);
this._interceptCurrZone =
zoneSpec && (zoneSpec.onIntercept ? this.zone : parentDelegate !.zone);
zoneSpec && (zoneSpec.onIntercept ? this.zone : parentDelegate !._interceptCurrZone);
this._invokeZS = zoneSpec && (zoneSpec.onInvoke ? zoneSpec : parentDelegate !._invokeZS);
this._invokeDlgt =
zoneSpec && (zoneSpec.onInvoke ? parentDelegate ! : parentDelegate !._invokeDlgt);
this._invokeCurrZone = zoneSpec && (zoneSpec.onInvoke ? this.zone : parentDelegate !.zone);
this._invokeCurrZone =
zoneSpec && (zoneSpec.onInvoke ? this.zone : parentDelegate !._invokeCurrZone);
this._handleErrorZS =
zoneSpec && (zoneSpec.onHandleError ? zoneSpec : parentDelegate !._handleErrorZS);
this._handleErrorDlgt = zoneSpec &&
(zoneSpec.onHandleError ? parentDelegate ! : parentDelegate !._handleErrorDlgt);
this._handleErrorCurrZone =
zoneSpec && (zoneSpec.onHandleError ? this.zone : parentDelegate !.zone);
zoneSpec && (zoneSpec.onHandleError ? this.zone : parentDelegate !._handleErrorCurrZone);
this._scheduleTaskZS =
zoneSpec && (zoneSpec.onScheduleTask ? zoneSpec : parentDelegate !._scheduleTaskZS);
this._scheduleTaskDlgt = zoneSpec &&
(zoneSpec.onScheduleTask ? parentDelegate ! : parentDelegate !._scheduleTaskDlgt);
this._scheduleTaskCurrZone =
zoneSpec && (zoneSpec.onScheduleTask ? this.zone : parentDelegate !.zone);
this._scheduleTaskCurrZone = zoneSpec &&
(zoneSpec.onScheduleTask ? this.zone : parentDelegate !._scheduleTaskCurrZone);
this._invokeTaskZS =
zoneSpec && (zoneSpec.onInvokeTask ? zoneSpec : parentDelegate !._invokeTaskZS);
this._invokeTaskDlgt =
zoneSpec && (zoneSpec.onInvokeTask ? parentDelegate ! : parentDelegate !._invokeTaskDlgt);
this._invokeTaskCurrZone =
zoneSpec && (zoneSpec.onInvokeTask ? this.zone : parentDelegate !.zone);
zoneSpec && (zoneSpec.onInvokeTask ? this.zone : parentDelegate !._invokeTaskCurrZone);
this._cancelTaskZS =
zoneSpec && (zoneSpec.onCancelTask ? zoneSpec : parentDelegate !._cancelTaskZS);
this._cancelTaskDlgt =
zoneSpec && (zoneSpec.onCancelTask ? parentDelegate ! : parentDelegate !._cancelTaskDlgt);
this._cancelTaskCurrZone =
zoneSpec && (zoneSpec.onCancelTask ? this.zone : parentDelegate !.zone);
zoneSpec && (zoneSpec.onCancelTask ? this.zone : parentDelegate !._cancelTaskCurrZone);
this._hasTaskZS = null;
this._hasTaskDlgt = null;

View File

@ -49,6 +49,22 @@ describe('Zone', function() {
const zoneC = zoneB.fork({name: 'C'});
zoneC.run(function() {});
});
it('should send correct currentZone in hook method when in nested zone with empty implementation',
function() {
const zone = Zone.current;
const zoneA = zone.fork({
name: 'A',
onInvoke: function(
parentDelegate, currentZone, targetZone, callback, applyThis, applyArgs, source) {
expect(currentZone.name).toEqual('A');
return parentDelegate.invoke(targetZone, callback, applyThis, applyArgs, source);
}
});
const zoneB = zoneA.fork({name: 'B'});
const zoneC = zoneB.fork({name: 'C'});
zoneC.run(function() {});
});
});
it('should allow zones to be run from within another zone', function() {