[jsscripting] Update GraalJS to 21.3 to allow method selection via JavaScript (#11437)

Signed-off-by: Lukas Agethen <lukas83@gmx.de>
This commit is contained in:
LukasA83
2021-11-06 19:18:40 +01:00
committed by GitHub
parent d4510f3fef
commit a6fd6a3545
3 changed files with 8 additions and 40 deletions

View File

@@ -1,37 +0,0 @@
/**
* Copyright (c) 2010-2021 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.automation.jsscripting;
import com.oracle.truffle.js.runtime.java.adapter.JavaAdapterFactory;
/**
* Class utility to allow creation of 'extendable' classes with a classloader of the GraalJS bundle, rather than the
* classloader of the file being extended.
*
* @author Jonathan Gilbert - Initial contribution
*/
public class ClassExtender {
private static ClassLoader classLoader = ClassExtender.class.getClassLoader();
public static Object extend(String className) {
try {
return extend(Class.forName(className));
} catch (ClassNotFoundException e) {
throw new RuntimeException("Cannot find class " + className, e);
}
}
public static Object extend(Class<?> clazz) {
return JavaAdapterFactory.getAdapterClassFor(clazz, null, classLoader);
}
}

View File

@@ -30,6 +30,7 @@ import javax.script.ScriptContext;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Engine;
import org.openhab.automation.jsscripting.internal.fs.DelegatingFileSystem;
import org.openhab.automation.jsscripting.internal.fs.PrefixedSeekableByteChannel;
import org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocable;
@@ -65,10 +66,14 @@ public class OpenhabGraalJSScriptEngine extends InvocationInterceptingScriptEngi
*/
public OpenhabGraalJSScriptEngine() {
super(null); // delegate depends on fields not yet initialised, so we cannot set it immediately
delegate = GraalJSScriptEngine.create(null,
delegate = GraalJSScriptEngine.create(
Engine.newBuilder().allowExperimentalOptions(true).option("engine.WarnInterpreterOnly", "false")
.build(),
Context.newBuilder("js").allowExperimentalOptions(true).allowAllAccess(true)
.option("js.commonjs-require-cwd", MODULE_DIR).option("js.nashorn-compat", "true") // to ease
// migration
.option("js.ecmascript-version", "2021") // nashorn compat will enforce es5 compatibility, we
// want ecma2021
.option("js.commonjs-require", "true") // enable CommonJS module support
.hostClassLoader(getClass().getClassLoader())
.fileSystem(new DelegatingFileSystem(FileSystems.getDefault().provider()) {