quickjs
quickjs copied to clipboard
An exception escapes try/catch block in an async function
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