-
Notifications
You must be signed in to change notification settings - Fork 162
Expand file tree
/
Copy pathmain.go
More file actions
43 lines (34 loc) · 914 Bytes
/
main.go
File metadata and controls
43 lines (34 loc) · 914 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//go:build wasm && js
package main
import (
"syscall/js"
"github.com/scaleway/scaleway-cli/v2/internal/jshelpers"
)
type jsFunction func(js.Value, []js.Value) any
var tests = map[string]jsFunction{
"FromSlice": wasmTestFromSlice,
"MarshalBuildInfo": wasmTestMarshalBuildInfo,
}
func main() {
stopChan := make(chan struct{})
stop := func(_ js.Value, args []js.Value) (any, error) {
stopChan <- struct{}{}
return nil, nil
}
args := getArgs()
if args.targetObject != "" {
cliPackage := js.ValueOf(map[string]any{})
for funcName, testFunc := range tests {
cliPackage.Set(funcName, js.FuncOf(testFunc))
}
cliPackage.Set("stop", js.FuncOf(jshelpers.AsyncJsFunc(stop)))
js.Global().Set(args.targetObject, cliPackage)
}
if args.callback != "" {
givenCallback := js.Global().Get(args.callback)
if !givenCallback.IsUndefined() {
givenCallback.Invoke()
}
}
<-stopChan
}