WasmModule.compile constructor

WasmModule.compile(
  1. WasmEngine engine,
  2. Uint8List bytes
)

Compiles bytes (a binary .wasm module).

Throws a WasmtimeException if the module is malformed or uses a feature that was not configured.

Implementation

factory WasmModule.compile(WasmEngine engine, Uint8List bytes) =>
    scoped((arena) {
      final (data, length) = copyBytes(arena, bytes);
      final out = arena<ffi.Pointer<c.wasmtime_module_t>>();
      throwIfError(c.wasmtime_module_new(engine.pointer, data, length, out));
      if (out.value == ffi.nullptr) {
        throw WasmtimeException('wasmtime_module_new() produced no module');
      }
      return WasmModule._(engine, out.value);
    });