diff --git a/red/runtime/nodes/context.js b/red/runtime/nodes/context.js index 965f8c264..e71a1eaed 100644 --- a/red/runtime/nodes/context.js +++ b/red/runtime/nodes/context.js @@ -28,7 +28,14 @@ function createContext(id,seed) { util.setMessageProperty(data,key,value); } obj.keys = function() { - return Object.keys(data); + var keysData = Object.keys(data); + if (seed == null) { + return keysData; + } else { + return keysData.filter(function (key) { + return key !== "set" && key !== "get" && key !== "keys"; + }); + } } return obj; } diff --git a/test/nodes/core/core/80-function_spec.js b/test/nodes/core/core/80-function_spec.js index 793aef07b..6a4407c71 100644 --- a/test/nodes/core/core/80-function_spec.js +++ b/test/nodes/core/core/80-function_spec.js @@ -160,6 +160,22 @@ describe('function node', function() { }); }); + it('should get keys in global context', function(done) { + var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"msg.payload=global.keys();return msg;"}, + {id:"n2", type:"helper"}]; + helper.load(functionNode, flow, function() { + var n1 = helper.getNode("n1"); + var n2 = helper.getNode("n2"); + n1.context().global.set("count","0"); + n2.on("input", function(msg) { + msg.should.have.property('topic', 'bar'); + msg.should.have.property('payload', ['count']); + done(); + }); + n1.receive({payload:"foo",topic: "bar"}); + }); + }); + function testNonObjectMessage(functionText,done) { var flow = [{id:"n1",type:"function",wires:[["n2"]],func:functionText}, {id:"n2", type:"helper"}];