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

syscall/js: zero Value is interpreted as NaN instead of Undefined #28174

Closed
dennwc opened this issue Oct 12, 2018 · 2 comments
Closed

syscall/js: zero Value is interpreted as NaN instead of Undefined #28174

dennwc opened this issue Oct 12, 2018 · 2 comments
Labels
arch-wasm WebAssembly issues FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@dennwc
Copy link
Contributor

dennwc commented Oct 12, 2018

What version of Go are you using (go version)?

go version go1.11.1 linux/amd64

Does this issue reproduce with the latest release?

Yes (same on tip)

What operating system and processor architecture are you using (go env)?

GOOS=js
GOARCH=wasm

What did you do?

var v js.Value
fmt.Println(v == js.Undefined())

What did you expect to see?

true

What did you see instead?

false

Description

Currently, ref type codes of JS values in wasm are arranged in a way that makes a zero value a NaN number instead of undefined.

This breaks established Go semantics where a zero pointer value of a type is assumed to have a nil value (JS default value is undefined).

To illustrate the difference, consider the case:

var a *Obj // a == nil

var m map[string]*Obj
b := m["non existent"] // b == nil

a == b // true

However, this code does not work in the current implementation:

var a js.Value // NaN !

m := js.Global()
b := m.Get("non existent") // undefined

a == b // false !

Proposed solution

Remap JS value type enum to list undefined as a first type code (= 0) and move NaN to a different type code.

CC @neelance

@neelance
Copy link
Member

Yes, the zero value is intentionally unspecified atm, since I did not decide yet if this is worth a special case. It probably is.

@agnivade agnivade changed the title wasm: zero Value is interpreted as NaN instead of Undefined syscall/js: zero Value is interpreted as NaN instead of Undefined Oct 12, 2018
@agnivade agnivade added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. arch-wasm WebAssembly issues labels Oct 12, 2018
@agnivade agnivade added this to the Unplanned milestone Oct 12, 2018
@cherrymui
Copy link
Member

See #27592. Closing this as a dup.

@golang golang locked and limited conversation to collaborators Oct 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly issues FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants