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

Fix global.keys() bug in function node (#1417)

* Fix global.keys() bug in function node

* Filter set(), get() and keys() in global.keys() method
This commit is contained in:
Kazuhito Yokoi 2017-10-11 05:13:38 +09:00 committed by Nick O'Leary
parent 3479c794de
commit 0634a97598
2 changed files with 24 additions and 1 deletions

View File

@ -28,7 +28,14 @@ function createContext(id,seed) {
util.setMessageProperty(data,key,value); util.setMessageProperty(data,key,value);
} }
obj.keys = function() { 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; return obj;
} }

View File

@ -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) { function testNonObjectMessage(functionText,done) {
var flow = [{id:"n1",type:"function",wires:[["n2"]],func:functionText}, var flow = [{id:"n1",type:"function",wires:[["n2"]],func:functionText},
{id:"n2", type:"helper"}]; {id:"n2", type:"helper"}];