It would be good to update the explainer with a sketch of how we expect the embedding API given in the appendix to be extended.
Taking inspiration from how the embedding API is extended for exception handling, we can add a new kind of result from func_invoke, SUSPEND a, where a is a continuation address. We can also add a new function cont_resume that behaves exactly like func_invoke, except that it takes a continuation address instead of a function address. Finally, we can allow host functions to result in suspensions, just like we allow them to result in throws. The suspensions need to be able to carry payloads and need to record the types of the parameters necessary to resume the suspending continuation.
This set of changes are sufficient to allow the JS API spec to specify that an error should be thrown when calling an export results in SUSPEND a. It is also sufficient to specify JSPI in terms of core stack switching by having JSPI suspending import wrappers return suspensions to Wasm carrying the suspending promises as payloads and having JSPI promising export wrappers call func_invoke, receive SUSPEND a, then schedule the future resumption of the continuation via cont_resume once the extracted suspending promise is resolved.
It would be good to update the explainer with a sketch of how we expect the embedding API given in the appendix to be extended.
Taking inspiration from how the embedding API is extended for exception handling, we can add a new kind of result from
func_invoke
,SUSPEND a
, wherea
is a continuation address. We can also add a new functioncont_resume
that behaves exactly likefunc_invoke
, except that it takes a continuation address instead of a function address. Finally, we can allow host functions to result in suspensions, just like we allow them to result in throws. The suspensions need to be able to carry payloads and need to record the types of the parameters necessary to resume the suspending continuation.This set of changes are sufficient to allow the JS API spec to specify that an error should be thrown when calling an export results in
SUSPEND a
. It is also sufficient to specify JSPI in terms of core stack switching by having JSPI suspending import wrappers return suspensions to Wasm carrying the suspending promises as payloads and having JSPI promising export wrappers callfunc_invoke
, receiveSUSPEND a
, then schedule the future resumption of the continuation viacont_resume
once the extracted suspending promise is resolved.