diff --git a/src/zones.ts b/src/zones.ts index fc4eeeb25..dbd4a234a 100644 --- a/src/zones.ts +++ b/src/zones.ts @@ -145,6 +145,7 @@ const zoneWrapFn = (it: (...args: any[]) => any, macrotask: MacroTask|undefined) // function() is needed for the arguments object // tslint:disable-next-line:only-arrow-functions return function() { + const _arguments = arguments; if (macrotask) { setTimeout(() => { if (macrotask.state === 'scheduled') { @@ -152,7 +153,7 @@ const zoneWrapFn = (it: (...args: any[]) => any, macrotask: MacroTask|undefined) } }, 10); } - return run(() => it.apply(_this, arguments)); + return run(() => it.apply(_this, _arguments)); }; }; @@ -161,18 +162,19 @@ export const ɵzoneWrap = (it: T, blockUntilFirst: boolean): T => { // tslint:disable-next-line:only-arrow-functions return function() { let macrotask: MacroTask | undefined; + const _arguments = arguments; // if this is a callback function, e.g, onSnapshot, we should create a microtask and invoke it // only once one of the callback functions is tripped. for (let i = 0; i < arguments.length; i++) { - if (typeof arguments[i] === 'function') { + if (typeof _arguments[i] === 'function') { if (blockUntilFirst) { macrotask ||= run(() => Zone.current.scheduleMacroTask('firebaseZoneBlock', noop, {}, noop, noop)); } // TODO create a microtask to track callback functions - arguments[i] = zoneWrapFn(arguments[i], macrotask); + _arguments[i] = zoneWrapFn(_arguments[i], macrotask); } } - const ret = runOutsideAngular(() => (it as any).apply(this, arguments)); + const ret = runOutsideAngular(() => (it as any).apply(this, _arguments)); if (!blockUntilFirst) { if (ret instanceof Observable) { const schedulers = getSchedulers();