HarlonWang / quickjs-wrapper

QuickJS wrapper for Android/JVM

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Native receive promise function with exception

HarlonWang opened this issue · comments

复现代码如下:

    @Test
    public void testPromiseUnHandledExceptionWithCall() {
        QuickJSContext context = QuickJSContext.create();
        context.getGlobalObject().setProperty("nativeCall", new JSCallFunction() {
            @Override
            public Object call(Object... args) {
                JSFunction function = (JSFunction) args[0];
                function.call();
                return null;
            }
        });
        context.evaluate("const getData = async () => {\n" +
                "\tconst res = await new Promise(() => {\n" +
                "\t\twindow.setTimeout();\n" +
                "\t});\n" +
                "}\n" +
                "\n" +
                "// function nativeCall(fn) {\n" +
                "// \tfn.call();\n" +
                "// }\n" +
                "\n" +
                "// console.log(getData);\n" +
                "\n" +
                "nativeCall(getData);");
        context.destroyContext();
    }