libquickjs_sys/
static-functions.rs

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