fix(zone.js): hook should set correct current zone (#31642)
Close #31641 PR Close #31642
This commit is contained in:
parent
29e1c53a31
commit
17b32b5fd4
|
@ -1021,47 +1021,49 @@ const Zone: ZoneType = (function(global: any) {
|
||||||
this._forkZS =
|
this._forkZS =
|
||||||
zoneSpec && (zoneSpec && zoneSpec.onFork ? zoneSpec : parentDelegate !._forkZS);
|
zoneSpec && (zoneSpec && zoneSpec.onFork ? zoneSpec : parentDelegate !._forkZS);
|
||||||
this._forkDlgt = zoneSpec && (zoneSpec.onFork ? parentDelegate : parentDelegate !._forkDlgt);
|
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 =
|
this._interceptZS =
|
||||||
zoneSpec && (zoneSpec.onIntercept ? zoneSpec : parentDelegate !._interceptZS);
|
zoneSpec && (zoneSpec.onIntercept ? zoneSpec : parentDelegate !._interceptZS);
|
||||||
this._interceptDlgt =
|
this._interceptDlgt =
|
||||||
zoneSpec && (zoneSpec.onIntercept ? parentDelegate : parentDelegate !._interceptDlgt);
|
zoneSpec && (zoneSpec.onIntercept ? parentDelegate : parentDelegate !._interceptDlgt);
|
||||||
this._interceptCurrZone =
|
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._invokeZS = zoneSpec && (zoneSpec.onInvoke ? zoneSpec : parentDelegate !._invokeZS);
|
||||||
this._invokeDlgt =
|
this._invokeDlgt =
|
||||||
zoneSpec && (zoneSpec.onInvoke ? parentDelegate ! : parentDelegate !._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 =
|
this._handleErrorZS =
|
||||||
zoneSpec && (zoneSpec.onHandleError ? zoneSpec : parentDelegate !._handleErrorZS);
|
zoneSpec && (zoneSpec.onHandleError ? zoneSpec : parentDelegate !._handleErrorZS);
|
||||||
this._handleErrorDlgt = zoneSpec &&
|
this._handleErrorDlgt = zoneSpec &&
|
||||||
(zoneSpec.onHandleError ? parentDelegate ! : parentDelegate !._handleErrorDlgt);
|
(zoneSpec.onHandleError ? parentDelegate ! : parentDelegate !._handleErrorDlgt);
|
||||||
this._handleErrorCurrZone =
|
this._handleErrorCurrZone =
|
||||||
zoneSpec && (zoneSpec.onHandleError ? this.zone : parentDelegate !.zone);
|
zoneSpec && (zoneSpec.onHandleError ? this.zone : parentDelegate !._handleErrorCurrZone);
|
||||||
|
|
||||||
this._scheduleTaskZS =
|
this._scheduleTaskZS =
|
||||||
zoneSpec && (zoneSpec.onScheduleTask ? zoneSpec : parentDelegate !._scheduleTaskZS);
|
zoneSpec && (zoneSpec.onScheduleTask ? zoneSpec : parentDelegate !._scheduleTaskZS);
|
||||||
this._scheduleTaskDlgt = zoneSpec &&
|
this._scheduleTaskDlgt = zoneSpec &&
|
||||||
(zoneSpec.onScheduleTask ? parentDelegate ! : parentDelegate !._scheduleTaskDlgt);
|
(zoneSpec.onScheduleTask ? parentDelegate ! : parentDelegate !._scheduleTaskDlgt);
|
||||||
this._scheduleTaskCurrZone =
|
this._scheduleTaskCurrZone = zoneSpec &&
|
||||||
zoneSpec && (zoneSpec.onScheduleTask ? this.zone : parentDelegate !.zone);
|
(zoneSpec.onScheduleTask ? this.zone : parentDelegate !._scheduleTaskCurrZone);
|
||||||
|
|
||||||
this._invokeTaskZS =
|
this._invokeTaskZS =
|
||||||
zoneSpec && (zoneSpec.onInvokeTask ? zoneSpec : parentDelegate !._invokeTaskZS);
|
zoneSpec && (zoneSpec.onInvokeTask ? zoneSpec : parentDelegate !._invokeTaskZS);
|
||||||
this._invokeTaskDlgt =
|
this._invokeTaskDlgt =
|
||||||
zoneSpec && (zoneSpec.onInvokeTask ? parentDelegate ! : parentDelegate !._invokeTaskDlgt);
|
zoneSpec && (zoneSpec.onInvokeTask ? parentDelegate ! : parentDelegate !._invokeTaskDlgt);
|
||||||
this._invokeTaskCurrZone =
|
this._invokeTaskCurrZone =
|
||||||
zoneSpec && (zoneSpec.onInvokeTask ? this.zone : parentDelegate !.zone);
|
zoneSpec && (zoneSpec.onInvokeTask ? this.zone : parentDelegate !._invokeTaskCurrZone);
|
||||||
|
|
||||||
this._cancelTaskZS =
|
this._cancelTaskZS =
|
||||||
zoneSpec && (zoneSpec.onCancelTask ? zoneSpec : parentDelegate !._cancelTaskZS);
|
zoneSpec && (zoneSpec.onCancelTask ? zoneSpec : parentDelegate !._cancelTaskZS);
|
||||||
this._cancelTaskDlgt =
|
this._cancelTaskDlgt =
|
||||||
zoneSpec && (zoneSpec.onCancelTask ? parentDelegate ! : parentDelegate !._cancelTaskDlgt);
|
zoneSpec && (zoneSpec.onCancelTask ? parentDelegate ! : parentDelegate !._cancelTaskDlgt);
|
||||||
this._cancelTaskCurrZone =
|
this._cancelTaskCurrZone =
|
||||||
zoneSpec && (zoneSpec.onCancelTask ? this.zone : parentDelegate !.zone);
|
zoneSpec && (zoneSpec.onCancelTask ? this.zone : parentDelegate !._cancelTaskCurrZone);
|
||||||
|
|
||||||
this._hasTaskZS = null;
|
this._hasTaskZS = null;
|
||||||
this._hasTaskDlgt = null;
|
this._hasTaskDlgt = null;
|
||||||
|
|
|
@ -49,6 +49,22 @@ describe('Zone', function() {
|
||||||
const zoneC = zoneB.fork({name: 'C'});
|
const zoneC = zoneB.fork({name: 'C'});
|
||||||
zoneC.run(function() {});
|
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() {
|
it('should allow zones to be run from within another zone', function() {
|
||||||
|
|
Loading…
Reference in New Issue