/
float64array.go
executable file
·97 lines (74 loc) · 2.1 KB
/
float64array.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package typedarray
import (
"sync"
"syscall/js"
"github.com/realPy/hogosuru/baseobject"
)
var singletonFloat64array sync.Once
var Float64arrayinterface js.Value
//Float64Array struct
type Float64Array struct {
TypedArray
}
type Float64ArrayFrom interface {
Float64Array_() Float64Array
}
func (u Float64Array) Float64Array_() Float64Array {
return u
}
//GetFloat64ArrayInterface get the JS interface of Float64Array
func GetFloat64ArrayInterface() js.Value {
singletonFloat64array.Do(func() {
var err error
if Float64arrayinterface, err = baseobject.Get(js.Global(), "Float64Array"); err != nil {
Float64arrayinterface = js.Undefined()
}
baseobject.Register(Float64arrayinterface, func(v js.Value) (interface{}, error) {
return NewFloat64FromJSObject(v)
})
})
return Float64arrayinterface
}
func NewFloat64Array(value interface{}) (Float64Array, error) {
var a Float64Array
var objnew js.Value
var err error
if ai := GetFloat64ArrayInterface(); !ai.IsUndefined() {
if objnew, err = baseobject.New(ai, baseobject.GetJsValueOf(value)); err == nil {
a.BaseObject = a.SetObject(objnew)
}
} else {
err = ErrNotImplementedFloat64Array
}
return a, err
}
func NewFloat64ArrayFrom(iterable interface{}) (Float64Array, error) {
arr, err := newTypedArrayFrom(GetFloat64ArrayInterface(), func(v js.Value) (interface{}, error) {
return NewFloat64FromJSObject(v)
}, iterable)
return arr.(Float64Array), err
}
func NewFloat64ArrayOf(values ...interface{}) (Float64Array, error) {
arr, err := newTypedArrayOf(GetFloat64ArrayInterface(), func(v js.Value) (interface{}, error) {
return NewFloat64FromJSObject(v)
}, values...)
return arr.(Float64Array), err
}
func NewFloat64FromJSObject(obj js.Value) (Float64Array, error) {
var u Float64Array
var err error
if ui := GetFloat64ArrayInterface(); !ui.IsUndefined() {
if obj.IsUndefined() || obj.IsNull() {
err = baseobject.ErrUndefinedValue
} else {
if obj.InstanceOf(ui) {
u.BaseObject = u.SetObject(obj)
} else {
err = ErrNotAFloat64Array
}
}
} else {
err = ErrNotImplementedFloat64Array
}
return u, err
}