Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Default value of WebAssembly.Global #6

Closed
binji opened this issue Apr 5, 2018 · 3 comments
Closed

Default value of WebAssembly.Global #6

binji opened this issue Apr 5, 2018 · 3 comments

Comments

@binji
Copy link
Member

binji commented Apr 5, 2018

I'm currently working on the v8 implementation of this proposal, and noticed that the current wording requires the default value of a f32 or f64 WebAssembly.Global to be NaN.

I believe this is because of the step 1. Let |v| be |descriptor|["value"], which makes |v| undefined, which ToWebAssemblyValue converts to NaN. This seems to be consistent with passing an undefined value to an exported function, but I think in this case it would be nicer to have the default be zero instead.

Note that if an imported global has an undefined in the import object, a LinkError will be thrown instead:

1. If |globaltype| is [=𝗂𝟨𝟦=] or [=Type=](|v|) is not [=Number=], throw a {{LinkError}} exception.
@lars-t-hansen
Copy link
Collaborator

I probably agree that zero is nicer (== more useful for more programs), but this seems like the type of case that justifies the existence of NaN in the first place.

I won't be able to attend the CG f2f next week but perhaps get this on the agenda for a quick poll?

@jfbastien
Copy link
Member

Make sure to ask which NaN, and which zero 😉

@binji
Copy link
Member Author

binji commented Apr 19, 2018

We discussed this at the April CG meeting, and decided to make the default value 0.

@rossberg also presented on the js types proposal, where it would be more convenient to move the value initializer out of the descriptor, into a second argument:

new WebAssembly.Global({type, mutable}, value);

This second argument, if omitted, will use the default value for the type. For the numeric types, that's 0, but for future nullable reference types it will be null.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants