caoccao / Javet

Javet is Java + V8 (JAVa + V + EighT). It is an awesome way of embedding Node.js and V8 in Java.
https://www.caoccao.com/Javet/
Apache License 2.0
698 stars 68 forks source link

issue with setResourceName #356

Open Losin6450 opened 3 months ago

Losin6450 commented 3 months ago

Code: `

private static boolean debug = true;

private static final JavetEnginePool<NodeRuntime> pool;

static {
    pool = new JavetEnginePool<>(new JavetEngineConfig()
            .setAllowEval(true)
            .setAutoSendGCNotification(true)
            .setJSRuntimeType(JSRuntimeType.Node)
    );
}

private final Path file;

public Context(File file){
    this.file = file.toPath();
}

public Context(Path path){
    this.file = path;
}

@Override
public void run() {
        if (debug) System.out.println(this.file);
        if (!Files.exists(this.file)){
            try {
                Files.createDirectories(this.file.getParent());
                Files.createFile(this.file);
            } catch (IOException e){
                e.printStackTrace();
                return;
            }
        }
        try (JavetEngine<NodeRuntime> engine = (JavetEngine<NodeRuntime>) pool.getEngine()){
            try (NodeRuntime runtime = engine.getV8Runtime()){
                JavetBridgeConverter converter = new JavetBridgeConverter();
                runtime.setConverter(converter);
                JavetJVMInterceptor interceptor = new JavetJVMInterceptor(runtime);
                try (V8ValueGlobalObject globalObject = runtime.getGlobalObject()){
                    interceptor.register(globalObject);
                }
                runtime.getExecutor(this.file).setModule(true).executeVoid();
                runtime.await();
            }
        } catch (JavetException e) {
            e.printStackTrace();
        }
}

`

Error: [13:23:03] [Server thread/WARN]: com.caoccao.javet.exceptions.JavetExecutionException: TypeError [ERR_INVALID_ARG_TYPE]: The "id" argument must be of type string. Received an instance of String [13:23:03] [Server thread/WARN]: at com.caoccao.javet.interop.V8Native.functionCall(Native Method) [13:23:03] [Server thread/WARN]: at com.caoccao.javet.interop.V8Runtime.functionCall(V8Runtime.java:1074) [13:23:03] [Server thread/WARN]: at com.caoccao.javet.interop.V8Internal.functionCall(V8Internal.java:107) [13:23:03] [Server thread/WARN]: at com.caoccao.javet.values.reference.V8ValueFunction.callExtended(V8ValueFunction.java:97) [13:23:03] [Server thread/WARN]: at com.caoccao.javet.values.reference.IV8ValueFunction.call(IV8ValueFunction.java:56) [13:23:03] [Server thread/WARN]: at com.caoccao.javet.interop.NodeRuntime.getNodeModule(NodeRuntime.java:136) [13:23:03] [Server thread/WARN]: at com.caoccao.javet.interop.NodeRuntime.getNodeModule(NodeRuntime.java:110) [13:23:03] [Server thread/WARN]: at com.caoccao.javet.interop.executors.IV8Executor.setResourceName(IV8Executor.java:230) [13:23:03] [Server thread/WARN]: at com.caoccao.javet.interop.executors.V8PathExecutor.<init>(V8PathExecutor.java:54) [13:23:03] [Server thread/WARN]: at com.caoccao.javet.interop.V8Runtime.getExecutor(V8Runtime.java:1400) [13:23:03] [Server thread/WARN]: at org.grakkit.core.Context.run(Context.java:63)

Losin6450 commented 3 months ago

i have tried different versions and none worked

caoccao commented 3 months ago

Please leave a repo that can reproduce this issue.

Losin6450 commented 3 months ago

https://github.com/Losin6450/JavetIssue356/tree/main