Skip to main content

hirofa_quickjs_sys/
static-functions.rs

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