mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Clone the first message passed to node.send in Function
Also introduces an optional second arg to node.send in the Function node that can disable that cloning
This commit is contained in:
@@ -19,7 +19,7 @@ module.exports = function(RED) {
|
||||
var util = require("util");
|
||||
var vm = require("vm");
|
||||
|
||||
function sendResults(node,send,_msgid,msgs) {
|
||||
function sendResults(node,send,_msgid,msgs,cloneFirstMessage) {
|
||||
if (msgs == null) {
|
||||
return;
|
||||
} else if (!util.isArray(msgs)) {
|
||||
@@ -35,6 +35,10 @@ module.exports = function(RED) {
|
||||
var msg = msgs[m][n];
|
||||
if (msg !== null && msg !== undefined) {
|
||||
if (typeof msg === 'object' && !Buffer.isBuffer(msg) && !util.isArray(msg)) {
|
||||
if (msgCount === 0 && cloneFirstMessage !== false) {
|
||||
msgs[m][n] = RED.util.cloneMessage(msgs[m][n]);
|
||||
msg = msgs[m][n];
|
||||
}
|
||||
msg._msgid = _msgid;
|
||||
msgCount++;
|
||||
} else {
|
||||
@@ -80,7 +84,7 @@ module.exports = function(RED) {
|
||||
"trace:__node__.trace,"+
|
||||
"on:__node__.on,"+
|
||||
"status:__node__.status,"+
|
||||
"send:function(msgs){ __node__.send(__send__,__msgid__,msgs);},"+
|
||||
"send:function(msgs,cloneMsg){ __node__.send(__send__,__msgid__,msgs,cloneMsg);},"+
|
||||
"done:__done__"+
|
||||
"};\n"+
|
||||
this.func+"\n"+
|
||||
@@ -114,8 +118,8 @@ module.exports = function(RED) {
|
||||
trace: function() {
|
||||
node.trace.apply(node, arguments);
|
||||
},
|
||||
send: function(send, id, msgs) {
|
||||
sendResults(node, send, id, msgs);
|
||||
send: function(send, id, msgs, cloneMsg) {
|
||||
sendResults(node, send, id, msgs, cloneMsg);
|
||||
},
|
||||
on: function() {
|
||||
if (arguments[0] === "input") {
|
||||
@@ -241,7 +245,7 @@ module.exports = function(RED) {
|
||||
context.done = done;
|
||||
|
||||
this.script.runInContext(context);
|
||||
sendResults(this,send,msg._msgid,context.results);
|
||||
sendResults(this,send,msg._msgid,context.results,false);
|
||||
if (handleNodeDoneCall) {
|
||||
done();
|
||||
}
|
||||
|
Reference in New Issue
Block a user