libquickjspp_sys/
static-functions.rs

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