Skip to content

Commit

Permalink
Adding explicit test for ES6 Support
Browse files Browse the repository at this point in the history
  • Loading branch information
mxro committed Dec 22, 2024
1 parent e4cd990 commit a989a14
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/delight/nashornsandbox/NashornSandboxes.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static NashornSandbox create() {
}

/**
* <p>Create a sandbox while supplying arguments for the engine such as '--no-java'.
* <p>Create a sandbox while supplying arguments for the engine such as '--language=es6'.
* <p>More information on available parameters can be found in the following:
* <ul>
* <li><a href='http://hg.openjdk.java.net/jdk8/jdk8/nashorn/file/tip/docs/DEVELOPER_README'>Nashorn DEVELOPER README</a></li>
Expand Down
32 changes: 32 additions & 0 deletions src/test/java/delight/nashornsandbox/TestES6.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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;
import junit.framework.Assert;

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();

}

}

0 comments on commit a989a14

Please sign in to comment.