Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[js-api] DefaultValue needs updating #501

Closed
rossberg opened this issue Dec 20, 2023 · 2 comments
Closed

[js-api] DefaultValue needs updating #501

rossberg opened this issue Dec 20, 2023 · 2 comments
Assignees

Comments

@rossberg
Copy link
Member

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
Copy link
Contributor

eqrion commented Dec 20, 2023

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
Copy link
Member Author

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.)

takikawa added a commit to takikawa/gc that referenced this issue Feb 15, 2024
DefaultValue will return undefined for externref as before, but
for other nullable reference types will return null.

For non-nullable reference types, operations like grow and set
should error if the value to set is missing.

Also adds WPT tests for the error cases. This requires some
updates to wasm-module-builder.js as well.

Fixes issue WebAssembly#501
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants