feat: 迁移 NativeResult

This commit is contained in:
爱特每羊队
2026-06-25 18:32:09 +08:00
parent 93326a6f31
commit 2c8f85d5a9
32 changed files with 164 additions and 66 deletions
+1 -36
View File
@@ -1,38 +1,3 @@
use oxide_types::value::JsValue;
pub enum NativeResult {
Ok(JsValue),
Err(JsValue),
TailCall { callee: JsValue, this: JsValue, args: Vec<JsValue> },
}
impl NativeResult {
pub fn ok(val: JsValue) -> Self {
Self::Ok(val)
}
pub fn err(val: JsValue) -> Self {
Self::Err(val)
}
pub fn unwrap(self) -> JsValue {
match self {
Self::Ok(val) => val,
Self::Err(_) => panic!("called `NativeResult::unwrap()` on an `Err` value"),
Self::TailCall { .. } => panic!("called `NativeResult::unwrap()` on a `TailCall` value"),
}
}
pub fn map_err<E, F>(self, op: F) -> Result<JsValue, E>
where
F: FnOnce(JsValue) -> E,
{
match self {
Self::Ok(val) => Ok(val),
Self::Err(err) => Err(op(err)),
Self::TailCall { .. } => panic!("TailCall cannot be converted to Result"),
}
}
}
use oxide_runtime_api::NativeResult;
pub type NativeFn = fn(&mut crate::vm::Vm, args: &[u8]) -> NativeResult;