Skip to main content

hirofa_quickjs_sys/
static-functions.rs

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