0

I've written some scripts in Javascript under Rhino 1.7, one of them starts a minimal http server and accepts JS commands in input.

Now, if I call (from within Rhino):

engine = ScriptEngineManager().getEngineByName("JavaScript");

I get the builtin JS engine (from Java 1.6), that is an older version of Rhino, and lacks some functions (like JavaAdapter for multiple interfaces).

How do I get the Rhino Engine instead of that? Do I need ScriptEngineManager.getEngineFactories() or what else?

2
  • Sorry for the redundancy, but: the "engine = ScriptEngineManager()..." is a call in your JS? Which is being run in Rhino 1.7, but returning the default Java 6 JS script engine instead of Rhino? Why do you need a new script engine inside of your JS? Or are you trying to get the current engine / why do you need a reference to the current engine inside of your JS? Commented Nov 30, 2009 at 16:10
  • Yes. I need a script to start another interpreter, to avoid using eval(). The first script starts an HTTP server, which serves a single page, with an HTML form in it. The POST method sends a command or file name to the server, and the server-side script executes the code. Commented Dec 1, 2009 at 11:19

3 Answers 3

1

What you want to achieve is to select a certain version of an script engine which implements "JavaScript". The correct way to do that is to call ScriptEngineManager.getEngineFactories() and then check the results of getLanguageName() and getEngineVersion().

Sign up to request clarification or add additional context in comments.

Comments

1

I found it out myself (trial and error). As noted above, Rhino doesn't register an engine factory. You can get the current engine (as a context and a scriptable object):

cx = Context.getCurrentContext();
scope = new ImporterTopLevel(cx);

With these objects, I can run my scripts or command lines using evalString/evalReader.

Comments

0

Before invoking your initial script, why don't you set the engine you're using as a context variable inside the script? That way, inside the script, you'll have access to the engine that is running it.

1 Comment

I'm not sure I understand what you mean. However: changing the java code which runs the javascript engine is what I'm trying to avoid (otherwise I'd implement the whole http-server thing in Java).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.