Javet icon indicating copy to clipboard operation
Javet copied to clipboard

JavetException does not intercept engine errors

Open Vectorted opened this issue 2 years ago • 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

Vectorted avatar Apr 26 '24 06:04 Vectorted

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

Vectorted avatar Apr 26 '24 06:04 Vectorted

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

caoccao avatar Apr 26 '24 07:04 caoccao

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

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) {
        
    }

Vectorted avatar Apr 26 '24 07:04 Vectorted

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

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

Vectorted avatar Apr 26 '24 07:04 Vectorted

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

l

Vectorted avatar Apr 26 '24 07:04 Vectorted

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

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

Vectorted avatar Apr 26 '24 09:04 Vectorted

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

caoccao avatar Apr 26 '24 09:04 caoccao

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

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

Vectorted avatar Apr 26 '24 10:04 Vectorted

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

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

Vectorted avatar Apr 26 '24 10:04 Vectorted

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!

Vectorted avatar Apr 26 '24 12:04 Vectorted