fromNative static method

Reads a borrowed wasm_externtype_t.

Implementation

static WasmExternType fromNative(ffi.Pointer<c.wasm_externtype_t> type) {
  final kind = WasmExternKind.fromC(c.wasm_externtype_kind(type));
  switch (kind) {
    case WasmExternKind.func:
      return WasmFuncExternType(
        WasmFuncType.fromNative(c.wasm_externtype_as_functype(type)),
      );
    case WasmExternKind.global:
      final global = c.wasm_externtype_as_globaltype(type);
      return WasmGlobalExternType(
        content: WasmValueKind.fromWasmKind(
          c.wasm_valtype_kind(c.wasm_globaltype_content(global)),
        ),
        mutable: c.wasm_globaltype_mutability(global) != 0,
      );
    case WasmExternKind.memory:
    case WasmExternKind.sharedMemory:
      return WasmMemoryExternType(
        limits: _readLimits(
          c.wasm_memorytype_limits(c.wasm_externtype_as_memorytype(type)),
        ),
      );
    case WasmExternKind.table:
      final table = c.wasm_externtype_as_tabletype(type);
      return WasmTableExternType(
        element: WasmValueKind.fromWasmKind(
          c.wasm_valtype_kind(c.wasm_tabletype_element(table)),
        ),
        limits: _readLimits(c.wasm_tabletype_limits(table)),
      );
    case WasmExternKind.tag:
      throw UnsupportedError('Exception tags are not supported.');
  }
}