Am 31.01.2017 um 11:39 schrieb Frantzius, Jörg <joerg.frantz...@aperto.com>: > > As the function object is dynamically created within some 3rd party > Javascript that I cannot modify, I’m not able to create a CompiledScript > instead. >
Then your best bet is probably to evaluate the script containing the function for each ScriptContext you’re using it with. The Nashorn-Dev engine should cache the compiled script so it shouldn’t affect performance too much. > Just for some nit-picking, my test was able to call the function without > placing it in parenthesis (the error message was '"foo" is not defined‘, so > execution did enter the function, even though it does not find „foo“ because > that wasn't defined in its closure). So it seems that the function > declaration does not evaluate to undefined, at least not when evaluating it > using engine.eval() from Java. You’re right - that is a bug we fixed in JDK 9. For some reason it wasn’t back ported to 8u, maybe for compatibility reasons. https://bugs.openjdk.java.net/browse/JDK-8086052 Hannes