nanvm_lib/js/
visitor.rs

1use crate::mem::manager::Dealloc;
2
3use super::{
4    any::Any, js_array::JsArrayRef, js_bigint::JsBigintRef, js_object::JsObjectRef,
5    js_string::JsStringRef, type_::Type,
6};
7
8pub enum Visitor<T: Dealloc> {
9    Number(f64),
10    Null,
11    Bool(bool),
12    String(JsStringRef<T>),
13    Object(JsObjectRef<T>),
14    Array(JsArrayRef<T>),
15    Bigint(JsBigintRef<T>),
16}
17
18pub fn to_visitor<T: Dealloc>(any: Any<T>) -> Visitor<T> {
19    match any.get_type() {
20        Type::Number => Visitor::Number(any.try_move().unwrap()),
21        Type::Null => Visitor::Null,
22        Type::Bool => Visitor::Bool(any.try_move().unwrap()),
23        Type::String => Visitor::String(any.try_move().unwrap()),
24        Type::Object => Visitor::Object(any.try_move().unwrap()),
25        Type::Array => Visitor::Array(any.try_move().unwrap()),
26        Type::Bigint => Visitor::Bigint(any.try_move().unwrap()),
27    }
28}