mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-23 18:21:13 +08:00
fix: 清理 CallFrame 无效字段并接入函数名元数据
This commit is contained in:
@@ -163,3 +163,35 @@ pub fn error_stack_getter(vm: &mut Vm, _args: &[u8]) -> NativeResult {
|
||||
let si = vm.kernel().string_forge().intern(&result).0;
|
||||
Ok(JsValue::string(si, 0))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::error_stack_getter;
|
||||
use crate::vm::{CallFrame, Vm};
|
||||
use oxide_types::value::JsValue;
|
||||
|
||||
#[test]
|
||||
fn error_stack_uses_call_frame_function_name() {
|
||||
let mut vm = Vm::new();
|
||||
let name_si = vm.kernel().string_forge().intern("foo").0;
|
||||
vm.frames.push(CallFrame {
|
||||
return_addr: 0,
|
||||
function_name: name_si,
|
||||
caller_reg_limit: 1,
|
||||
saved_regs: vec![JsValue::undefined()].into_boxed_slice(),
|
||||
saved_this: JsValue::undefined(),
|
||||
saved_new_target: JsValue::undefined(),
|
||||
});
|
||||
|
||||
let stack = error_stack_getter(&mut vm, &[0]).unwrap();
|
||||
let stack_str = vm
|
||||
.kernel()
|
||||
.string_forge()
|
||||
.lookup(stack.as_string_index())
|
||||
.unwrap_or_default();
|
||||
assert!(
|
||||
stack_str.contains("foo"),
|
||||
"expected function name in stack: {stack_str}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,10 +135,6 @@ macro_rules! member_read_prop {
|
||||
|
||||
pub struct CallFrame {
|
||||
pub return_addr: usize,
|
||||
pub n_locals: u8,
|
||||
pub n_args: u8,
|
||||
pub function_obj_reg: u8,
|
||||
pub frame_base: u8,
|
||||
pub function_name: u32,
|
||||
pub caller_reg_limit: u8,
|
||||
pub saved_regs: Box<[JsValue]>,
|
||||
@@ -779,11 +775,11 @@ impl Vm {
|
||||
// Push call frame
|
||||
self.frames.push(CallFrame {
|
||||
return_addr: self.pc,
|
||||
n_locals: sub_n_args as u8,
|
||||
n_args: sub_n_args as u8,
|
||||
function_obj_reg: callee_reg as u8,
|
||||
frame_base: sub_param_base as u8,
|
||||
function_name: 0,
|
||||
function_name: self.sub_modules[sub_idx]
|
||||
.function_name
|
||||
.as_deref()
|
||||
.map(|name| self.kernel.string_forge().intern(name).0)
|
||||
.unwrap_or(0),
|
||||
caller_reg_limit,
|
||||
saved_regs,
|
||||
saved_this,
|
||||
|
||||
Reference in New Issue
Block a user