rquickjs_sys/inlines/
common.rs1pub use ::std::os::raw::{c_char, c_int, c_uint, c_void};
2
3pub type JSValueConst = JSValue;
4
5pub const JS_NULL: JSValue = JS_MKVAL(JS_TAG_NULL, 0);
6pub const JS_UNDEFINED: JSValue = JS_MKVAL(JS_TAG_UNDEFINED, 0);
7pub const JS_FALSE: JSValue = JS_MKVAL(JS_TAG_BOOL, 0);
8pub const JS_TRUE: JSValue = JS_MKVAL(JS_TAG_BOOL, 1);
9pub const JS_EXCEPTION: JSValue = JS_MKVAL(JS_TAG_EXCEPTION, 0);
10pub const JS_UNINITIALIZED: JSValue = JS_MKVAL(JS_TAG_UNINITIALIZED, 0);
11
12#[inline]
13pub unsafe fn JS_VALUE_HAS_REF_COUNT(v: JSValue) -> bool {
14 JS_VALUE_GET_TAG(v) as c_uint >= JS_TAG_FIRST as c_uint
15}
16
17#[inline]
18pub unsafe fn JS_IsNumber(v: JSValue) -> bool {
19 let tag = JS_VALUE_GET_TAG(v);
20 tag == JS_TAG_INT || JS_TAG_IS_FLOAT64(tag)
21}
22
23#[inline]
24pub unsafe fn JS_IsInt(v: JSValue) -> bool {
25 let tag = JS_VALUE_GET_TAG(v);
26 tag == JS_TAG_INT
27}
28
29#[inline]
30pub unsafe fn JS_IsBigInt(v: JSValue) -> bool {
31 let tag = JS_VALUE_GET_TAG(v);
32 tag == JS_TAG_BIG_INT
33}
34
35#[inline]
36pub unsafe fn JS_IsBool(v: JSValue) -> bool {
37 let tag = JS_VALUE_GET_TAG(v);
38 tag == JS_TAG_BOOL
39}
40
41#[inline]
42pub unsafe fn JS_IsNull(v: JSValue) -> bool {
43 let tag = JS_VALUE_GET_TAG(v);
44 tag == JS_TAG_NULL
45}
46
47#[inline]
48pub unsafe fn JS_IsUndefined(v: JSValue) -> bool {
49 let tag = JS_VALUE_GET_TAG(v);
50 tag == JS_TAG_UNDEFINED
51}
52
53#[inline]
54pub unsafe fn JS_IsException(v: JSValue) -> bool {
55 let tag = JS_VALUE_GET_TAG(v);
56 tag == JS_TAG_EXCEPTION
57}
58
59#[inline]
60pub unsafe fn JS_IsUninitialized(v: JSValue) -> bool {
61 let tag = JS_VALUE_GET_TAG(v);
62 tag == JS_TAG_UNINITIALIZED
63}
64
65#[inline]
66pub unsafe fn JS_IsString(v: JSValue) -> bool {
67 let tag = JS_VALUE_GET_TAG(v);
68 tag == JS_TAG_STRING
69}
70
71#[inline]
72pub unsafe fn JS_IsSymbol(v: JSValue) -> bool {
73 let tag = JS_VALUE_GET_TAG(v);
74 tag == JS_TAG_SYMBOL
75}
76
77#[inline]
78pub unsafe fn JS_IsObject(v: JSValue) -> bool {
79 let tag = JS_VALUE_GET_TAG(v);
80 tag == JS_TAG_OBJECT
81}
82
83#[inline]
84pub unsafe fn JS_ToCString(ctx: *mut JSContext, val: JSValue) -> *const c_char {
85 JS_ToCStringLen2(ctx, ptr::null_mut(), val, (false).into())
86}
87#[inline]
88pub unsafe fn JS_ToCStringLen(
89 ctx: *mut JSContext,
90 plen: *mut usize,
91 val: JSValue,
92) -> *const c_char {
93 JS_ToCStringLen2(ctx, plen as _, val, (false).into())
94}
95
96#[inline]
97pub fn JS_NewFloat64(d: f64) -> JSValue {
98 union U {
99 d: f64,
100 u: u64,
101 }
102
103 let u = U { d };
104 let val = d as i32;
105 let t = U { d: val as f64 };
106 if unsafe { u.u == t.u } {
109 JS_MKVAL(JS_TAG_INT, val)
110 } else {
111 __JS_NewFloat64(d)
112 }
113}