久々のnashorn

実は最近の版のnashornは速いんだけどliveconnectまわり、つまりjavaの型まわりがダメダメなままなのでまともに動きません。
例えばこのJOGLコード、newtでwindowを表示するだけでも回避策のグルーコードを入れる必要があります。

// imports classes
var newt = new JavaImporter(
 Packages.com.jogamp.newt.NewtFactory,
 Packages.com.jogamp.newt.event.WindowListener,
 Packages.com.jogamp.newt.event.WindowEvent,
 Packages.com.jogamp.newt.event.KeyListener,
 Packages.com.jogamp.newt.event.KeyEvent,
 Packages.com.jogamp.newt.opengl.GLWindow
);
var gl = new JavaImporter(
 javax.media.opengl.GLProfile,
 javax.media.opengl.GLCapabilities,
 javax.media.opengl.GLEventListener,
 com.jogamp.opengl.util.awt.TextRenderer
);

load("Assets.js")

var font = java.awt.Font.createFont(
 java.awt.Font.TRUETYPE_FONT, Assets.getStream("./res/TakaoExGothic.ttf")
);
var W = 16;
var H = 9;
var Z = 8;

// config screen
// nashorn bug
//var glProfile = gl.GLProfile.get(gl.GLProfile.GL2ES2);
var glProfile = gl.GLProfile.get("GL2ES2");
var glCapabilities = new gl.GLCapabilities(glProfile);

var COLOR_BITS = 8;
glCapabilities.alphaBits = COLOR_BITS
glCapabilities.blueBits  = COLOR_BITS
glCapabilities.greenBits = COLOR_BITS

newt.NewtFactory.setUseEDT(true);

// create each elements
var display = newt.NewtFactory.createDisplay(null);// native display
var screen = newt.NewtFactory.createScreen(display, 0);
var window = newt.GLWindow.create(newt.NewtFactory.createWindow(screen, glCapabilities));

// listener settings
var quit = false;

window.addGLEventListener(new gl.GLEventListener({
 "display" : function(drawable){
  var gl2 = drawable.getGL().getGL2();
  var i = drawable.insets;
  var w = drawable.width  - i.totalWidth;
     var h = drawable.height - i.totalHeight;
  var left = i.leftWidth;
  var top = drawable.height - i.topHeight;
  this.renderer.beginRendering(drawable.width, drawable.height, true);
   this.renderer.draw("あいうえお", left, top);
  this.renderer.endRendering();

 },
 "dispose" : function(drawable){
 },
 "init" : function(drawable){
  print(drawable.width, drawable.height);
  this.D_FACTOR = drawable.width / W;
  this.renderer = new gl.TextRenderer(font.deriveFont(0, 32) , true, true);
     var gl2 = drawable.getGL().getGL2();
  gl2.glShadeModel(gl2.GL_SMOOTH);

  gl2.glEnable(gl2.GL_BLEND);
  gl2.glBlendFunc(gl2.GL_SRC_ALPHA, gl2.GL_ONE);

  gl2.glHint(
   gl2.GL_PERSPECTIVE_CORRECTION_HINT,
   gl2.GL_NICEST
  );
  gl2.glHint(
   gl2.GL_POINT_SMOOTH_HINT,
   gl2.GL_NICEST
  );
  gl2.glEnable(gl2.GL_TEXTURE_2D);

     gl2.glMatrixMode(gl2.GL_PROJECTION);

     gl2.glLoadIdentity();
     gl2.glFrustum(
      - W/2, W/2,
      - H/2, H/2,
      - Z/2, Z/2
     );
     gl2.glMatrixMode(gl2.GL_MODELVIEW);
     gl2.glLoadIdentity();
     gl2.glTranslated(0, 0, 0);
 },
 "reshape" : function(drawable, x, y, width, height){
 }
}));

window.addWindowListener(new newt.WindowListener({
 "windowDestroyed" : function(e){},
 "windowDestroyNotify" : function(e){ quit = true; },
 "windowGainedFocus" : function(e){},
 "windowLostFocus" : function(e){},
 "windowMoved" : function(e){},
 "windowRepaint" : function(e){},
 "windowResized" : function(e){}
}));

window.addKeyListener(new newt.KeyListener({
 "keyPressed" : function(e){},
 "keyReleased" : function(e){
  if(e.keyCode == newt.KeyEvent.VK_ESCAPE){
   window.sendWindowEvent(newt.WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY);
  }
 },
 "keyTyped" : function(e){}
}));

window.title = "NewtTest";
window.undecorated = false;
window.setSize(1280, 720);
window.setUpdateFPSFrames(60, java.lang.System.out);
window.visible = true;

// task for newt event loop.
// don't work nashorn
/*(new java.lang.Thread(function (){
 do{
  window.display();
 }while (!quit);
 window.destroy();
 screen.destroy();
 display.destroy();
})).start();*/
(function (){
 do{
  window.display();
 }while (!quit);
 window.destroy();
 screen.destroy();
 display.destroy();
})();

ちょっと進んでJOGLのサンプルをベタ移植したものとなると状況はもっと悪化します。回避策を講じようにもnashornはrhinoと違ってデバッガがない(あるんだろうか?)のでどこが正常に動いてないか見つけることも困難です。

型まわりがダメダメななのは初期からですが一向に改善しません。
そろそろjava8がGAというかもう既にAPIフリーズなのであとは期間内にバグがどれだけ減るかの話になってきました。