Closed1

wasm gc struct.new_default

tanishikingtanishiking
(module
  (type $record (struct (field (mut i32)) (field i32)))
  (global $instance (mut (ref null $record)) (ref.null $record))

  (func (export "make")
    (result (ref $record))
    (struct.new_default $record)
  )
  (func (export "get")
    (param $o (ref null $record))
    (result i32)
    (global.set $instance (local.get $o))
    (struct.set $record 0 (local.get $o) (i32.const 1000))
    (struct.get $record 0 (global.get $instance))
  )
)
import { readFileSync } from "node:fs";
const wasmBuffer = readFileSync("test.wasm");
const wasmModule = await WebAssembly.instantiate(wasmBuffer);
const { make, get } = wasmModule.instance.exports;
const o = make();
console.log(o, get(o));
❯ deno run --allow-read run.mjs
[Object: null prototype] {} 1000

これ結局 new_default の挙動わかんないやつやんけ

new_default の default value は 例えば i32 なら 0(ref null $healType)null

このスクラップは3ヶ月前にクローズされました