hirofa_quickjs_sys/
static-functions.rs

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