...
1 package gojs
2
3 import (
4 "context"
5
6 "github.com/tetratelabs/wazero/api"
7 "github.com/tetratelabs/wazero/internal/gojs/custom"
8 "github.com/tetratelabs/wazero/internal/gojs/goos"
9 "github.com/tetratelabs/wazero/internal/wasm"
10 )
11
12
13
14
15
16
17
18
19 var jsCrypto = newJsVal(goos.RefJsCrypto, custom.NameCrypto).
20 addFunction(custom.NameCryptoGetRandomValues, cryptoGetRandomValues{})
21
22
23 type cryptoGetRandomValues struct{}
24
25 func (cryptoGetRandomValues) invoke(_ context.Context, mod api.Module, args ...interface{}) (interface{}, error) {
26 randSource := mod.(*wasm.ModuleInstance).Sys.RandSource()
27
28 r := args[0].(*goos.ByteArray)
29 n, err := randSource.Read(r.Unwrap())
30 return uint32(n), err
31 }
32
View as plain text