quickjs icon indicating copy to clipboard operation
quickjs copied to clipboard

An exception escapes try/catch block in an async function

Open xeioex opened this issue 1 year ago • 0 comments

t1.js

var p = new Promise(() => {throw new Error("Oops")});

async function f() {
    try {
        await p;
    } catch (e) {
        console.log(`Exception caught: ${e.message}`);
    }
}

f()

t2.js

var p = new Promise(() => 0);
Object.defineProperty(p, "constructor", {get: () => ({}).a.a});

async function f() {
    try {
        await p;
    } catch (e) {
        console.log(`Exception caught: ${e.message}`);
    }
}

f()
$ qjs  t1.js 
Exception caught: Oops

$ qjs  t2.js ; echo $?
0

xeioex avatar Feb 10 '24 02:02 xeioex