From e60d162a39f8596fb630434dc45b57d5be80e27a Mon Sep 17 00:00:00 2001 From: QuintinKruger Date: Mon, 28 Jul 2025 21:24:25 +0200 Subject: [PATCH 1/2] Set callback to undefined using index rather than splice which changes dimension of array not expected given indices for callbacks --- dist/thunderJS.cjs | 6 +++--- dist/thunderJS.js | 4 ++-- module/thunderJS.js | 6 +++--- src/listener.js | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/dist/thunderJS.cjs b/dist/thunderJS.cjs index a72daf4..85b8981 100644 --- a/dist/thunderJS.cjs +++ b/dist/thunderJS.cjs @@ -2,7 +2,7 @@ * If not stated otherwise in this file or this component's LICENSE file the * following copyright and licenses apply: * - * Copyright 2024 Metrological + * Copyright 2025 Metrological * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. @@ -230,8 +230,8 @@ function listener(plugin, event, callback, errorCallback) { dispose() { const listener_id = makeListenerId(plugin, event); if (listeners[listener_id] === undefined) return - listeners[listener_id].splice(index, 1); - if (listeners[listener_id].length === 0) { + listeners[listener_id][index] = undefined; + if (listeners[listener_id].every(item => item === undefined)) { unregister.call(thunder, plugin, event, errorCallback); } }, diff --git a/dist/thunderJS.js b/dist/thunderJS.js index e09882d..7ff63b8 100644 --- a/dist/thunderJS.js +++ b/dist/thunderJS.js @@ -2,7 +2,7 @@ * If not stated otherwise in this file or this component's LICENSE file the * following copyright and licenses apply: * - * Copyright 2024 Metrological + * Copyright 2025 Metrological * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. @@ -17,4 +17,4 @@ * limitations under the License. */ -var ThunderJS=function(){"use strict";function c(n){return(c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n})(n)}function e(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter(function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable})),t.push.apply(t,r)}return t}function t(o){for(var n=1;nn.length)&&(e=n.length);for(var t=0,r=new Array(e);tn.length)&&(e=n.length);for(var t=0,r=new Array(e);t item === undefined)) { unregister.call(thunder, plugin, event, errorCallback); } }, diff --git a/src/listener.js b/src/listener.js index affffe3..4d373db 100644 --- a/src/listener.js +++ b/src/listener.js @@ -31,9 +31,9 @@ export default function(plugin, event, callback, errorCallback) { //early return if the listener is already deleted and someone is calling dispose twice if (listeners[listener_id] === undefined) return - listeners[listener_id].splice(index, 1) - - if (listeners[listener_id].length === 0) { + // invalidate the callback with the given index to mark it as deleted without changing the array dimensions + listeners[listener_id][index] = undefined; + if (listeners[listener_id].every(item => item === undefined)) { unregister.call(thunder, plugin, event, errorCallback) } }, From 86dd353527c7e9f644d79f3a2f9a4e7ad0171c86 Mon Sep 17 00:00:00 2001 From: QuintinKruger Date: Tue, 29 Jul 2025 07:58:21 +0200 Subject: [PATCH 2/2] Handle possiblity of undefined callback function --- dist/thunderJS.cjs | 2 +- dist/thunderJS.js | 2 +- module/thunderJS.js | 2 +- src/api/notificationListener.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/thunderJS.cjs b/dist/thunderJS.cjs index 85b8981..94a6090 100644 --- a/dist/thunderJS.cjs +++ b/dist/thunderJS.cjs @@ -58,7 +58,7 @@ var notificationListener = data => { const callbacks = listeners[data.method]; if (callbacks && Array.isArray(callbacks) && callbacks.length) { callbacks.forEach(callback => { - callback(data.params); + if (callback) callback(data.params); }); } } diff --git a/dist/thunderJS.js b/dist/thunderJS.js index 7ff63b8..d060b80 100644 --- a/dist/thunderJS.js +++ b/dist/thunderJS.js @@ -17,4 +17,4 @@ * limitations under the License. */ -var ThunderJS=function(){"use strict";function c(n){return(c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n})(n)}function e(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter(function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable})),t.push.apply(t,r)}return t}function t(o){for(var n=1;nn.length)&&(e=n.length);for(var t=0,r=new Array(e);tn.length)&&(e=n.length);for(var t=0,r=new Array(e);t { const callbacks = listeners[data.method]; if (callbacks && Array.isArray(callbacks) && callbacks.length) { callbacks.forEach(callback => { - callback(data.params); + if (callback) callback(data.params); }); } } diff --git a/src/api/notificationListener.js b/src/api/notificationListener.js index 5ae0781..e95d446 100644 --- a/src/api/notificationListener.js +++ b/src/api/notificationListener.js @@ -33,7 +33,7 @@ export default data => { const callbacks = listeners[data.method] if (callbacks && Array.isArray(callbacks) && callbacks.length) { callbacks.forEach(callback => { - callback(data.params) + if (callback) callback(data.params) }) } }