Class Module

java.lang.Object
io.github.eutro.wasm2j.embed.Module

public class Module extends Object
A parsed WebAssembly module.
  • Method Details

    • decode

      public static Module decode(byte[] bytes)
      Decode a binary module from a byte array.
      Parameters:
      bytes - The byte array.
      Returns:
      The decoded module
    • parse

      public static Module parse(String source)
      Parse a text module from a string.
      Parameters:
      source - The source string.
      Returns:
      The parsed module.
    • fromNode

      public static Module fromNode(ModuleNode node)
      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

      public Instance instantiate(Store store, ExternVal[] imports)
      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

      public Instance instantiate(Store store, BiFunction<String,String,ExternVal> imports)
      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

      public Instance 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.
      Parameters:
      store - The store.
      modules - The function for looking up module instances.
      Returns:
      The instantiated module.
    • imports

      public List<Import> imports()
      Get the imports that this module requires.
      Returns:
      The list of imports.
    • exports

      public List<Export> exports()
      Get the exports that this module supplies.
      Returns:
      The list of exports.