mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-24 18:51:13 +08:00
refactor: 统一调用调度并安全化 IC 缓存
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use crate::native::NativeFn;
|
||||
use crate::vm::Vm;
|
||||
use crate::native::{NativeFn, NativeResult};
|
||||
use crate::vm::{native_fn_ptr_to_fn, FrameContinuation, Vm};
|
||||
use oxide_types::object::JsObject;
|
||||
use oxide_types::value::JsValue;
|
||||
|
||||
@@ -25,16 +25,18 @@ impl Vm {
|
||||
let (args_buf, len) = Self::build_native_args(first_arg_reg, arg_count, this_reg);
|
||||
let args_slice = &args_buf[..len];
|
||||
|
||||
let func: NativeFn = unsafe { std::mem::transmute(obj.native_fn().unwrap()) };
|
||||
// SAFETY: native_fn was set via set_native_fn with a valid NativeFn pointer;
|
||||
// native_fn_ptr_to_fn is the single coercion point for NativeFnPtr → NativeFn.
|
||||
let func: NativeFn = unsafe { native_fn_ptr_to_fn(obj.native_fn().unwrap()) };
|
||||
self.regs[254] = callee;
|
||||
self.native_call_depth += 1;
|
||||
match func(self, args_slice) {
|
||||
Ok(val) => {
|
||||
NativeResult::Ok(val) => {
|
||||
self.native_call_depth -= 1;
|
||||
self.regs[0] = val;
|
||||
Ok(())
|
||||
}
|
||||
Err(err_val) => {
|
||||
NativeResult::Err(err_val) => {
|
||||
self.native_call_depth -= 1;
|
||||
let (error, kind) = if err_val.is_object() {
|
||||
(err_val, self.thrown_error_kind(err_val))
|
||||
@@ -53,6 +55,18 @@ impl Vm {
|
||||
self.pending_error_kind = Some(kind);
|
||||
self.unwind()
|
||||
}
|
||||
NativeResult::TailCall { callee, this, args } => {
|
||||
self.native_call_depth -= 1;
|
||||
if callee.is_object() {
|
||||
let obj = unsafe { &*callee.as_js_object_ptr() };
|
||||
if obj.native_fn().is_some() {
|
||||
let result = self.call_function_sync(callee, this, &args)?;
|
||||
self.regs[0] = result;
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
self.push_bytecode_frame(callee, this, &args, None, None, JsValue::undefined(), FrameContinuation::None)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user