fix: 装箱 Symbol 强转恒返 Symbol 并修正迭代器 name

This commit is contained in:
2026-09-25 06:52:46 +00:00
parent 01195ffb32
commit ae330e2b34
4 changed files with 21 additions and 34 deletions
+4 -2
View File
@@ -137,12 +137,14 @@ pub fn string_constructor<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
let v = oxide_runtime_api::to_string_for_string_constructor(v, vm);
match v {
Ok(s) => vm.new_string_owned(s),
Err(_) => {
Err(msg) => {
// ToString on an object may throw via toString/valueOf; propagate the original exception.
if let Some(exc) = vm.take_uncaught_value() {
return NativeResult::Err(exc);
}
return NativeResult::Err(crate::error::create_type_error(vm, "Cannot convert value to a string"));
// 无在途异常时按格式化文本恢复 kind 与消息(装箱 Symbol 走 ToString
// 抛 TypeError,消息须与原始异常一致)。
return NativeResult::Err(crate::error::create_from_text(vm, &msg));
}
}
} else {