Skip to content

Commit 598b2fa

Browse files
committed
Avoid mutating parameterArray
1 parent c47703c commit 598b2fa

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

trackers/javascript-tracker/src/in_queue.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,14 @@ export function InQueueManager(functionName: string, asyncQueue: Array<unknown>)
266266
fnTrackers[tracker.id.replace(`${functionName}_`, '')] = tracker;
267267
}
268268

269-
// Append the `fnTrackers` object to the parameterArray, to allow it to be
270-
// accessed as the final argument in the callback, useful in environments that don't support `this` (GTM)
271-
Array.prototype.push.call(parameterArray, fnTrackers);
269+
// Create a new array from `parameterArray` to avoid mutating the original
270+
const parameterArrayCopy = Array.prototype.slice.call(parameterArray);
272271

273-
input.apply(fnTrackers, parameterArray);
272+
// Add the `fnTrackers` object as the last element of the new array to allow it to be accessed in the callback
273+
// as the final argument, useful in environments that don't support `this` (GTM)
274+
const args = Array.prototype.concat.apply(parameterArrayCopy, [fnTrackers]);
275+
276+
input.apply(fnTrackers, args);
274277
} catch (ex) {
275278
LOG.error('Tracker callback failed', ex);
276279
} finally {

0 commit comments

Comments
 (0)