hirofa_quickjs_sys/
static-functions.rs

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