Description
Hello,
If my understanding is correct, in the jerryscript implementation, if an error is thrown when resolving a promise, it will only be passed to the rejection handler (if there is one registered). If there is no promise rejection registered, the error is silently ignored. I am looking for a way to make that error return to the calling function, or some other way to signal it.
My approach was to change ecma_reject_promise()
to take an additional out parameter telling whether the rejection was handled or not. ecma_promise_trigger_reactions()
sets this parameter to false
in case the reactions collection was empty from the start. Based on this, ecma_promise_reject_handler()
will return an error for unhandled rejections.
This works for a snapshot that was loaded, with all the chained promises' reactions registered. In this situation, when a .then()
handler executes, we can determine whether it has a subsequent .catch()
rejection handler chained. If it doesn't, ecma_reject_handler()
returns with an error as expected.
This doesn't work for direct function calls. For instance, a scenario like foo().then()
, where foo()
calls into a C implementation that returns a rejected promise immediately via jerry_resolve_or_reject_promise()
. At this point, I noticed ecma_promise_do_then()
wasn't called yet to register the handlers and schedule the reactions.
I would like opinions on this approach. Do you think the current jerry design allows to signal unhandled errors thrown during exceptions, or it's always up the the developer to chain a .catch()
call for thrown errors?
Thank you!