-
Notifications
You must be signed in to change notification settings - Fork 0
/
constructor.go
128 lines (90 loc) · 3.86 KB
/
constructor.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//go:build js && wasm
package builtin
import "syscall/js"
type Constructor string
func (c Constructor) JSValue() js.Value {
return js.Global().Get(string(c))
}
// -----------------------------------------------------------------------------
func (c Constructor) New(args ...any) js.Value {
return c.JSValue().New(args...)
}
// -----------------------------------------------------------------------------
const (
EventTarget = Constructor("EventTarget")
Event = Constructor("Event")
ArrayBuffer = Constructor("ArrayBuffer")
Int8Array = Constructor("Int8Array")
Uint8Array = Constructor("Uint8Array")
Uint8ClampedArray = Constructor("Uint8ClampedArray")
Int16Array = Constructor("Int16Array")
Uint16Array = Constructor("Uint16Array")
Int32Array = Constructor("Int32Array")
Uint32Array = Constructor("Uint32Array")
Float32Array = Constructor("Float32Array")
Float64Array = Constructor("Float64Array")
BigInt64Array = Constructor("BigInt64Array")
BigUint64Array = Constructor("BigUint64Array")
URL = Constructor("URL")
XMLHttpRequest = Constructor("XMLHttpRequest")
HTMLFormElement = Constructor("HTMLFormElement")
FormData = Constructor("FormData")
WebSocket = Constructor("WebSocket")
Element = Constructor("Element")
HTMLInputElement = Constructor("HTMLInputElement")
HTMLSelectElement = Constructor("HTMLSelectElement")
HTMLTextAreaElement = Constructor("HTMLTextAreaElement")
Blob = Constructor("Blob")
File = Constructor("File")
RegExp = Constructor("RegExp")
)
// -----------------------------------------------------------------------------
func IsEventTarget(v js.Value) bool {
return v.InstanceOf(EventTarget.JSValue())
}
// -----------------------------------------------------------------------------
func IsEvent(v js.Value) bool {
return v.InstanceOf(Event.JSValue())
}
// -----------------------------------------------------------------------------
func IsArrayBuffer(v js.Value) bool {
return v.InstanceOf(ArrayBuffer.JSValue())
}
// -----------------------------------------------------------------------------
func IsArrayBufferView(v js.Value) bool {
return v.InstanceOf(Int8Array.JSValue()) || v.InstanceOf(Uint8Array.JSValue()) || v.InstanceOf(Uint8ClampedArray.JSValue()) ||
v.InstanceOf(Int16Array.JSValue()) || v.InstanceOf(Uint16Array.JSValue()) ||
v.InstanceOf(Int32Array.JSValue()) || v.InstanceOf(Uint32Array.JSValue()) ||
v.InstanceOf(Float32Array.JSValue()) || v.InstanceOf(Float64Array.JSValue()) ||
v.InstanceOf(BigInt64Array.JSValue()) || v.InstanceOf(BigUint64Array.JSValue())
}
// -----------------------------------------------------------------------------
func IsUint8Array(v js.Value) bool {
return v.InstanceOf(Uint8Array.JSValue()) || v.InstanceOf(Uint8ClampedArray.JSValue())
}
// -----------------------------------------------------------------------------
func IsElement(v js.Value) bool {
return v.InstanceOf(Element.JSValue())
}
// -----------------------------------------------------------------------------
func IsInputElement(v js.Value) bool {
return v.InstanceOf(HTMLInputElement.JSValue())
}
// -----------------------------------------------------------------------------
func HasValueProperty(v js.Value) bool {
return v.InstanceOf(HTMLInputElement.JSValue()) ||
v.InstanceOf(HTMLSelectElement.JSValue()) ||
v.InstanceOf(HTMLTextAreaElement.JSValue())
}
// -----------------------------------------------------------------------------
func IsFile(v js.Value) bool {
return v.InstanceOf(File.JSValue())
}
// -----------------------------------------------------------------------------
func IsBlob(v js.Value) bool {
return v.InstanceOf(Blob.JSValue())
}
// -----------------------------------------------------------------------------
func IsForm(v js.Value) bool {
return v.InstanceOf(HTMLFormElement.JSValue())
}