Skip to content

Commit

Permalink
Merge pull request #165 from javadelight/test-es6
Browse files Browse the repository at this point in the history
Adding explicit test for ES6 Support
  • Loading branch information
mxro authored Dec 22, 2024
2 parents e4cd990 + ce9aab9 commit 04f0541
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
14 changes: 8 additions & 6 deletions injectJs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
31 changes: 31 additions & 0 deletions src/test/java/delight/nashornsandbox/TestES6.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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();

}

}

0 comments on commit 04f0541

Please sign in to comment.