Skip to content

Commit 8b693e4

Browse files
authored
fix(core): avoid referring to arguments in arrow functions (#3127)
1 parent 058d624 commit 8b693e4

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/zones.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,15 @@ const zoneWrapFn = (it: (...args: any[]) => any, macrotask: MacroTask|undefined)
145145
// function() is needed for the arguments object
146146
// tslint:disable-next-line:only-arrow-functions
147147
return function() {
148+
const _arguments = arguments;
148149
if (macrotask) {
149150
setTimeout(() => {
150151
if (macrotask.state === 'scheduled') {
151152
macrotask.invoke();
152153
}
153154
}, 10);
154155
}
155-
return run(() => it.apply(_this, arguments));
156+
return run(() => it.apply(_this, _arguments));
156157
};
157158
};
158159

@@ -161,18 +162,19 @@ export const ɵzoneWrap = <T= unknown>(it: T, blockUntilFirst: boolean): T => {
161162
// tslint:disable-next-line:only-arrow-functions
162163
return function() {
163164
let macrotask: MacroTask | undefined;
165+
const _arguments = arguments;
164166
// if this is a callback function, e.g, onSnapshot, we should create a microtask and invoke it
165167
// only once one of the callback functions is tripped.
166168
for (let i = 0; i < arguments.length; i++) {
167-
if (typeof arguments[i] === 'function') {
169+
if (typeof _arguments[i] === 'function') {
168170
if (blockUntilFirst) {
169171
macrotask ||= run(() => Zone.current.scheduleMacroTask('firebaseZoneBlock', noop, {}, noop, noop));
170172
}
171173
// TODO create a microtask to track callback functions
172-
arguments[i] = zoneWrapFn(arguments[i], macrotask);
174+
_arguments[i] = zoneWrapFn(_arguments[i], macrotask);
173175
}
174176
}
175-
const ret = runOutsideAngular(() => (it as any).apply(this, arguments));
177+
const ret = runOutsideAngular(() => (it as any).apply(this, _arguments));
176178
if (!blockUntilFirst) {
177179
if (ret instanceof Observable) {
178180
const schedulers = getSchedulers();

0 commit comments

Comments
 (0)