From d5f4f987f209427d7541f62340b9f9267e20aed8 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Wed, 17 Feb 2021 14:41:50 +0000 Subject: [PATCH] Add 'node' object to Function close scope --- .../@node-red/nodes/core/function/10-function.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/node_modules/@node-red/nodes/core/function/10-function.js b/packages/node_modules/@node-red/nodes/core/function/10-function.js index d6abde563..1097e9d1f 100644 --- a/packages/node_modules/@node-red/nodes/core/function/10-function.js +++ b/packages/node_modules/@node-red/nodes/core/function/10-function.js @@ -347,7 +347,21 @@ module.exports = function(RED) { } node.script = vm.createScript(functionText, createVMOpt(node, "")); if (node.fin && (node.fin !== "")) { - var finText = "(function () {\n"+node.fin +"\n})();"; + var finText = `(function () { + var node = { + id:__node__.id, + name:__node__.name, + log:__node__.log, + error:__node__.error, + warn:__node__.warn, + debug:__node__.debug, + trace:__node__.trace, + status:__node__.status, + send: function(msgs, cloneMsg) { + __node__.error("Cannot send from close function"); + } + }; + `+node.fin +`})();`; finOpt = createVMOpt(node, " cleanup"); finScript = new vm.Script(finText, finOpt); }