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

Handle lookup of undefined property in Global context

Fixes #1978
This commit is contained in:
Nick O'Leary 2018-11-14 20:57:17 +00:00
parent 20a31a6d38
commit 8167608f04
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -210,12 +210,26 @@ function createContext(id,seed) {
insertSeedValues = function(keys,values) {
if (!Array.isArray(keys)) {
if (values[0] === undefined) {
values[0] = util.getObjectProperty(seed,keys);
try {
values[0] = util.getObjectProperty(seed,keys);
} catch(err) {
if (err.code === "INVALID_EXPR") {
throw err;
}
value[0] = undefined;
}
}
} else {
for (var i=0;i<keys.length;i++) {
if (values[i] === undefined) {
values[i] = util.getObjectProperty(seed,keys[i]);
try {
values[i] = util.getObjectProperty(seed,keys[i]);
} catch(err) {
if (err.code === "INVALID_EXPR") {
throw err;
}
value[i] = undefined;
}
}
}
}
@ -257,7 +271,12 @@ function createContext(id,seed) {
return;
}
var results = Array.prototype.slice.call(arguments,[1]);
insertSeedValues(key,results);
try {
insertSeedValues(key,results);
} catch(err) {
callback.apply(err);
return
}
// Put the err arg back
results.unshift(undefined);
callback.apply(null,results);
@ -270,7 +289,14 @@ function createContext(id,seed) {
if (Array.isArray(key)) {
insertSeedValues(key,results);
} else if (results === undefined){
results = util.getObjectProperty(seed,key);
try {
results = util.getObjectProperty(seed,key);
} catch(err) {
if (err.code === "INVALID_EXPR") {
throw err;
}
results = undefined;
}
}
}
return results;