Repository navigation
Expand file tree
/
Copy pathtypeof.v
More file actions
147 lines (113 loc) · 2.96 KB
/
Copy pathtypeof.v
File metadata and controls
147 lines (113 loc) · 2.96 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
module vjsx
// Declare Type Is
fn C.JS_IsException(JSValueConst) int
fn C.JS_IsNumber(JSValueConst) int
fn C.JS_IsBigInt(&C.JSContext, JSValueConst) int
fn C.JS_IsBool(JSValueConst) int
fn C.JS_IsBigFloat(JSValueConst) int
fn C.JS_IsBigDecimal(JSValueConst) int
fn C.JS_IsNull(JSValueConst) int
fn C.JS_IsUndefined(JSValueConst) int
fn C.JS_IsUninitialized(JSValueConst) int
fn C.JS_IsString(JSValueConst) int
fn C.JS_IsSymbol(JSValueConst) int
fn C.JS_IsObject(JSValueConst) int
fn C.JS_IsArray(&C.JSContext, JSValueConst) int
fn C.JS_IsError(&C.JSContext, JSValueConst) int
fn C.JS_IsFunction(&C.JSContext, JSValueConst) int
fn C.JS_IsInstanceOf(&C.JSContext, JSValueConst, JSValueConst) int
fn C.JS_IsRegisteredClass(&C.JSRuntime, C.JSClassID) int
// Check value is exception.
pub fn (v Value) is_exception() bool {
return C.JS_IsException(v.ref) == 1
}
// Check value is number.
pub fn (v Value) is_number() bool {
return C.JS_IsNumber(v.ref) == 1
}
// Check value is bigfloat.
pub fn (v Value) is_big_float() bool {
return C.JS_IsBigFloat(v.ref) == 1
}
// Check value is big decimal.
pub fn (v Value) is_big_decimal() bool {
return C.JS_IsBigDecimal(v.ref) == 1
}
// Check value is bigint.
pub fn (v Value) is_big_int() bool {
return C.JS_IsBigInt(v.ctx.ref, v.ref) == 1
}
// Check value is boolean.
pub fn (v Value) is_bool() bool {
return C.JS_IsBool(v.ref) == 1
}
// Check value is null.
pub fn (v Value) is_null() bool {
return C.JS_IsNull(v.ref) == 1
}
// Check value is undefined.
pub fn (v Value) is_undefined() bool {
return C.JS_IsUndefined(v.ref) == 1
}
// Check value is uninitialized.
pub fn (v Value) is_uninitialized() bool {
return C.JS_IsUninitialized(v.ref) == 1
}
// Check value is string.
pub fn (v Value) is_string() bool {
return C.JS_IsString(v.ref) == 1
}
// Check value is symbol.
pub fn (v Value) is_symbol() bool {
return C.JS_IsSymbol(v.ref) == 1
}
// Check value is object.
pub fn (v Value) is_object() bool {
return C.JS_IsObject(v.ref) == 1
}
// Check value is array.
pub fn (v Value) is_array() bool {
return C.JS_IsArray(v.ctx.ref, v.ref) == 1
}
// Check value is error.
pub fn (v Value) is_error() bool {
return C.JS_IsError(v.ctx.ref, v.ref) == 1
}
// Check value is function.
pub fn (v Value) is_function() bool {
return C.JS_IsFunction(v.ctx.ref, v.ref) == 1
}
// Check value with instanceof.
// Example: assert val.instanceof('Promise') == true
@[manualfree]
pub fn (v Value) instanceof(key string) bool {
glob := v.ctx.js_global().get(key)
stat := C.JS_IsInstanceOf(v.ctx.ref, v.ref, glob.ref) == 1
glob.free()
return stat
}
// Check typeof name value.
pub fn (v Value) typeof_name() string {
if v.is_undefined() || v.is_uninitialized() {
return 'undefined'
}
if v.is_string() {
return 'string'
}
if v.is_bool() {
return 'boolean'
}
if v.is_number() {
return 'number'
}
if v.is_function() {
return 'function'
}
if v.is_symbol() {
return 'symbol'
}
if v.is_big_int() {
return 'bigint'
}
return 'object'
}