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

NameDescription
RuntimeGets the runtime of the store.

Runtime

Gets the runtime of the store.

public abstract WasmRuntime Runtime { get; }

Property value

WasmRuntime

Methods

NameDescription
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

tag WasmTag
payload ReadOnlySpan<WasmValue>

Returns

WasmExceptionReference

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

type WasmFunctionType
The type of the function.
callback WasmHostCallback
The steps of the function.
state object?
A value associated with the function (WasmFunction.HostState).

Returns

WasmFunction

CreateGlobal(WasmGlobalType, WasmValue)

Creates a global (global_alloc).

public abstract WasmGlobal CreateGlobal(WasmGlobalType type, WasmValue value)

Parameters

type WasmGlobalType
value WasmValue

Returns

WasmGlobal

Exceptions

WasmTypeMismatchException
The value does not match the type.

CreateMemory(WasmMemoryType)

Creates a memory (mem_alloc).

public abstract WasmMemory CreateMemory(WasmMemoryType type)

Parameters

type WasmMemoryType

Returns

WasmMemory

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

type WasmTableType
value WasmValue

Returns

WasmTable

Exceptions

WasmAllocationException
The table cannot be allocated.

CreateTag(WasmTagType)

Creates a tag (tag_alloc).

public abstract WasmTag CreateTag(WasmTagType type)

Parameters

type WasmTagType

Returns

WasmTag

Dispose overloads

Releases the native store. The objects of the store must not be used afterwards.

public void Dispose()

Dispose(bool)

WasmObjects.cs

Releases the native store.

protected virtual void Dispose(bool disposing)
Parameters
disposing bool
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

array WasmGcObject
index int

Returns

WasmValue

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

array WasmGcObject

Returns

int

Exceptions

WasmTrapException
The object is not an array of the store.

Instantiate overloads

Instantiate(WasmModule)

WasmObjects.cs

Instantiates a module without imports (module_instantiate).

public WasmInstance Instantiate(WasmModule module)
Parameters
module WasmModule
A module of the runtime of the store.
Returns

WasmInstance

Exceptions
WasmLinkException
The module has imports.
WasmTrapException
The start function trapped.
WasmThrowException
The start function threw an exception.

Instantiate(WasmModule, WasmImports)

WasmObjects.cs

Instantiates a module with the imports of their module and name (module_instantiate).

public WasmInstance Instantiate(WasmModule module, WasmImports imports)
Parameters
module WasmModule
A module of the runtime of the store.
imports WasmImports
The values of the imports.
Returns

WasmInstance

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
module WasmModule
A module of the runtime of the store.
imports IReadOnlyList<WasmExtern>
The values of the imports, in the order of WasmModule.Imports.
Returns

WasmInstance

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

array WasmGcObject
index int
value WasmValue
type WasmValueType

Exceptions

WasmTrapException
The index is out of bounds, the array is immutable, or the object is not an array of the store.