#[derive(Copy, Clone, Debug, PartialEq)]
pub(crate) enum AbruptKind {
Continue,
Break,
Throw,
Return,
}
#[derive(Clone, Copy, Debug)]
pub(crate) struct AbruptCompletionRecord {
kind: AbruptKind,
target: u32,
}
impl AbruptCompletionRecord {
pub(crate) const fn new_break() -> Self {
Self {
kind: AbruptKind::Break,
target: u32::MAX,
}
}
pub(crate) const fn new_continue() -> Self {
Self {
kind: AbruptKind::Continue,
target: u32::MAX,
}
}
pub(crate) const fn new_throw() -> Self {
Self {
kind: AbruptKind::Throw,
target: u32::MAX,
}
}
pub(crate) const fn new_return() -> Self {
Self {
kind: AbruptKind::Return,
target: u32::MAX,
}
}
pub(crate) const fn with_initial_target(mut self, target: u32) -> Self {
self.target = target;
self
}
}
impl AbruptCompletionRecord {
pub(crate) fn is_break(self) -> bool {
self.kind == AbruptKind::Break
}
pub(crate) fn is_continue(self) -> bool {
self.kind == AbruptKind::Continue
}
pub(crate) fn is_return(self) -> bool {
self.kind == AbruptKind::Return
}
pub(crate) fn is_throw(self) -> bool {
self.kind == AbruptKind::Throw
}
pub(crate) fn is_throw_with_target(self) -> bool {
self.is_throw() && self.target < u32::MAX
}
pub(crate) const fn target(self) -> u32 {
self.target
}
}