Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Replace Nashorn with GraalVM JS Engine #3717

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ dependencies {

implementation "com.github.ben-manes.caffeine:caffeine"

implementation "org.graalvm.js:js:${revGraalVM}"
implementation "org.graalvm.js:js-scriptengine:${revGraalVM}"

// JAXB is not bundled with Java 11, dependencies added explicitly
// These are needed by Apache BVAL
implementation "jakarta.xml.bind:jakarta.xml.bind-api:${revJAXB}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@

public class ScriptEvaluator {

private static final ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
private static final ScriptEngine engine =
new ScriptEngineManager().getEngineByName("graal.js");

static {
engine.put("polyglot.js.allowHostAccess", true);
}

private ScriptEvaluator() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ boolean evaluateCondition(WorkflowModel workflow, TaskModel task) throws ScriptE
boolean result = false;
if (condition != null) {
LOGGER.debug("Condition: {} is being evaluated", condition);
// Evaluate the expression by using the Nashorn based script evaluator
// Evaluate the expression by using the GraalVM based script evaluator
result = ScriptEvaluator.evalBool(condition, conditionInput);
}
return result;
Expand Down
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ ext {
revSpock = '1.3-groovy-2.5'
revSpotifyCompletableFutures = '0.3.3'
revTestContainer = '1.15.3'
revGraalVM = '22.3.3'
}
8 changes: 4 additions & 4 deletions docs/docs/reference-docs/do-while-task.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ Branching inside loopOver task is supported.

### Input Parameters:

| name | type | description |
|---------------|------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| loopCondition | String | Condition to be evaluated after every iteration. This is a Javascript expression, evaluated using the Nashorn engine. If an exception occurs during evaluation, the DO_WHILE task is set to FAILED_WITH_TERMINAL_ERROR. |
| loopOver | List[Task] | List of tasks that needs to be executed as long as the condition is true. |
| name | type | description |
|---------------|------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| loopCondition | String | Condition to be evaluated after every iteration. This is a Javascript expression, evaluated using the GraalVM JS engine. If an exception occurs during evaluation, the DO_WHILE task is set to FAILED_WITH_TERMINAL_ERROR. |
| loopOver | List[Task] | List of tasks that needs to be executed as long as the condition is true. |

### Output Parameters

Expand Down
3 changes: 3 additions & 0 deletions java-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ dependencies {
implementation "javax.ws.rs:javax.ws.rs-api:${revJAXRS}"
implementation "org.glassfish.jersey.core:jersey-common:${revJerseyCommon}"

implementation "org.graalvm.js:js:${revGraalVM}"
implementation "org.graalvm.js:js-scriptengine:${revGraalVM}"

testImplementation "org.springframework:spring-web"
testImplementation "org.spockframework:spock-core:${revSpock}"
testImplementation "org.spockframework:spock-spring:${revSpock}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ public class Javascript extends Task<Javascript> {

private static final String EVALUATOR_TYPE_PARAMETER = "evaluatorType";

private static final String ENGINE = "nashorn";
private static final String ENGINE = "graal.js";

private static final String POLYGLOT_JS_ALLOW_HOST_ACCESS = "polyglot.js.allowHostAccess";

/**
* Javascript tasks are executed on the Conductor server without having to write worker code
Expand Down Expand Up @@ -105,6 +107,7 @@ public Javascript validate() {
LOGGER.error("missing " + ENGINE + " engine. Ensure you are running supported JVM");
return this;
}
scriptEngine.put(POLYGLOT_JS_ALLOW_HOST_ACCESS, true);

try {

Expand Down Expand Up @@ -133,6 +136,7 @@ public Object test(Map<String, Object> input) {
LOGGER.error("missing " + ENGINE + " engine. Ensure you are running supported JVM");
return this;
}
scriptEngine.put(POLYGLOT_JS_ALLOW_HOST_ACCESS, true);

try {

Expand Down
Loading