refactor: 统一调用调度并安全化 IC 缓存
This commit is contained in:
@@ -1,5 +1,46 @@
|
||||
use oxide_types::value::JsValue;
|
||||
|
||||
pub type NativeResult = Result<JsValue, 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 into_result(self) -> Result<JsValue, JsValue> {
|
||||
match self {
|
||||
Self::Ok(val) => Ok(val),
|
||||
Self::Err(err) => Err(err),
|
||||
Self::TailCall { .. } => panic!("TailCall cannot be converted to Result"),
|
||||
}
|
||||
}
|
||||
|
||||
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"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type NativeFn = fn(&mut crate::vm::Vm, args: &[u8]) -> NativeResult;
|
||||
|
||||
Reference in New Issue
Block a user