If I use local.get
to access the value of a WebAssembly local which I have not already set via local.set
or local.tee
, am I guaranteed to get a specific default value, or is this undefined behavior? For instance:
(module
(func (result i32) (local i32)
local.get 0))
Running this in Chrome gives zero, but I would like to know if that is guaranteed by the spec.
Yes, the Wasm spec demands that all local variables are zero initialized. Thus you'd get the same behavior on all spec compliant runtimes.
You can find this in the spec here: https://webassembly.github.io/spec/core/exec/instructions.html#exec-invoke