Package io.github.eutro.wasm2j.embed
Class Module
java.lang.Object
io.github.eutro.wasm2j.embed.Module
A parsed WebAssembly module.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Module
decode
(byte[] bytes) Decode a binary module from a byte array.exports()
Get the exports that this module supplies.static Module
fromNode
(ModuleNode node) Create a module from a JWasm module node.imports()
Get the imports that this module requires.instantiate
(Store store, ExternVal[] imports) Instantiate the module in the given store with the provided values for imports.instantiate
(Store store, BiFunction<String, String, ExternVal> imports) Instantiate the module in the given store with the provided function for looking up imports.instantiate
(Store store, Function<String, Instance> modules) Instantiate the module in the given store with the provided function for looking up modules to import from.static Module
Parse a text module from a string.void
validate()
Validate the module, throwing an exception if the module is invalid.
-
Method Details
-
decode
Decode a binary module from a byte array.- Parameters:
bytes
- The byte array.- Returns:
- The decoded module
-
parse
Parse a text module from a string.- Parameters:
source
- The source string.- Returns:
- The parsed module.
-
fromNode
Create a module from a JWasm module node.The module node will be copied, to prevent exterior mutation.
- Parameters:
node
- The module node.- Returns:
- The new module.
-
validate
public void validate()Validate the module, throwing an exception if the module is invalid.This is idempotent, and will not run validation again if the module has already been validated.
-
instantiate
Instantiate the module in the given store with the provided values for imports.The imports must be in the same order as those returned for
imports()
.- Parameters:
store
- The store.imports
- The supplied imports.- Returns:
- The instantiated module.
-
instantiate
Instantiate the module in the given store with the provided function for looking up imports.- Parameters:
store
- The store.imports
- The import resolving function.- Returns:
- The instantiated module.
-
instantiate
Instantiate the module in the given store with the provided function for looking up modules to import from.- Parameters:
store
- The store.modules
- The function for looking up module instances.- Returns:
- The instantiated module.
-
imports
Get the imports that this module requires.- Returns:
- The list of imports.
-
exports
Get the exports that this module supplies.- Returns:
- The list of exports.
-