Class WebAssembly
Clients do not need to use this class, and are free to directly invoke the more convenient and granular methods and constructors of the relevant classes themselves.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfuncAlloc
(@Nullable Store store, ExternType.Func type, MethodHandle handle) Construct a new function extern.Object[]
funcInvoke
(@Nullable Store store, Func func, Object... args) Invoke a function extern.Get the type of a function extern.globalAlloc
(@Nullable Store store, ExternType.Global type) Create a new global with the given type.globalRead
(@Nullable Store store, Global global) Read the value of a global.globalType
(@Nullable Store store, Global global) Get the type of a global.void
globalWrite
(@Nullable Store store, Global global, Object value) Write the value of a global.instanceExport
(Instance inst, String name) Get a named export of the module instance.memAlloc
(@Nullable Store store, ExternType.Mem type) Create a new memory with the given type.int
Grow the memory by a number of pages, filling new pages with 0.byte
Read a single byte from a memory.int
Get the size of the memory, in pages.Get the type of a memory.void
Write a single byte to a memory.moduleDecode
(byte[] bytes) Decode a binary module from a byte array.moduleExports
(Module module) Get the exports that this module supplies.moduleFromNode
(ModuleNode node) Create a module from a JWasm module node.moduleImports
(Module module) Get the imports that the module requires.moduleInstantiate
(Store store, Module module, ExternVal[] imports) Instantiate the module in the given store with the provided values for imports.moduleParse
(String source) Parse a text module from a string.void
moduleValidate
(Module module) Validate the module, throwing an exception if the module is invalid.void
setDebugOutputDirectory
(File file) Set the debug output of stores created by this embedding instance.Returns a new empty store.tableAlloc
(@Nullable Store store, ExternType.Table type) Construct a new table with the given type.int
Grow the table by a number of elements, filling it with the given value.Get an element of the table.int
Get the size of a table.Get the type of a table extern.void
tableWrite
(@Nullable Store store, Table table, int i, Object value) Set an element of the table.
-
Constructor Details
-
WebAssembly
public WebAssembly()
-
-
Method Details
-
setDebugOutputDirectory
Set the debug output of stores created by this embedding instance.- Parameters:
file
- The debug directory.- See Also:
-
storeInit
Returns a new empty store.- Returns:
- The new store.
- See Also:
-
moduleDecode
Decode a binary module from a byte array.- Parameters:
bytes
- The byte array.- Returns:
- The decoded module
- See Also:
-
moduleParse
Parse a text module from a string.- Parameters:
source
- The source string.- Returns:
- The parsed module.
- See Also:
-
moduleFromNode
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.
- See Also:
-
moduleValidate
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.
- Parameters:
module
- The module to validate.- See Also:
-
moduleInstantiate
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
Module.imports()
.- Parameters:
store
- The store.module
- The module to instantiate.imports
- The supplied imports.- Returns:
- The instantiated module.
- See Also:
-
moduleImports
Get the imports that the module requires.- Parameters:
module
- The module.- Returns:
- The list of imports.
- See Also:
-
moduleExports
Get the exports that this module supplies.- Parameters:
module
- The module.- Returns:
- The list of exports.
- See Also:
-
instanceExport
Get a named export of the module instance.- Parameters:
inst
- The module instance.name
- The name of the export.- Returns:
- The export.
- See Also:
-
funcAlloc
Construct a new function extern.- Parameters:
store
- The store. Ignored.type
- The function type.handle
- The method handle.- Returns:
- The allocated function.
- See Also:
-
funcType
Get the type of a function extern.- Parameters:
store
- The store. Ignored.func
- The function.- Returns:
- The type of the function.
- See Also:
-
funcInvoke
Invoke a function extern.- Parameters:
store
- The store. Ignored.func
- The function.args
- The function arguments.- Returns:
- The type of the function.
- See Also:
-
tableAlloc
Construct a new table with the given type.- Parameters:
store
- The store. Ignored.type
- The table type.- Returns:
- A new table.
- See Also:
-
tableType
Get the type of a table extern.- Parameters:
store
- The store. Ignored.table
- The table.- Returns:
- The table's type.
- See Also:
-
tableRead
Get an element of the table.- Parameters:
store
- The store. Ignored.table
- The table.i
- The element index.- Returns:
- The element.
- See Also:
-
tableWrite
Set an element of the table.- Parameters:
store
- The store. Ignored.table
- The table.i
- The element index.value
- The element.- See Also:
-
tableSize
Get the size of a table.- Parameters:
store
- The store. Ignored.table
- The table.- Returns:
- The size of the table.
- See Also:
-
tableGrow
Grow the table by a number of elements, filling it with the given value.This operation is allowed to fail (and must fail if the upper limit is exceeded), in which case -1 should be returned.
- Parameters:
store
- The store. Ignored.table
- The table.growBy
- The number of elements to grow by.fillWith
- The value to fill new elements with.- Returns:
- The old size of the table.
- See Also:
-
memAlloc
Create a new memory with the given type.- Parameters:
store
- The store. Ignored.type
- The type.- Returns:
- The new memory.
- See Also:
-
memType
Get the type of a memory.- Parameters:
store
- The store. Ignored.memory
- The memory.- Returns:
- The memory type.
- See Also:
-
memRead
Read a single byte from a memory.Using this is discouraged, see
Memory.read(int)
.- Parameters:
store
- The store. Ignored.memory
- The memory.addr
- The memory address.- Returns:
- The byte.
- See Also:
-
memWrite
Write a single byte to a memory.Using this is discouraged, see
Memory.write(int, byte)
.- Parameters:
store
- The store. Ignored.memory
- The memory.addr
- The memory address.value
- The byte.- See Also:
-
memSize
Get the size of the memory, in pages.- Parameters:
store
- The store. Ignored.memory
- The memory.- Returns:
- The size of the memory, in pages.
- See Also:
-
memGrow
Grow the memory by a number of pages, filling new pages with 0.This operation is allowed to fail (and must fail if the upper limit is exceeded), in which case -1 should be returned.
- Parameters:
store
- The store. Ignored.memory
- The memory.growByPages
- The number of pages to grow by, interpreted as an unsigned integer.- Returns:
- The old size, or -1 if the memory was not grown.
- See Also:
-
globalAlloc
Create a new global with the given type.- Parameters:
store
- The store. Ignored.type
- The type.- Returns:
- The global.
- See Also:
-
globalType
Get the type of a global.- Parameters:
store
- The store. Ignored.global
- The global.- Returns:
- The global type.
- See Also:
-
globalRead
Read the value of a global.- Parameters:
store
- The store. Ignored.global
- The global.- Returns:
- The value of the global.
- See Also:
-
globalWrite
Write the value of a global.Should fail if the global is immutable.
- Parameters:
store
- The store. Ignored.global
- The global.value
- The new value of the global.- See Also:
-