hirofa_quickjs_sys/
static-functions.rs

1
2unsafe extern "C" {
3    fn JS_ValueGetTag_real(v: JSValue) -> i32;
4    #[cfg(feature = "bellard")]
5    fn JS_DupValue_real(ctx: *mut JSContext, v: JSValue);
6    #[cfg(feature = "bellard")]
7    fn JS_DupValueRT_real(rt: *mut JSRuntime, v: JSValue);
8    #[cfg(feature = "bellard")]
9    fn JS_FreeValue_real(ctx: *mut JSContext, v: JSValue);
10    #[cfg(feature = "bellard")]
11    fn JS_FreeValueRT_real(rt: *mut JSRuntime, v: JSValue);
12    fn JS_NewBool_real(ctx: *mut JSContext, v: bool) -> JSValue;
13    fn JS_NewInt32_real(ctx: *mut JSContext, v: i32) -> JSValue;
14
15    #[cfg(feature = "bellard")]
16    fn JS_NewFloat64_real(ctx: *mut JSContext, v: f64) -> JSValue;
17
18    fn JS_VALUE_IS_NAN_real(v: JSValue) -> bool;
19    fn JS_VALUE_GET_FLOAT64_real(v: JSValue) -> f64;
20    fn JS_VALUE_GET_NORM_TAG_real(v: JSValue) -> ::std::os::raw::c_int;
21    fn JS_IsNumber_real(v: JSValue) -> bool;
22    fn JS_IsBigInt_real(ctx: *mut JSContext, v: JSValue) -> bool;
23    fn JS_IsBigFloat_real(v: JSValue) -> bool;
24    fn JS_IsBigDecimal_real(v: JSValue) -> bool;
25    fn JS_IsBool_real(v: JSValue) -> bool;
26    fn JS_IsNull_real(v: JSValue) -> bool;
27    fn JS_IsUndefined_real(v: JSValue) -> bool;
28    fn JS_IsException_real(v: JSValue) -> bool;
29    fn JS_IsUninitialized_real(v: JSValue) -> bool;
30    fn JS_IsString_real(v: JSValue) -> bool;
31    fn JS_IsSymbol_real(v: JSValue) -> bool;
32    fn JS_IsObject_real(v: JSValue) -> bool;
33    fn JS_ToUint32_real(ctx: *mut JSContext, pres: u32, val: JSValue) -> u32;
34    #[cfg(feature = "bellard")]
35    fn JS_SetProperty_real(ctx: *mut JSContext, this_obj: JSValue, prop: JSAtom, val: JSValue) -> ::std::os::raw::c_int;
36    fn JS_NewCFunction_real(ctx: *mut JSContext, func: *mut JSCFunction, name: *const ::std::os::raw::c_char,length: ::std::os::raw::c_int) -> JSValue;
37    fn JS_NewCFunctionMagic_real(ctx: *mut JSContext, func: *mut JSCFunctionMagic, name: *const ::std::os::raw::c_char, length: ::std::os::raw::c_int, cproto: JSCFunctionEnum, magic: ::std::os::raw::c_int) -> JSValue;
38}
39
40pub unsafe fn JS_ValueGetTag(v: JSValue) -> i32 {
41    unsafe {
42        JS_ValueGetTag_real(v)
43    }
44}
45
46/// Increment the refcount of this value
47#[cfg(feature = "bellard")]
48pub unsafe fn JS_DupValue(ctx: *mut JSContext, v: JSValue) {
49    unsafe {
50        JS_DupValue_real(ctx, v);
51    }
52}
53
54/// Increment the refcount of this value
55#[cfg(feature = "bellard")]
56pub unsafe fn JS_DupValueRT(rt: *mut JSRuntime, v: JSValue) {
57    unsafe {
58        JS_DupValueRT_real(rt, v);
59    }
60}
61
62/// Decrement the refcount of this value
63#[cfg(feature = "bellard")]
64pub unsafe fn JS_FreeValue(ctx: *mut JSContext, v: JSValue) {
65    unsafe {
66        JS_FreeValue_real(ctx, v);
67    }
68}
69
70/// Decrement the refcount of this value
71#[cfg(feature = "bellard")]
72pub unsafe fn JS_FreeValueRT(rt: *mut JSRuntime, v: JSValue) {
73    unsafe {
74        JS_FreeValueRT_real(rt, v);
75    }
76}
77
78/// create a new boolean value
79pub unsafe fn JS_NewBool(ctx: *mut JSContext, v: bool) -> JSValue {
80    unsafe {
81        JS_NewBool_real(ctx, v)
82    }
83}
84
85/// create a new int32 value
86pub unsafe fn JS_NewInt32(ctx: *mut JSContext, v: i32) -> JSValue {
87    unsafe {
88        JS_NewInt32_real(ctx, v)
89    }
90}
91
92/// create a new f64 value, please note that if the passed f64 fits in a i32 this will return a value with flag 0 (i32)
93#[cfg(feature = "bellard")]
94pub unsafe fn JS_NewFloat64(ctx: *mut JSContext, v: f64) -> JSValue {
95    unsafe {
96        JS_NewFloat64_real(ctx, v)
97    }
98}
99
100/// check if a JSValue is a NaN value
101pub unsafe fn JS_VALUE_IS_NAN(v: JSValue) -> bool {
102    unsafe {
103        JS_VALUE_IS_NAN_real(v)
104    }
105
106}
107
108/// get a f64 value from a JSValue
109pub unsafe fn JS_VALUE_GET_FLOAT64(v: JSValue) -> f64 {
110
111    unsafe {
112        JS_VALUE_GET_FLOAT64_real(v)
113    }
114}
115
116/// same as JS_VALUE_GET_TAG, but return JS_TAG_FLOAT64 with NaN boxing
117pub unsafe fn JS_VALUE_GET_NORM_TAG(v: JSValue) -> ::std::os::raw::c_int {
118    unsafe {
119        JS_VALUE_GET_NORM_TAG_real(v)
120    }
121}
122
123/// check if a JSValue is a Number
124pub unsafe fn JS_IsNumber(v: JSValue) -> bool {
125    unsafe {
126        JS_IsNumber_real(v)
127    }
128}
129
130/// check if a JSValue is a BigInt
131pub unsafe fn JS_IsBigInt(ctx: *mut JSContext, v: JSValue) -> bool {
132    unsafe {
133        JS_IsBigInt_real(ctx,v)
134    }
135}
136
137/// check if a JSValue is a BigFloat
138pub unsafe fn JS_IsBigFloat(v: JSValue) -> bool {
139    unsafe {
140        JS_IsBigFloat_real(v)
141    }
142}
143
144/// check if a JSValue is a BigDecimal
145pub unsafe fn JS_IsBigDecimal(v: JSValue) -> bool {
146    unsafe {
147        JS_IsBigDecimal_real(v)
148    }
149}
150
151/// check if a JSValue is a Boolean
152pub unsafe fn JS_IsBool(v: JSValue) -> bool {
153    unsafe {
154        JS_IsBool_real(v)
155    }
156}
157
158/// check if a JSValue is null
159pub unsafe fn JS_IsNull(v: JSValue) -> bool {
160    unsafe {
161        JS_IsNull_real(v)
162    }
163}
164
165/// check if a JSValue is Undefined
166pub unsafe fn JS_IsUndefined(v: JSValue) -> bool {
167    unsafe {
168        JS_IsUndefined_real(v)
169    }
170}
171
172/// check if a JSValue is an Exception
173pub unsafe fn JS_IsException(v: JSValue) -> bool{
174    unsafe {
175        JS_IsException_real(v)
176    }
177}
178
179/// check if a JSValue is initialized
180pub unsafe fn JS_IsUninitialized(v: JSValue) -> bool {
181    unsafe {
182        JS_IsUninitialized_real(v)
183    }
184}
185
186/// check if a JSValue is a String
187pub unsafe fn JS_IsString(v: JSValue) -> bool {
188    unsafe {
189        JS_IsString_real(v)
190    }
191}
192
193/// check if a JSValue is a Symbol
194pub unsafe fn JS_IsSymbol(v: JSValue) -> bool {
195    unsafe {
196        JS_IsSymbol_real(v)
197    }
198}
199
200/// check if a JSValue is an Object
201pub unsafe fn JS_IsObject(v: JSValue) -> bool {
202    unsafe {
203        JS_IsObject_real(v)
204    }
205}
206
207/// get a u32 value from a JSValue
208pub unsafe fn JS_ToUint32(ctx: *mut JSContext, pres: u32, val: JSValue) -> u32 {
209    unsafe {
210        JS_ToUint32_real(ctx, pres, val)
211    }
212}
213
214/// set a property of an object identified by a JSAtom
215#[cfg(feature = "bellard")]
216pub unsafe fn JS_SetProperty(ctx: *mut JSContext, this_obj: JSValue, prop: JSAtom, val: JSValue) -> ::std::os::raw::c_int {
217    unsafe {
218        JS_SetProperty_real(ctx, this_obj, prop, val)
219    }
220}
221
222/// create a new Function based on a JSCFunction
223pub unsafe fn JS_NewCFunction(ctx: *mut JSContext, func: *mut JSCFunction, name: *const ::std::os::raw::c_char,length: ::std::os::raw::c_int) -> JSValue {
224    unsafe {
225        JS_NewCFunction_real(ctx, func, name, length)
226    }
227}
228
229/// create a new Function based on a JSCFunction
230pub unsafe fn JS_NewCFunctionMagic(ctx: *mut JSContext, func: *mut JSCFunctionMagic, name: *const ::std::os::raw::c_char, length: ::std::os::raw::c_int, cproto: JSCFunctionEnum, magic: ::std::os::raw::c_int) -> JSValue {
231    unsafe {
232        JS_NewCFunctionMagic_real(ctx, func, name, length, cproto, magic)
233    }
234}