|
21 | 21 |
|
22 | 22 | import static org.assertj.core.api.Assertions.assertThat; |
23 | 23 |
|
| 24 | +import com.oracle.truffle.js.scriptengine.GraalJSScriptEngine; |
24 | 25 | import java.io.File; |
25 | 26 | import java.io.IOException; |
26 | 27 | import java.io.Reader; |
|
35 | 36 | import java.util.ArrayList; |
36 | 37 | import java.util.Arrays; |
37 | 38 | import java.util.Collections; |
38 | | -import java.util.EnumSet; |
39 | 39 | import java.util.List; |
40 | 40 | import java.util.Locale; |
41 | 41 | import java.util.Optional; |
42 | 42 | import java.util.function.Consumer; |
43 | 43 | import java.util.stream.Stream; |
44 | 44 | import javax.script.Compilable; |
45 | | -import javax.script.ScriptEngineManager; |
46 | 45 | import javax.script.ScriptException; |
47 | 46 | import org.apache.commons.io.IOUtils; |
48 | 47 | import org.apache.commons.lang3.SystemUtils; |
49 | 48 | import org.apache.commons.lang3.mutable.MutableInt; |
50 | 49 | import org.codehaus.groovy.jsr223.GroovyScriptEngineFactory; |
| 50 | +import org.graalvm.polyglot.Context; |
| 51 | +import org.graalvm.polyglot.Engine; |
51 | 52 | import org.jruby.embed.jsr223.JRubyEngineFactory; |
52 | 53 | import org.junit.jupiter.api.AfterAll; |
53 | 54 | import org.junit.jupiter.api.BeforeAll; |
54 | | -import org.junit.jupiter.api.condition.JRE; |
55 | 55 | import org.junit.jupiter.params.ParameterizedTest; |
56 | 56 | import org.junit.jupiter.params.provider.Arguments; |
57 | 57 | import org.junit.jupiter.params.provider.MethodSource; |
@@ -102,15 +102,23 @@ private static Stream<Arguments> scriptsGroovy() { |
102 | 102 | } |
103 | 103 |
|
104 | 104 | private static Stream<Arguments> scriptsJavaScript() { |
105 | | - if (!EnumSet.range(JRE.JAVA_8, JRE.JAVA_14).contains(JRE.currentVersion())) { |
106 | | - // Nashorn is not bundled in Java 15+ |
107 | | - getFilesWithExtension(".js"); |
108 | | - return Stream.empty(); |
109 | | - } |
110 | | - |
111 | | - Compilable engine = (Compilable) new ScriptEngineManager().getEngineByName("ECMAScript"); |
112 | | - assertThat(engine).as("ECMAScript script engine exists.").isNotNull(); |
113 | | - return testData(".js", engine); |
| 105 | + Engine engine = |
| 106 | + Engine.newBuilder() |
| 107 | + .allowExperimentalOptions(true) |
| 108 | + .option("engine.WarnInterpreterOnly", "false") |
| 109 | + .build(); |
| 110 | + |
| 111 | + Context.Builder contextBuilder = |
| 112 | + Context.newBuilder("js") |
| 113 | + .allowExperimentalOptions(true) |
| 114 | + .option("js.syntax-extensions", "true") |
| 115 | + .option("js.load", "true") |
| 116 | + .option("js.print", "true") |
| 117 | + .option("js.nashorn-compat", "true") |
| 118 | + .allowAllAccess(true) |
| 119 | + .hostClassLoader(VerifyScripts.class.getClassLoader()); |
| 120 | + |
| 121 | + return testData(".js", GraalJSScriptEngine.create(engine, contextBuilder)); |
114 | 122 | } |
115 | 123 |
|
116 | 124 | private static Stream<Arguments> scriptsPython() { |
|
0 commit comments