WasmStore Class
A store (https://webassembly.github.io/spec/core/exec/runtime.html#store): the instances, functions, memories, tables, globals, tags and exceptions created in it. A store is not thread-safe: use it from one thread at a time. Dispose it to release its native resources; a store that is not disposed is released when it is collected.
public abstract class WasmStore : IDisposable- Implements
Properties
| Name | Description |
|---|---|
| Runtime | Gets the runtime of the store. |
Runtime
Methods
| Name | Description |
|---|---|
| CreateException(WasmTag, ReadOnlySpan<WasmValue>) | Creates an exception (exn_alloc), which a host function can throw with a WasmThrowException. |
| CreateFunction(WasmFunctionType, WasmHostCallback, object?) | Creates a host function (func_alloc). |
| CreateGlobal(WasmGlobalType, WasmValue) | Creates a global (global_alloc). |
| CreateMemory(WasmMemoryType) | Creates a memory (mem_alloc). |
| CreateTable(WasmTableType, WasmValue) | Creates a table (table_alloc) whose elements are value. |
| CreateTag(WasmTagType) | Creates a tag (tag_alloc). |
| Dispose() | Releases the native store. The objects of the store must not be used afterwards. |
| Dispose(bool) | Releases the native store. |
| GetArrayElement(WasmGcObject, int) | Reads an element of an array (array.get; a packed element is zero-extended). |
| GetArrayLength(WasmGcObject) | Returns the number of elements of an array (array.len). |
| Instantiate(WasmModule) | Instantiates a module without imports (module_instantiate). |
| Instantiate(WasmModule, WasmImports) | Instantiates a module with the imports of their module and name (module_instantiate). |
| Instantiate(WasmModule, IReadOnlyList<WasmExtern>) | Instantiates a module with the imports, in the order of WasmModule.Imports (module_instantiate). |
| SetArrayElement(WasmGcObject, int, WasmValue, WasmValueType) | Writes an element of an array (array.set) whose storage type is type (i32 for a packed element). |
CreateException(WasmTag, ReadOnlySpan<WasmValue>)
Creates an exception (exn_alloc), which a host function can throw with a WasmThrowException.
public abstract WasmExceptionReference CreateException(WasmTag tag, ReadOnlySpan<WasmValue> payload)Parameters
tagWasmTagpayloadReadOnlySpan<WasmValue>
Returns
Exceptions
WasmTypeMismatchException- The payload does not match the type of the tag.
CreateFunction(WasmFunctionType, WasmHostCallback, object?)
Creates a host function (func_alloc).
public abstract WasmFunction CreateFunction(WasmFunctionType type, WasmHostCallback callback, object? state = null)Parameters
typeWasmFunctionType- The type of the function.
callbackWasmHostCallback- The steps of the function.
stateobject?- A value associated with the function (
WasmFunction.HostState).
Returns
CreateGlobal(WasmGlobalType, WasmValue)
Creates a global (global_alloc).
public abstract WasmGlobal CreateGlobal(WasmGlobalType type, WasmValue value)Parameters
typeWasmGlobalTypevalueWasmValue
Returns
Exceptions
WasmTypeMismatchException- The value does not match the type.
CreateMemory(WasmMemoryType)
Creates a memory (mem_alloc).
public abstract WasmMemory CreateMemory(WasmMemoryType type)Parameters
typeWasmMemoryType
Returns
Exceptions
WasmAllocationException- The memory cannot be allocated.
CreateTable(WasmTableType, WasmValue)
Creates a table (table_alloc) whose elements are value.
public abstract WasmTable CreateTable(WasmTableType type, WasmValue value)Parameters
typeWasmTableTypevalueWasmValue
Returns
Exceptions
WasmAllocationException- The table cannot be allocated.
CreateTag(WasmTagType)
Creates a tag (tag_alloc).
public abstract WasmTag CreateTag(WasmTagType type)Dispose overloads
Dispose()
WasmObjects.csReleases the native store. The objects of the store must not be used afterwards.
public void Dispose()Dispose(bool)
WasmObjects.csReleases the native store.
Parameters
disposingbool- Whether the method is called by
WasmStore.Dispose.
GetArrayElement(WasmGcObject, int)
Reads an element of an array (array.get; a packed element is zero-extended).
public abstract WasmValue GetArrayElement(WasmGcObject array, int index)Parameters
arrayWasmGcObjectindexint
Returns
Exceptions
WasmTrapException- The index is out of bounds, or the object is not an array of the store.
GetArrayLength(WasmGcObject)
Returns the number of elements of an array (array.len).
public abstract int GetArrayLength(WasmGcObject array)Parameters
arrayWasmGcObject
Returns
Exceptions
WasmTrapException- The object is not an array of the store.
Instantiate overloads
Instantiate(WasmModule)
WasmObjects.csInstantiates a module without imports (module_instantiate).
public WasmInstance Instantiate(WasmModule module)Parameters
moduleWasmModule- A module of the runtime of the store.
Returns
Exceptions
WasmLinkException- The module has imports.
WasmTrapException- The start function trapped.
WasmThrowException- The start function threw an exception.
Instantiate(WasmModule, WasmImports)
WasmObjects.csInstantiates a module with the imports of their module and name (module_instantiate).
public WasmInstance Instantiate(WasmModule module, WasmImports imports)Parameters
moduleWasmModule- A module of the runtime of the store.
importsWasmImports- The values of the imports.
Returns
Exceptions
WasmLinkException- An import is missing, or does not match the type of the import of the module.
WasmTrapException- The start function trapped.
WasmThrowException- The start function threw an exception.
Instantiate(WasmModule, IReadOnlyList<WasmExtern>)
Instantiates a module with the imports, in the order of WasmModule.Imports (module_instantiate).
public abstract WasmInstance Instantiate(WasmModule module, IReadOnlyList<WasmExtern> imports)Parameters
moduleWasmModule- A module of the runtime of the store.
importsIReadOnlyList<WasmExtern>- The values of the imports, in the order of
WasmModule.Imports.
Returns
Exceptions
WasmLinkException- An import does not match the type of the import of the module.
WasmTrapException- The start function trapped.
WasmThrowException- The start function threw an exception.
SetArrayElement(WasmGcObject, int, WasmValue, WasmValueType)
Writes an element of an array (array.set) whose storage type is type (i32 for a packed element).
public abstract void SetArrayElement(WasmGcObject array, int index, WasmValue value, WasmValueType type)Parameters
arrayWasmGcObjectindexintvalueWasmValuetypeWasmValueType
Exceptions
WasmTrapException- The index is out of bounds, the array is immutable, or the object is not an array of the store.