refactor: 退役数组缓冲与正则与 promise 盒克隆重写族死函数

This commit is contained in:
2026-10-02 21:46:41 +00:00
parent b76f2214f9
commit ccd6b06b6e
4 changed files with 7 additions and 239 deletions
-21
View File
@@ -560,27 +560,6 @@ pub fn drop_regexp_native(obj: &mut JsObject) -> u64 {
bytes
}
/// 深拷贝已编译正则到新对象(GC 搬移 / 晋升流程用)。
///
/// 与 drop 配对:新对象获得独立的 `Box<regress::Regex>`,源对象保留自己的指针,
/// 两侧各自释放恰好一次,杜绝跨 arena 克隆后的指针别名双释放。
/// 作用于全部持编译正则的对象形态(RegExp / matchAll 载体)。
pub fn clone_regexp_native(old_obj: &JsObject, new_obj: &mut JsObject) {
if !old_obj.holds_compiled_regex() {
return;
}
let Some(ptr) = old_obj.native_fn() else {
return;
};
let regex_ptr = ptr.as_ptr() as *const regress::Regex;
if regex_ptr.is_null() {
return;
}
// SAFETY: old_obj 的 native_fn 槽存 `Box<regress::Regex>` 指针,对象存活期间有效。
let cloned_ptr = Box::into_raw(Box::new(unsafe { (&*regex_ptr).clone() }));
new_obj.set_native_fn(Some(unsafe { NativeFnPtr::from_raw(cloned_ptr as *const ()) }));
}
/// `RegExp.prototype.test(string)`:判断是否匹配。global/sticky 从 lastIndex
/// 开始匹配,sticky 要求匹配恰在 lastIndex 起点。
///