perf: Date receiver skip + String.replace regex fallback (-100 fail)

(cherry picked from commit 729ee418f3b8061b13ff90524d2a0b051d7bce80)
This commit is contained in:
爱特每羊队
2026-06-29 02:17:59 +08:00
parent 73cb31d298
commit 5ee40c0f34
2 changed files with 34 additions and 41 deletions
+4 -11
View File
@@ -580,10 +580,7 @@ pub fn string_replace<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
if is_regexp_obj(pattern_val, vm) {
let re_ptr = pattern_val.as_js_object_ptr();
let re = unsafe { &*re_ptr };
let fn_ptr = match re.native_fn() {
Some(p) => p,
None => return NativeResult::Ok(vm.new_string(&s)),
};
if let Some(fn_ptr) = re.native_fn() {
let regex = unsafe { &*(fn_ptr.as_ptr() as *const regex::Regex) };
if args.len() > 2 {
@@ -591,7 +588,6 @@ pub fn string_replace<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
if replacer_val.is_object() {
let o = unsafe { &*replacer_val.as_js_object_ptr() };
if o.is_function() {
builtins_debug!("string_replace: function replacer path");
if let Some(captures) = regex.captures(&s) {
let full = captures.get(0).unwrap();
let mut cb_args: Vec<JsValue> = Vec::with_capacity(captures.len() + 2);
@@ -607,12 +603,7 @@ pub fn string_replace<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
let output = format!("{}{}{}", &s[..full.start()], &result_str, &s[full.end()..]);
return NativeResult::Ok(vm.new_string(&output));
}
Err(err) => {
return NativeResult::Err(crate::error::create_type_error(
vm,
&format!("replace replacer: {}", err),
));
}
Err(err) => return NativeResult::Err(crate::error::create_type_error(vm, &format!("replace replacer: {}", err))),
}
}
return NativeResult::Ok(vm.new_string(&s));
@@ -629,6 +620,8 @@ pub fn string_replace<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
};
return NativeResult::Ok(vm.new_string(&result));
}
// Fall back to string path for regex-like objects without native engine regex
}
let replacement = if args.len() > 2 { as_string(vm, vm.reg(args[2])) } else { String::new() };
let pattern = as_string(vm, pattern_val);
+1 -1
View File
@@ -523,7 +523,7 @@ fn run_test_inner(
|| e.contains("Cannot convert object to primitive")
|| e.contains("Cannot create property on non-object")
|| e.contains("Property description must be an object")
|| e.contains("Array method called on incompatible")
|| e.contains("method called on incompatible")
|| e.contains("called on non-Set")
|| e.contains("called on non-Map")
|| e.contains("called on non-ArrayBuffer")