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: comparing two number objects with ==
fails
#25802
Comments
/cc @neelance |
I’m not completely sure if two distinct A similar situation I can think of is
https://play.golang.org/p/cX0RhxB_800 The original code would work correctly if you compared the underlying values, right? Something like this: // gl is a WebGL context of a canvas.
if s := gl.Call("checkFramebufferStatus", gl.Get("FRAMEBUFFER")); s.Int() != gl.Get("FRAMEBUFFER_COMPLETE").Int() {
return js.Null, errors.New(fmt.Sprintf("opengl: creating framebuffer failed: %d", s.Int()))
} These are some initial thoughts, I’m open to further discussion. |
Why is this your expectation? Is there some example from the Javascript world where this equates to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness |
Yes, Of course always adding |
Oh I was misunderstanding:
Looks like 'false' would be fine in my example... |
OK another example would be package main
import (
"syscall/js"
)
func main() {
js.Global.Set("a", 1)
js.Global.Set("b", 1)
println(js.Global.Get("a") == js.Global.Get("b")) // false
} Looks like |
We need to add |
@neelance Would https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness |
I thought |
Yes, |
Indeed, my point was that it immediately raises the question of which one it refers to. There is also Is there any reason this needs to be part of the API at all? Can we not make it incumbent on the developer to call the appropriate JS function? |
What exactly do you mean? |
I should start by clarifying one thing: it's my understanding that currently a
By doing things like:
(although that said I'm not sure if there are JS function equivalents of |
Afaik there are no JS function equivalents of |
I just got an initial idea on how to make Go's |
Chatted to @neelance about this offline so just adding some points here for the record. I think what we need to do here is make Go's comparison func TestEquals(t *testing.T) {
a := js.Global.Call("eval", "5")
b := js.Global.Call("eval", "5")
cmp := js.Global.Call("eval", "(function(a, b) { return a === b; })")
if !cmp.Invoke(a, b).Bool() {
t.Fatalf("Javascript === should be true") // ok
}
if a != b {
t.Fatalf("should compare equal in Go") // currently fails
}
} This will, I think, then mean we don't need to add If users want Javascript's |
Change https://golang.org/cl/120561 mentions this issue: |
(This issue is copied from https://github.com/neelance/go/issues/27)
I'm using 8d6062b on neelance's wasm-wip branch
Shows
false
, I expectedtrue
though. I suggest==
returntrue
since it'd be more intuitive.The current result might be intended, but was really confusing to me. For example, getting WebGL's constant like
FRAMEBUFFER_COMPLETE
via Get creates a number object if I understand correctly, and comparing this constant value and another value always fails.String object might be in the same situation .
The text was updated successfully, but these errors were encountered: