-
Notifications
You must be signed in to change notification settings - Fork 0
/
testsuite_native_test.go
58 lines (50 loc) · 1.29 KB
/
testsuite_native_test.go
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//go:build !js
// +build !js
package masc
import (
"fmt"
"os/exec"
"reflect"
)
type jsFuncImpl struct {
goFunc func(this jsObject, args []jsObject) interface{}
}
func (j *jsFuncImpl) String() string { return "func" }
func (j *jsFuncImpl) Release() {}
func commandOutput(command string, args ...string) (string, error) {
cmd := exec.Command(command, args...)
out, _ := cmd.CombinedOutput()
return string(out), nil
}
var valueOfImpl func(interface{}) jsObject
func init() {
htmlNodeImpl = func(h *HTML) SyscallJSValue {
if h.node == nil {
panic("masc: cannot call (*HTML).Node() before DOM node creation / component mount")
}
return h.node.(wrappedObject).j
}
funcOfImpl = func(fn func(this jsObject, args []jsObject) interface{}) jsFunc {
return &jsFuncImpl{
goFunc: fn,
}
}
valueOfImpl = func(v interface{}) jsObject {
ts := global().(*objectRecorder).ts
name := fmt.Sprintf("valueOf(%v)", v)
r := &objectRecorder{ts: ts, name: name}
switch reflect.ValueOf(v).Kind() {
case reflect.String:
ts.strings.mock(name, v)
case reflect.Bool:
ts.bools.mock(name, v)
case reflect.Float32, reflect.Float64:
ts.floats.mock(name, v)
case reflect.Int:
ts.ints.mock(name, v)
default:
}
return r
}
}
func valueOf(v interface{}) jsObject { return valueOfImpl(v) }