Call javascript from java step by step

Is there a way to execute a java script from a java program in stages?

I know how to call javascript from java. I know about Rhino or Beanshell. There is no web server.

What I'm trying to achieve: Several scripts are executed by a semi-command scheduled scheduler, where each script receives a "tick" each time, and then when it executes one atomic command, as in a debugger. This should also β€œenter” into functions for / while loops.

I need to call the script 'tick' at a specific time (and return immediately), so real threads are useless.

So, I think I need a way to debug a script from a java program without using a debugger (and its overhead). It just takes a step-by-step execution.

Any ideas?

+4
source share
2 answers

Yes, it is possible with the help of an interpreter. More specifically, you need a JavaScript interpreter that can be run on the JVM. Rhino seems to be the most popular.

http://www.mozilla.org/rhino/

If you use scripts at the same time, you will need an interpreter for each parallel script.

+3
source

Source: https://habr.com/ru/post/1396784/


All Articles