WasmGlobal.create constructor
WasmGlobal.create(
- WasmStore store,
- WasmValueKind type, {
- required bool mutable,
- Object? value,
Creates a new global in store.
Implementation
factory WasmGlobal.create(
WasmStore store,
WasmValueKind type, {
required bool mutable,
Object? value,
}) => scoped((arena) {
// `wasm_globaltype_new` takes ownership of the value type.
final globalType = c.wasm_globaltype_new(
c.wasm_valtype_new(type.wasmKind),
mutable ? 1 : 0,
);
try {
final initial = arena<c.wasmtime_val_t>();
writeValue(initial, type, value);
final out = arena<c.wasmtime_global_t>();
throwIfError(
c.wasmtime_global_new(store.context, globalType, initial, out),
);
return WasmGlobal._(store, readGlobalHandle(out.ref));
} finally {
c.wasm_globaltype_delete(globalType);
}
});