-
Notifications
You must be signed in to change notification settings - Fork 83
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
Enabling ES6? #164
Comments
Thank you for your question! Yes, that is supported, see example: package delight.nashornsandbox;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.script.ScriptException;
import org.junit.Test;
import delight.nashornsandbox.exceptions.ScriptCPUAbuseException;
public class TestES6 {
@Test
public void test() throws ScriptCPUAbuseException, ScriptException {
NashornSandbox sandbox = NashornSandboxes.create("--language=es6");
sandbox.setMaxCPUTime(100);
sandbox.setMaxMemory(1000 * 1000);
ExecutorService executor = Executors.newSingleThreadExecutor();
sandbox.setExecutor(executor);
sandbox.eval("let greetUsers = (users) => {"+
" users.forEach((args) => {"+
" console.log(`Hello, ${args.name}! You are ${args.age} years old.`);"+
"});"+
"};");
sandbox.getExecutor().shutdown();
}
} Note that Nashorn does not support all ES6 features. Not sure where the latest documentation is, but this one gives some idea: https://openjdk.org/jeps/292 |
Thank you -- you should probably document this in the main |
Great idea! I've added this into the polyfill PR as well, see here https://github.com/javadelight/delight-nashorn-sandbox/pull/167/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5 I thought easiest would just be to change the default in all the examples to es6 - given there should be little downside in using that, and should be easy enough to remove? |
Can this sandbox start Nashorn as follows?:
And even if you can get an engine, how do you turn the engine into a sandbox, so you can call
setMaxCPUTime
etc.?The text was updated successfully, but these errors were encountered: