Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScriptContext support for nashorn #28

Closed
srinivasarajuch opened this issue Jan 22, 2018 · 2 comments
Closed

ScriptContext support for nashorn #28

srinivasarajuch opened this issue Jan 22, 2018 · 2 comments

Comments

@srinivasarajuch
Copy link

Hi,

Currently, this library is providing option to set java object as a JS global variable. It is not giving an option to set ScriptContext, which is very useful feature form nashorn library to scoping the script execution as below

ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("nashorn");

// define a different script context
ScriptContext newContext = new SimpleScriptContext();
newContext.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE);
Bindings engineScope = newContext.getBindings(ScriptContext.ENGINE_SCOPE);

    // set the variable to a different value in another scope
    engineScope.put("x", "world");

    // evaluate the same code but in a different script context (x = "world")
    engine.eval("print(x)", newContext);

It would be very helpful if you expose the option to set the script context

@srinivasarajuch
Copy link
Author

I have created pull request with the above changes. Please review it.

#29

javadelight added a commit that referenced this issue Jan 23, 2018
ScriptContext support for nashorn #28 : Added support for ScriptContext to support engine level scope.
@javadelight
Copy link
Owner

Thank you! The PR is included in the latest released version 0.1.5 which will be available in Maven Central shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants