Skip to content

Commit

Permalink
Handle _initialize non existence in wasi reactor modules
Browse files Browse the repository at this point in the history
The `_initialize` export is optional and may not exist in a wasi
reactor module, according to
https://github.com/WebAssembly/WASI/blob/main/legacy/application-abi.md#current-unstable-abi.
When it doesn't exist, simply don't do anything. This is especially
useful in cases where a module has been pre-initialized by `wizer` and
the `_initialize` export has been stripped.
  • Loading branch information
TerrorJack committed Mar 11, 2024
1 parent d6e62e8 commit 6f7a996
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/wasi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ export default class WASI {

/// Initialize a WASI reactor
initialize(instance: {
exports: { memory: WebAssembly.Memory; _initialize: () => unknown };
exports: { memory: WebAssembly.Memory; _initialize?: () => unknown };
}) {
this.inst = instance;
instance.exports._initialize();
if (instance.exports._initialize) {
instance.exports._initialize();
}
}

constructor(
Expand Down

0 comments on commit 6f7a996

Please sign in to comment.