diff --git a/nodes/core/core/80-function.js b/nodes/core/core/80-function.js index 08fbce1f4..28cacb11c 100644 --- a/nodes/core/core/80-function.js +++ b/nodes/core/core/80-function.js @@ -19,7 +19,7 @@ module.exports = function(RED) { var vm = require("vm"); var fs = require('fs'); var fspath = require('path'); - + function FunctionNode(n) { RED.nodes.createNode(this,n); this.name = n.name; @@ -30,42 +30,42 @@ module.exports = function(RED) { try { this.script = vm.createScript(functionText); this.on("input", function(msg) { - if (msg != null) { - var sandbox = {msg:msg,console:console,util:util,Buffer:Buffer,context:this.context}; - try { - this.script.runInNewContext(sandbox); - var results = sandbox.results; - - if (results == null) { - results = []; - } else if (results.length == null) { - results = [results]; - } - if (msg._topic) { - for (var m in results) { - if (results[m]) { - if (util.isArray(results[m])) { - for (var n in results[m]) { - results[m][n]._topic = msg._topic; - } - } else { - results[m]._topic = msg._topic; + if (msg != null) { + var sandbox = {msg:msg,console:console,util:util,Buffer:Buffer,context:this.context}; + try { + this.script.runInNewContext(sandbox); + var results = sandbox.results; + + if (results == null) { + results = []; + } else if (results.length == null) { + results = [results]; + } + if (msg._topic) { + for (var m in results) { + if (results[m]) { + if (util.isArray(results[m])) { + for (var n in results[m]) { + results[m][n]._topic = msg._topic; } + } else { + results[m]._topic = msg._topic; } } } - this.send(results); - - } catch(err) { - this.error(err); } + this.send(results); + + } catch(err) { + this.error(err); } + } }); } catch(err) { this.error(err); } } - + RED.nodes.registerType("function",FunctionNode); RED.library.register("functions"); } diff --git a/nodes/core/core/80-template.js b/nodes/core/core/80-template.js index e5939537c..aafb893e4 100644 --- a/nodes/core/core/80-template.js +++ b/nodes/core/core/80-template.js @@ -18,24 +18,23 @@ module.exports = function(RED) { var mustache = require("mustache"); var util = require("util"); var fs = require('fs'); - + function TemplateNode(n) { RED.nodes.createNode(this,n); this.name = n.name; this.template = n.template; this.on("input", function(msg) { - if (msg != null) { - try { - msg.payload = mustache.render(this.template,msg) - this.send(msg); - } catch(err) { - this.error(err.message); - } + if (msg != null) { + try { + msg.payload = mustache.render(this.template,msg) + this.send(msg); + } catch(err) { + this.error(err.message); } + } }); } - + RED.nodes.registerType("template",TemplateNode); - RED.library.register("templates"); } diff --git a/nodes/core/core/90-comment.js b/nodes/core/core/90-comment.js index 2cb5ed75d..759b16207 100644 --- a/nodes/core/core/90-comment.js +++ b/nodes/core/core/90-comment.js @@ -18,6 +18,5 @@ module.exports = function(RED) { function CommentNode(n) { RED.nodes.createNode(this,n); } - RED.nodes.registerType("comment",CommentNode); }