Fix Nashorn error: has no such function getHandlerList.

This commit is contained in:
TennysonHolloway 2014-06-05 15:55:19 -07:00
parent 20519d88db
commit 553bec363b

View file

@ -108,21 +108,20 @@ exports.on = function(
} else { } else {
priority = bkEventPriority[priority.toUpperCase()]; priority = bkEventPriority[priority.toUpperCase()];
} }
if ( typeof eventType == 'string' ) { if ( typeof Java != 'undefined' ) {
/* //Nashorn doesn't like when getHandlerList is in a superclass of your event
Nashorn doesn't support bracket notation for accessing packages. //so to avoid this problem, call getHandlerList using java.lang.reflect
E.g. java.net will work but java['net'] won't. //methods
handlerList = java.lang.Class.forName(bkEventPackage + '' + eventType)
https://bugs.openjdk.java.net/browse/JDK-8031715 .getMethod("getHandlerList").invoke(null);
*/ //rhino environment doesn't have this issue.
if ( typeof Java != 'undefined' ) { } else if ( typeof eventType == 'string' ) {
// nashorn environment
eventType = Java.type( bkEventPackage + eventType );
} else {
eventType = eval( bkEventPackage + eventType ); eventType = eval( bkEventPackage + eventType );
} handlerList = eventType.getHandlerList( );
} else {
handlerList = eventType.getHandlerList( );
} }
handlerList = eventType.getHandlerList( );
var result = { }; var result = { };
eventExecutor = new bkEventExecutor( { eventExecutor = new bkEventExecutor( {