diff options
author | Richard Musiol <mail@richard-musiol.de> | 2018-06-27 17:36:24 +0200 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2018-06-27 20:29:21 +0000 |
commit | bafe466a9537d8ea5ac5767504628803302ebb12 (patch) | |
tree | beed5451227350c519435fc24053df039711ef8a /src/net/http/roundtrip_js.go | |
parent | 63a4acba7d19a665f864b929eb8293858d1cee45 (diff) | |
download | go-git-bafe466a9537d8ea5ac5767504628803302ebb12.tar.gz |
syscall/js: add TypedArrayOf
The new function js.TypedArrayOf returns a JavaScript typed array for
a given slice.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays
This change also changes js.ValueOf to not accept a []byte any more.
Fixes #25532.
Change-Id: I8c7bc98ca4e21c3514d19eee7a1f92388d74ab2a
Reviewed-on: https://go-review.googlesource.com/121215
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/net/http/roundtrip_js.go')
-rw-r--r-- | src/net/http/roundtrip_js.go | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/net/http/roundtrip_js.go b/src/net/http/roundtrip_js.go index c183f87fff..1e6f83a666 100644 --- a/src/net/http/roundtrip_js.go +++ b/src/net/http/roundtrip_js.go @@ -166,7 +166,9 @@ func (r *streamReader) Read(p []byte) (n int, err error) { return } value := make([]byte, result.Get("value").Get("byteLength").Int()) - js.ValueOf(value).Call("set", result.Get("value")) + a := js.TypedArrayOf(value) + a.Call("set", result.Get("value")) + a.Release() bCh <- value }) defer success.Close() @@ -227,7 +229,9 @@ func (r *arrayReader) Read(p []byte) (n int, err error) { // Wrap the input ArrayBuffer with a Uint8Array uint8arrayWrapper := js.Global().Get("Uint8Array").New(args[0]) value := make([]byte, uint8arrayWrapper.Get("byteLength").Int()) - js.ValueOf(value).Call("set", uint8arrayWrapper) + a := js.TypedArrayOf(value) + a.Call("set", uint8arrayWrapper) + a.Release() bCh <- value }) defer success.Close() |