1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Add 'node' object to Function close scope

This commit is contained in:
Nick O'Leary 2021-02-17 14:41:50 +00:00
parent 11475b0c38
commit d5f4f987f2
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -347,7 +347,21 @@ module.exports = function(RED) {
} }
node.script = vm.createScript(functionText, createVMOpt(node, "")); node.script = vm.createScript(functionText, createVMOpt(node, ""));
if (node.fin && (node.fin !== "")) { 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"); finOpt = createVMOpt(node, " cleanup");
finScript = new vm.Script(finText, finOpt); finScript = new vm.Script(finText, finOpt);
} }