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