WebAssembly / gc

Branch of the spec repo scoped to discussion of GC integration in WebAssembly
https://webassembly.github.io/gc/
Other
982 stars 70 forks source link

[js-api] DefaultValue needs updating #501

Closed rossberg closed 6 months ago

rossberg commented 8 months ago

The DefaultValue algorithm needs updating to handle more general reference types. Moreover, it is partial now, so all use sites need to adapt to the possibility of it failing.

@takikawa

Also, this algorithm is unrelated to JS and in fact duplicates the respective definition in the core spec. It might be preferable to expose that in the core spec's embedding interface and call into that.

eqrion commented 8 months ago

Also, this algorithm is unrelated to JS and in fact duplicates the respective definition in the core spec. It might be preferable to expose that in the core spec's embedding interface and call into that.

The JS-API default value function is slightly different than wasm's default value function. JSAPI-DefaultValue(externref) = undefined, while Wasm-DefaultValue(externref) = null. This is thanks to JS filling in missing parameters with undefined.

rossberg commented 8 months ago

Fair enough, but it would still be preferable to handle only this special case here and then defer to the core spec for all regular cases.

(Although personally I still think this special case is odd and instead it should only use undefined if explicitly given, not as default. There is precedence in JS for treating an absent parameter differently from explicit undefined, e.g., [].reduce(() => 0) throws TypeError, whereas [].reduce(() => 0, undefined) returns undefined.)