use boa_gc::{custom_trace, Finalize, Trace};
use crate::{JsError, JsResult, JsValue};
#[derive(Debug, Clone, Finalize)]
pub(crate) enum CompletionRecord {
Normal(JsValue),
Return(JsValue),
Throw(JsError),
}
unsafe impl Trace for CompletionRecord {
custom_trace!(this, {
match this {
Self::Normal(v) => mark(v),
Self::Return(r) => mark(r),
Self::Throw(th) => mark(th),
}
});
}
impl CompletionRecord {
pub(crate) const fn is_throw_completion(&self) -> bool {
matches!(self, Self::Throw(_))
}
#[allow(clippy::missing_const_for_fn)]
pub(crate) fn consume(self) -> JsResult<JsValue> {
match self {
Self::Throw(error) => Err(error),
Self::Normal(value) | Self::Return(value) => Ok(value),
}
}
}