Skip to content

Commit

Permalink
fix(core): avoid referring to arguments in arrow functions (#3127)
Browse files Browse the repository at this point in the history
  • Loading branch information
lacolaco committed Feb 7, 2022
1 parent 058d624 commit 8b693e4
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/zones.ts
Expand Up @@ -145,14 +145,15 @@ 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') {
macrotask.invoke();
}
}, 10);
}
return run(() => it.apply(_this, arguments));
return run(() => it.apply(_this, _arguments));
};
};

Expand All @@ -161,18 +162,19 @@ export const ɵzoneWrap = <T= unknown>(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();
Expand Down

0 comments on commit 8b693e4

Please sign in to comment.