From 061afb3a9488bc4c79a508496196fea2d14f5ba1 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Sat, 2 Oct 2021 23:25:16 +0100 Subject: [PATCH] Improve RED.actions api to ensure actions cannot be overridden Also alows multiple args to be passed to an action. --- .../@node-red/editor-client/src/js/ui/actions.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/actions.js b/packages/node_modules/@node-red/editor-client/src/js/ui/actions.js index 8ebc97cda..c7c5dd950 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/actions.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/actions.js @@ -4,6 +4,12 @@ RED.actions = (function() { } function addAction(name,handler) { + if (typeof handler !== 'function') { + throw new Error("Action handler not a function"); + } + if (actions[name]) { + throw new Error("Cannot override existing action"); + } actions[name] = handler; } function removeAction(name) { @@ -12,9 +18,11 @@ RED.actions = (function() { function getAction(name) { return actions[name]; } - function invokeAction(name,args) { + function invokeAction() { + var args = Array.prototype.slice.call(arguments); + var name = args.shift(); if (actions.hasOwnProperty(name)) { - actions[name](args); + actions[name].apply(null, args); } } function listActions() {