Skip to content
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

graaljs: update Graal JavaScript engine #4852

Merged
merged 1 commit into from
Aug 30, 2023
Merged
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: 2 additions & 1 deletion addOns/graaljs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ All notable changes to this add-on will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## Unreleased

### Changed
- Update Graal JavaScript engine.

## [0.4.0] - 2023-07-11
### Added
Expand Down
2 changes: 1 addition & 1 deletion addOns/graaljs/graaljs.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ crowdin {
}

dependencies {
val graalJsVersion = "20.2.0"
val graalJsVersion = "22.3.3"
implementation("org.graalvm.js:js:$graalJsVersion")
implementation("org.graalvm.js:js-scriptengine:$graalJsVersion")
implementation("org.javadelight:delight-graaljs-sandbox:0.1.2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
import java.util.List;
import java.util.Objects;
import javax.script.ScriptEngine;
import javax.script.ScriptException;
import javax.swing.ImageIcon;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Engine;
import org.zaproxy.zap.control.ExtensionFactory;
import org.zaproxy.zap.extension.script.DefaultEngineWrapper;
import org.zaproxy.zap.extension.script.ScriptWrapper;

Expand Down Expand Up @@ -61,28 +62,23 @@ public String getSyntaxStyle() {

@Override
public ScriptEngine getEngine() {
Engine engine =
Engine.newBuilder()
.allowExperimentalOptions(true)
.option("engine.WarnInterpreterOnly", "false")
.build();

Context.Builder contextBuilder =
Context.newBuilder("js")
.allowExperimentalOptions(true)
.option("js.syntax-extensions", "true")
.option("js.load", "true")
.option("js.print", "true")
.option("js.nashorn-compat", "true")
.allowAllAccess(true);
.allowAllAccess(true)
.hostClassLoader(ExtensionFactory.getAddOnLoader());

ScriptEngine se = GraalJSScriptEngine.create(null, contextBuilder);

// Force use of own (add-on) class loader
// https://github.com/graalvm/graaljs/issues/182
ClassLoader previousContextClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
try {
se.eval("");
} catch (ScriptException ignore) {
} finally {
Thread.currentThread().setContextClassLoader(previousContextClassLoader);
}
return se;
return GraalJSScriptEngine.create(engine, contextBuilder);
}

@Override
Expand Down