caoccao/Javet

JavetException does not intercept engine errors

Opened this issue · 10 comments

v8.getExecutor("b()").setModule(true).setResourceName("a.js").executeVoid();
v8.await()

ReferenceError: b is not defined at c.js:6:1 2024-04-26 14:38:46.684 6432-6696 nodejs com.proxy.plus E Node.js v20.12.2

The await blocking was used to make the setTimeout APIs work properly, but the normal error caused it to jump out of the try interception

I failed to see there's any problem. Could you leave the complet code?

我没有看到任何问题。你能留下完成代码吗?

try {
bindModule();
v8.setV8ModuleResolver(new IV8ModuleResolver() {
@OverRide
public IV8Module resolve(V8Runtime v8Runtime, String resourceName, IV8Module v8ModuleReferrer) throws JavetException {
v8Runtime.setV8ModuleResolver(new JavetBuiltInModuleResolver());
return v8Runtime.getExecutor(com.editor.async.files.file.READ(new File(path).getParent() + "/"+resourceName)).setModule(true).setResourceName(resourceName).compileV8Module();
}
});

        JavetProxyConverter javetProxyConverter = new JavetProxyConverter();
        javetProxyConverter.getConfig().setReflectionObjectFactory(new IJavetReflectionObjectFactory() {
            @Override
            public Object toObject(Class<?> type, V8Value v8Value) {
                return null;
            }
        });
        v8.setConverter(javetProxyConverter);
        JavetJVMInterceptor javetJVMInterceptor = new JavetJVMInterceptor(v8);
        javetJVMInterceptor.register(v8.getGlobalObject());

        V8ValueObject v = v8.getGlobalObject().get("javet");
        v8.getGlobalObject().set("jvm", v);

        v8.getExecutor(data).setModule(true).setResourceName(com.editor.async.files.file.getName(file)).executeVoid();
        v8.await();

    } catch (JavetException e) {
        
    }

我没有看到任何问题。你能留下完成代码吗?

The data is the above js code, which deliberately throws an error, but it can't be intercepted

我没有看到任何问题。你能留下完成代码吗?

l

I failed to see there's any problem. Could you leave the complet code?

But setMod(true), it won't be caught

If you execute that module, you'll get a Promise. The exception is in that Promise.

如果你执行该模块,你会得到一个 Promise。例外是那个应许。

Yes, I got a Promise, but I don't know how to manipulate it, can I give a clear indication

如果你执行该模块,你会得到一个 Promise。例外是那个应许。

I tried to call the ending method and catch inside, but I couldn't

If you execute that module, you'll get a Promise. The exception is in that Promise.

Thank you very much, I saw the post of other feedback, it has been resolved, thank you again!