#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum FieldKind {
StructField,
Namespace,
ArrayListLen,
StringLen,
SliceLen,
ArgumentsLen,
MapSetSize,
MathConstant(String),
NumberConstant(String),
SymbolWellKnown(String),
TypedArrayProp {
prop: String,
type_suffix: Option<String>,
},
Private,
PointerDeref,
RegExpProp { prop: String },
StaticField { class_name: String },
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum IndexKind {
ArrayListItem,
SliceIndex,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ComputedKeyKind {
StructField,
MapGet,
JsAnyGetByKey,
ArrayListItem,
StringCharAt,
CompileError(String),
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum CallKind {
Direct,
Method { object_type: MethodObjectKind },
Closure,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum MethodObjectKind {
ArrayList,
String,
Map,
Set,
Date,
Class(String),
JsAny,
Unknown,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum NewConstructor {
Map,
Set,
Date(DateConstructorKind),
RegExp,
TypedArray(TypedArrayKind),
Class(String),
Error(String),
Unsupported(String),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum DateConstructorKind {
Now,
FromMillis,
FromString,
FromComponents,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum TypedArrayKind {
Int8Array,
Uint8Array,
Uint8ClampedArray,
Int16Array,
Uint16Array,
Int32Array,
Uint32Array,
Float32Array,
Float64Array,
BigInt64Array,
BigUint64Array,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_field_kind_variants() {
let kinds = [
FieldKind::StructField,
FieldKind::ArrayListLen,
FieldKind::StringLen,
FieldKind::MapSetSize,
FieldKind::MathConstant("pi".to_string()),
FieldKind::NumberConstant("floatMax".to_string()),
FieldKind::SymbolWellKnown("iterator".to_string()),
FieldKind::TypedArrayProp {
prop: "buffer".to_string(),
type_suffix: None,
},
];
assert_eq!(kinds.len(), 8);
}
#[test]
fn test_call_kind() {
let direct = CallKind::Direct;
let method = CallKind::Method {
object_type: MethodObjectKind::ArrayList,
};
let closure = CallKind::Closure;
assert_ne!(direct, method);
assert_ne!(method, closure);
}
#[test]
fn test_new_constructor() {
let date_now = NewConstructor::Date(DateConstructorKind::Now);
let class = NewConstructor::Class("Foo".to_string());
assert!(matches!(
date_now,
NewConstructor::Date(DateConstructorKind::Now)
));
assert!(matches!(class, NewConstructor::Class(_)));
}
#[test]
fn test_typed_array_kinds() {
let all = [
TypedArrayKind::Int8Array,
TypedArrayKind::Uint8Array,
TypedArrayKind::Uint8ClampedArray,
TypedArrayKind::Int16Array,
TypedArrayKind::Uint16Array,
TypedArrayKind::Int32Array,
TypedArrayKind::Uint32Array,
TypedArrayKind::Float32Array,
TypedArrayKind::Float64Array,
TypedArrayKind::BigInt64Array,
TypedArrayKind::BigUint64Array,
];
assert_eq!(all.len(), 11);
}
}