Error ignored / infinite hang with async function in Promise constructor
I was playing around and noticed another funny behavior... Documenting it here in case it's helpful! (Sorry for all the issues 😄)
Minimal example:
package main
import (
"fmt"
"github.com/buke/quickjs-go"
)
func main() {
rt := quickjs.NewRuntime(quickjs.WithExecuteTimeout(1))
ctx := rt.NewContext()
fmt.Println(ctx.LoadModule(`
export default 123;
// This "async" VVVVV causes this code to hang forever.
await new Promise(async (res, rej) => {
// This line should error.
// Try removing the "async" to see.
undefinedVariable(3)
res(true)
});
`, "mod"))
}
While I don't know why anybody would use this pattern intentionally, is legal code, and in my testing, Chrome throws the error and shows in the console.
As far as I can tell, this is not an encouraged pattern of Promise usage since exceptions inside the callback will not be properly handled, but can be helpful if you want to use eg. for await loops inside of a promise.
And I think hanging forever is probably not the most useful behavior here - if you replace the error line with while(true); then the execution limit still does not trigger.
yeah, I track the code ,it will hanging forever in https://github.com/buke/quickjs-go/blob/1189365c62de07db3a85015132ab467600e38b18/bridge.c#L587
it seems quicks C js_std_await function loop for ever, maybe should report to https://github.com/bellard/quickjs