1use crate::vm::{
2 Array, BigInt, Function, IVm, Number, Object, String, dispatch::Dispatch, nullish::Nullish,
3};
4
5#[derive(Clone)]
6pub enum Unpacked<A: IVm> {
7 Nullish(Nullish),
8 Boolean(bool),
9 Number(Number),
10 String(String<A>),
11 BigInt(BigInt<A>),
12 Object(Object<A>),
13 Array(Array<A>),
14 Function(Function<A>),
15}
16
17impl<A: IVm> Unpacked<A> {
18 pub fn is_nullish(&self) -> bool {
22 matches!(self, Unpacked::Nullish(_))
23 }
24
25 pub fn is_undefined(&self) -> bool {
28 matches!(self, Unpacked::Nullish(Nullish::Undefined))
29 }
30
31 pub fn dispatch<T: Dispatch<A>>(self, o: T) -> T::Result {
32 match self {
33 Unpacked::Nullish(v) => o.nullish(v),
34 Unpacked::Boolean(v) => o.bool(v),
35 Unpacked::Number(v) => o.number(v),
36 Unpacked::String(v) => o.string(v),
37 Unpacked::BigInt(v) => o.bigint(v),
38 Unpacked::Object(v) => o.object(v),
39 Unpacked::Array(v) => o.array(v),
40 Unpacked::Function(v) => o.function(v),
41 }
42 }
43}