Congratulations on Nashorn - Question about Bytecode Generation
A. Sundararajan
sundararajan.athijegannathan at oracle.com
Sat Dec 22 19:09:07 PST 2012
Hi Toby,
Thanks for your interest in "nashorn". Thanks for your good words on the
first public release!
There is no support for customization of the generated bytecode. There
could be security and correctness implications of such support. But, I
guess a proposal that takes all such concerns into account can be
discussed definitely.
On manipulatable of parse trees:
* There are open source libraries such as "esprima" which can be used to
generate parse tree as JSON. There is also *experimental* support for
this sort of parse-tree-as-JSON in nashorn as well (please check
"test/script/basic/NASHORN-694.js" in nashorn repo).
* One could think of the following process for code transformation : (1)
parse the user script to get AST-as-JSON (2) manipulate the JSON to
insert hook calls (3) "serialize" AST/JSON to source form string
(apparently, there is "escodegen" for this). and (4) "eval" the
instrumented code produced in step (3).
It is possible to do some experiments along these lines.
PS. Due to holiday season, there may be some delay in responding to the
emails. So, please bear with us. And thanks again for your feedback /
suggestions!
Thanks,
-Sundar
Tobias Downer wrote:
> Hello Nashorn Developers. Congratulations on the first public release!
> I'm really interested to see the performance you'll get out of your
> JavaScript engine.
>
> My question; will (does?) Nashorn support customization of the
> bytecode generator so that we can get it to inject callbacks to our
> own code? I need a feature like this because I need a way to interrupt
> scripts that have been running for too long (gone into an infinite
> loop). To do this, I'd need the bytecode generator to inject a
> callback to my Java code on every JavaScript loop and function call.
> My Java code then might check 'Thread.isInterrupted()' and throw a
> runtime exception.
>
> Rhino supports this with an 'observeInstructionCount' flag/callback on
> the context. Groovy has a more sophisticated parse tree transformation
> API for this sort of thing. I'm wondering if Nashorn has something
> similar.
>
> Regards,
> Toby.
>
More information about the nashorn-dev
mailing list