don't echo result if undefined/null

This commit is contained in:
walterhiggins 2014-04-28 23:29:53 +01:00
parent 3700c11223
commit dc812c934c
2 changed files with 23 additions and 13 deletions

View file

@ -2,5 +2,8 @@ exports.isJavaObject = function( o ) {
if (o === global){
return false;
}
if (o !== undefined && o !== null){
return o.getClass ? true : false;
}
return o instanceof java.lang.Object;
};

View file

@ -651,12 +651,19 @@ function __onEnable ( __engine, __plugin, __script )
global.self = sender;
global.__engine = __engine;
try {
// cannot rely on native eval in jre7 and jre8
// because ...
// js var hearts
// js hearts
// ... throws an execption ('hearts' is not defined). vars are not sticky in native eval .
//
jsResult = __engine.eval( fnBody );
if ( typeof jsResult != 'undefined' ) {
if ( jsResult == null) {
sender.sendMessage('(null)');
// engine eval will return null even if the result should be undefined
// this can be confusing so I think it's better to omit output for this case
// sender.sendMessage('(null)');
} else {
try {
if ( isJavaObject(jsResult) || typeof jsResult === 'function') {