mirror of
https://github.com/golang/go.git
synced 2025-10-25 13:54:14 +00:00
misc/wasm: fix passing large negative integers from JS to Go
This commit addresses a FIXME left in the code of wasm_exec.js to properly get the upper 32 bit of a JS number to be stored as an 64-bit integer. A bitshift operation is not possible, because in JavaScript bitshift operations only operate on the lower 32 bits. Change-Id: I8f627fd604e592682d9d322942a4852db64a7f66 Reviewed-on: https://go-review.googlesource.com/113076 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
db91ee3651
commit
73b5951391
2 changed files with 19 additions and 5 deletions
|
|
@ -58,6 +58,24 @@ func TestInt(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestIntConversion(t *testing.T) {
|
||||
testIntConversion(t, 0)
|
||||
testIntConversion(t, 1)
|
||||
testIntConversion(t, -1)
|
||||
testIntConversion(t, 1<<20)
|
||||
testIntConversion(t, -1<<20)
|
||||
testIntConversion(t, 1<<40)
|
||||
testIntConversion(t, -1<<40)
|
||||
testIntConversion(t, 1<<60)
|
||||
testIntConversion(t, -1<<60)
|
||||
}
|
||||
|
||||
func testIntConversion(t *testing.T, want int) {
|
||||
if got := js.ValueOf(want).Int(); got != want {
|
||||
t.Errorf("got %#v, want %#v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFloat(t *testing.T) {
|
||||
want := 42.123
|
||||
o := dummys.Get("someFloat")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue