]> git.basschouten.com Git - openhab-addons.git/commitdiff
[jsscripting] Update GraalJS to 21.3 to allow method selection via JavaScript (#11437)
authorLukasA83 <58861945+LukasA83@users.noreply.github.com>
Sat, 6 Nov 2021 18:18:40 +0000 (19:18 +0100)
committerGitHub <noreply@github.com>
Sat, 6 Nov 2021 18:18:40 +0000 (19:18 +0100)
Signed-off-by: Lukas Agethen <lukas83@gmx.de>
bundles/org.openhab.automation.jsscripting/pom.xml
bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/ClassExtender.java [deleted file]
bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/OpenhabGraalJSScriptEngine.java

index e8868bb24bdbbbb927c341d1d737098b54bbb0fd..5a5ff68b054ccc60779caf0186748e90f92ef6d4 100644 (file)
@@ -22,7 +22,7 @@
       !jdk.internal.reflect.*,
       !jdk.vm.ci.services
     </bnd.importpackage>
-    <graal.version>20.1.0</graal.version>
+    <graal.version>21.3.0</graal.version>
     <asm.version>6.2.1</asm.version>
     <oh.version>${project.version}</oh.version>
   </properties>
@@ -81,7 +81,7 @@
     <dependency>
       <groupId>com.ibm.icu</groupId>
       <artifactId>icu4j</artifactId>
-      <version>62.1</version>
+      <version>69.1</version>
     </dependency>
 
     <!-- include as version required is older than OH provides -->
diff --git a/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/ClassExtender.java b/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/ClassExtender.java
deleted file mode 100644 (file)
index d3a1623..0000000
+++ /dev/null
@@ -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);
-    }
-}
index aa62c1308592e4107c35079c6272c3ad19e59517..9f29b0d99d2c768072a1ec1e4ec6c725f3e91f72 100644 (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()) {