use boa_gc::{Finalize, Trace, empty_trace};
use boa_macros::static_syms;
use core::num::NonZeroUsize;
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(transparent)
)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[allow(clippy::unsafe_derive_deserialize)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Finalize)]
pub struct Sym {
value: NonZeroUsize,
}
unsafe impl Trace for Sym {
empty_trace!();
}
impl Sym {
pub(super) fn new(value: usize) -> Option<Self> {
NonZeroUsize::new(value).map(|value| Self { value })
}
pub(super) const unsafe fn new_unchecked(value: usize) -> Self {
Self {
value:
unsafe {
NonZeroUsize::new_unchecked(value)
},
}
}
#[inline]
#[must_use]
pub fn is_reserved_identifier(self) -> bool {
(Self::BREAK..=Self::WITH).contains(&self)
}
#[inline]
#[must_use]
pub fn is_strict_reserved_identifier(self) -> bool {
(Self::IMPLEMENTS..=Self::YIELD).contains(&self)
}
#[inline]
#[must_use]
pub const fn get(self) -> usize {
self.value.get()
}
}
static_syms! {
"break",
"case",
"catch",
"class",
"const",
"continue",
"debugger",
"default",
"delete",
"do",
"else",
"enum",
"export",
"extends",
"false",
"finally",
"for",
"function",
"if",
"import",
"in",
"instanceof",
"new",
"null",
"return",
"super",
"switch",
"this",
"throw",
"true",
"try",
"typeof",
"var",
"void",
"while",
"with",
"implements",
"interface",
"let",
"package",
"private",
"protected",
"public",
"static",
"yield",
("", EMPTY_STRING),
"prototype",
"constructor",
"arguments",
"eval",
"RegExp",
"get",
"set",
("<main>", MAIN),
"raw",
"anonymous",
"async",
"of",
"target",
"as",
"from",
"__proto__",
"name",
"await",
("*default*", DEFAULT_EXPORT),
"meta",
"defer",
"source",
"using",
"dispose",
"asyncDispose"
}