aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/crypto/rand/rand_js.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/crypto/rand/rand_js.go')
-rw-r--r--libgo/go/crypto/rand/rand_js.go5
1 files changed, 3 insertions, 2 deletions
diff --git a/libgo/go/crypto/rand/rand_js.go b/libgo/go/crypto/rand/rand_js.go
index bb21396..7e93974 100644
--- a/libgo/go/crypto/rand/rand_js.go
+++ b/libgo/go/crypto/rand/rand_js.go
@@ -13,6 +13,7 @@ func init() {
}
var jsCrypto = js.Global().Get("crypto")
+var uint8Array = js.Global().Get("Uint8Array")
// reader implements a pseudorandom generator
// using JavaScript crypto.getRandomValues method.
@@ -20,8 +21,8 @@ var jsCrypto = js.Global().Get("crypto")
type reader struct{}
func (r *reader) Read(b []byte) (int, error) {
- a := js.TypedArrayOf(b)
+ a := uint8Array.New(len(b))
jsCrypto.Call("getRandomValues", a)
- a.Release()
+ js.CopyBytesToGo(b, a)
return len(b), nil
}