Skip to content

Feature request: Fallback for -sASYNCIFY=2 #18652

@hoodmane

Description

@hoodmane

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions