quickjs_rusty/value/
tag.rs1use std::fmt::Debug;
2
3use libquickjs_ng_sys as q;
4
5#[repr(i32)]
6#[derive(PartialEq, Eq, Clone, Copy, Debug)]
7pub enum JsTag {
8 #[cfg(feature = "bigint")]
12 BigInt = q::JS_TAG_BIG_INT,
13 Symbol = q::JS_TAG_SYMBOL,
14 String = q::JS_TAG_STRING,
15 Module = q::JS_TAG_MODULE,
16 FunctionBytecode = q::JS_TAG_FUNCTION_BYTECODE,
17 Object = q::JS_TAG_OBJECT,
18
19 Int = q::JS_TAG_INT,
20 Bool = q::JS_TAG_BOOL,
21 Null = q::JS_TAG_NULL,
22 Undefined = q::JS_TAG_UNDEFINED,
23 Uninitialized = q::JS_TAG_UNINITIALIZED,
24 CatchOffset = q::JS_TAG_CATCH_OFFSET,
25 Exception = q::JS_TAG_EXCEPTION,
26 ShortBigInt = q::JS_TAG_SHORT_BIG_INT,
27 Float64 = q::JS_TAG_FLOAT64,
28}
29
30impl JsTag {
31 #[inline]
32 pub(super) fn from_c(value: &q::JSValue) -> JsTag {
33 let inner = unsafe { q::JS_Ext_ValueGetTag(*value) };
34 match inner {
35 q::JS_TAG_INT => JsTag::Int,
36 q::JS_TAG_BOOL => JsTag::Bool,
37 q::JS_TAG_NULL => JsTag::Null,
38 q::JS_TAG_MODULE => JsTag::Module,
39 q::JS_TAG_OBJECT => JsTag::Object,
40 q::JS_TAG_STRING => JsTag::String,
41 q::JS_TAG_SYMBOL => JsTag::Symbol,
42 q::JS_TAG_FLOAT64 => JsTag::Float64,
43 q::JS_TAG_EXCEPTION => JsTag::Exception,
44 q::JS_TAG_UNDEFINED => JsTag::Undefined,
45 q::JS_TAG_CATCH_OFFSET => JsTag::CatchOffset,
46 q::JS_TAG_UNINITIALIZED => JsTag::Uninitialized,
47 q::JS_TAG_FUNCTION_BYTECODE => JsTag::FunctionBytecode,
48 #[cfg(feature = "bigint")]
49 q::JS_TAG_SHORT_BIG_INT => JsTag::ShortBigInt,
50 #[cfg(feature = "bigint")]
51 q::JS_TAG_BIG_INT => JsTag::BigInt,
52 _other => {
53 unreachable!("Unknown js_tag: {}", _other);
54 }
55 }
56 }
57
58 #[allow(dead_code)]
59 pub(super) fn to_c(self) -> i32 {
60 match self {
63 #[cfg(feature = "bigint")]
64 JsTag::BigInt => q::JS_TAG_FUNCTION_BYTECODE,
65 JsTag::Symbol => q::JS_TAG_SYMBOL,
66 JsTag::String => q::JS_TAG_STRING,
67 JsTag::Module => q::JS_TAG_MODULE,
68 JsTag::FunctionBytecode => q::JS_TAG_FUNCTION_BYTECODE,
69 JsTag::Object => q::JS_TAG_OBJECT,
70
71 JsTag::Int => q::JS_TAG_INT,
72 JsTag::Bool => q::JS_TAG_BOOL,
73 JsTag::Null => q::JS_TAG_NULL,
74 JsTag::Undefined => q::JS_TAG_UNDEFINED,
75 JsTag::Uninitialized => q::JS_TAG_UNINITIALIZED,
76 JsTag::CatchOffset => q::JS_TAG_CATCH_OFFSET,
77 JsTag::Exception => q::JS_TAG_EXCEPTION,
78 #[cfg(feature = "bigint")]
79 JsTag::ShortBigInt => q::JS_TAG_SHORT_BIG_INT,
80 JsTag::Float64 => q::JS_TAG_FLOAT64,
81 }
82 }
83
84 #[inline]
86 pub fn is_undefined(&self) -> bool {
87 matches!(self, Self::Undefined)
88 }
89
90 #[inline]
92 pub fn is_object(&self) -> bool {
93 matches!(self, Self::Object)
94 }
95
96 #[inline]
98 pub fn is_exception(&self) -> bool {
99 matches!(self, Self::Exception)
100 }
101
102 #[inline]
104 pub fn is_int(&self) -> bool {
105 matches!(self, Self::Int)
106 }
107
108 #[inline]
110 pub fn is_bool(&self) -> bool {
111 matches!(self, Self::Bool)
112 }
113
114 #[inline]
116 pub fn is_null(&self) -> bool {
117 matches!(self, Self::Null)
118 }
119
120 #[inline]
122 pub fn is_module(&self) -> bool {
123 matches!(self, Self::Module)
124 }
125
126 #[inline]
128 pub fn is_string(&self) -> bool {
129 matches!(self, Self::String)
130 }
131
132 #[inline]
134 pub fn is_symbol(&self) -> bool {
135 matches!(self, Self::Symbol)
136 }
137
138 #[cfg(feature = "bigint")]
140 #[inline]
141 pub fn is_big_int(&self) -> bool {
142 matches!(self, Self::BigInt)
143 }
144
145 #[inline]
147 pub fn is_float64(&self) -> bool {
148 matches!(self, Self::Float64)
149 }
150}