From 598b2faf6a600fbad4f89f9fde282acf3c0604c7 Mon Sep 17 00:00:00 2001 From: Greg Leonard <45019882+greg-el@users.noreply.github.com> Date: Thu, 23 Jan 2025 14:21:16 +0000 Subject: [PATCH] Avoid mutating `parameterArray` --- trackers/javascript-tracker/src/in_queue.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/trackers/javascript-tracker/src/in_queue.ts b/trackers/javascript-tracker/src/in_queue.ts index 2130cf7fb..3b6a8db90 100644 --- a/trackers/javascript-tracker/src/in_queue.ts +++ b/trackers/javascript-tracker/src/in_queue.ts @@ -266,11 +266,14 @@ export function InQueueManager(functionName: string, asyncQueue: Array) fnTrackers[tracker.id.replace(`${functionName}_`, '')] = tracker; } - // Append the `fnTrackers` object to the parameterArray, to allow it to be - // accessed as the final argument in the callback, useful in environments that don't support `this` (GTM) - Array.prototype.push.call(parameterArray, fnTrackers); + // Create a new array from `parameterArray` to avoid mutating the original + const parameterArrayCopy = Array.prototype.slice.call(parameterArray); - input.apply(fnTrackers, parameterArray); + // Add the `fnTrackers` object as the last element of the new array to allow it to be accessed in the callback + // as the final argument, useful in environments that don't support `this` (GTM) + const args = Array.prototype.concat.apply(parameterArrayCopy, [fnTrackers]); + + input.apply(fnTrackers, args); } catch (ex) { LOG.error('Tracker callback failed', ex); } finally {