-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
I'm very excited about using JavaScript promise integration once it starts gaining runtime support. I notice that it is an all or nothing thing right now: if we compile with -sASYNCIFY=2 then the emitted code won't run at all on a runtime missing JSPI. It would be great to feature detect JSPI and have a fallback in case it is missing. For example this would be very useful for code splitting: If JSPI is present, we can lazily load code with EM_JS_ASYNC, if it is missing we can fall back to eagerly loading everything at initialization time.
If JSPI is missing, instrumentWasmImports could make calling the imports into an error, and instrumentWasmExports could call the export$func wrapper function with a dummy value for the externref first argument and wrap the result in Promise.resolve.
If we also want to work in the case that externref support is missing, we would have to dynamically generate the import and export wrappers. This should be similar to createDyncallWrapper but simpler.
I am happy to implement this if you are interested in supporting it.