diff --git a/docs/release-notes.md b/docs/release-notes.md index 82b80a3..98fdb85 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -2,7 +2,7 @@ ## Version 2.0.6 -Fixed issues #122 #123 +Fixed issues #115 #122 #123 Improved background processing of Drone build commands. diff --git a/src/main/js/lib/scriptcraft.js b/src/main/js/lib/scriptcraft.js index 6b0081f..88f7546 100644 --- a/src/main/js/lib/scriptcraft.js +++ b/src/main/js/lib/scriptcraft.js @@ -640,15 +640,7 @@ function __onEnable ( __engine, __plugin, __script ) global.self = sender; global.__engine = __engine; try { - if ( typeof eval == 'undefined' ) { - jsResult = __engine.eval(fnBody); - } else { - /* - nashorn - https://bugs.openjdk.java.net/browse/JDK-8034055 - */ - jsResult = eval( fnBody ); - } + jsResult = __engine.eval(fnBody); if ( typeof jsResult != 'undefined' ) { if ( jsResult == null) { sender.sendMessage('(null)'); @@ -661,8 +653,13 @@ function __onEnable ( __engine, __plugin, __script ) sender.sendMessage( 'Error while trying to evaluate javascript: ' + fnBody + ', Error: '+ e ); throw e; } finally { - delete global.self; - delete global.__engine; + /* + wph 20140312 don't delete self on nashorn until https://bugs.openjdk.java.net/browse/JDK-8034055 is fixed + */ + if ( typeof Java === 'undefined' ) { // Java is an object in Nashorn + delete global.self; + delete global.__engine; + } } } if ( cmdName == 'jsp' ) { diff --git a/src/main/js/lib/tabcomplete.js b/src/main/js/lib/tabcomplete.js index 3cbdec2..37c0774 100644 --- a/src/main/js/lib/tabcomplete.js +++ b/src/main/js/lib/tabcomplete.js @@ -36,6 +36,15 @@ var _getProperties = function( o ) { typeofProperty; if ( _isJavaObject( o ) ) { + /* + fix for issue #115 - java objects are not iterable + see: http://mail.openjdk.java.net/pipermail/nashorn-dev/2014-March/002790.html + */ + if ( typeof Object.bindProperties === 'function' ) { + var placeholder = {}; + Object.bindProperties(placeholder, o); + o = placeholder; + } propertyLoop: for ( i in o ) { // @@ -45,7 +54,7 @@ var _getProperties = function( o ) { for ( j = 0; j < _javaLangObjectMethods.length; j++ ) { if ( _javaLangObjectMethods[j] == i ) { continue propertyLoop; - } + } } typeofProperty = null; try { @@ -71,9 +80,9 @@ var _getProperties = function( o ) { if ( i.match( /^[^_]/ ) ) { if ( typeof o[i] == 'function' ) { result.push( i+'()' ); - } else { + } else { result.push( i ); - } + } } } } @@ -130,6 +139,8 @@ var onTabCompleteJS = function( result, cmdSender, pluginCmd, cmdAlias, cmdArgs symbol = global[name]; + //print('DEBUG: name=' + name + ',symbol=' + symbol); + lastGoodSymbol = symbol; if ( typeof symbol !== 'undefined' ) { for ( i = 1; i < parts.length; i++ ) { @@ -140,10 +151,14 @@ var onTabCompleteJS = function( result, cmdSender, pluginCmd, cmdAlias, cmdArgs symbol = symbol[name]; // this causes problem in jre8 if name is '' if ( typeof symbol == 'undefined' ) { break; - } + } + // nashorn - object[missingProperty] returns null not undefined + if ( symbol == null ) { + break; + } lastGoodSymbol = symbol; } - if ( typeof symbol == 'undefined' ) { + if ( typeof symbol == 'undefined' || symbol === null) { // // look up partial matches against last good symbol // @@ -165,8 +180,8 @@ var onTabCompleteJS = function( result, cmdSender, pluginCmd, cmdAlias, cmdArgs // //print('debug:case Y: ScriptCraft.co'); - li = statement.lastIndexOf(name); - for ( i = 0; i < objectProps.length; i++ ) { + li = statement.lastIndexOf(name); + for ( i = 0; i < objectProps.length; i++ ) { if ( objectProps[i].indexOf(name) == 0 ) { candidate = lastSymbol.substring( 0, lastSymbol.lastIndexOf( name ) ); candidate = candidate + objectProps[i];