perf(test262): +2.4% pass rate via Function .name/.length and ArrayLike support

- Array indexOf/includes/lastIndexOf: ArrayLike receiver + fromIndex + SameValueZero
- Function.prototype methods: add .length property via bind_method_static
- Error objects: add .name property via create_kind_error
- Constructor functions: add .name via make_pair + .length via bind_constructor!
- test262: 8497→9009 pass (+512), 38.3%→40.7% rate

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit af61949e6cab1b149a13e571e29bacc4267d5690)
This commit is contained in:
爱特每羊队
2026-06-28 18:23:08 +08:00
parent db013bd4f6
commit 05f1056cde
4 changed files with 161 additions and 38 deletions
+12 -7
View File
@@ -234,25 +234,24 @@ fn make_pair(
si_name: u32,
) -> (P<JsObject>, P<JsObject>) {
intern_label(string_forge, name);
let name_si = string_forge.intern(name).0; // intern the constructor's name value too
let mut proto = JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null());
let mut ctor = JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null());
let proto_shape = shape_forge.make_shape(EMPTY_SHAPE_ID, si_constructor);
proto.set_shape_id(proto_shape);
// proto shape: EMPTY -> "constructor" (slot 0)
let ctor_shape1 = shape_forge.make_shape(EMPTY_SHAPE_ID, si_prototype);
let ctor_shape2 = shape_forge.make_shape(ctor_shape1, si_name);
ctor.set_shape_id(ctor_shape2);
// ctor shape: EMPTY -> "prototype" (slot 0) -> "name" (slot 1)
ctor.set_function(true);
// Pre-allocate Vec slots so wire_ctor_proto can overwrite vec[0] later.
// Proto: 1 property ("constructor"), Ctor: 2 properties ("prototype", "name").
proto.ensure_hash_props().push(JsValue::undefined()); // slot 0: "constructor" placeholder
ctor.ensure_hash_props().push(JsValue::undefined()); // slot 0: "prototype" placeholder
ctor.ensure_hash_props().push(JsValue::undefined()); // slot 1: "name" placeholder
// Pre-allocate slots: proto[0]="constructor", ctor[0]="prototype", ctor[1]="name"
proto.ensure_hash_props().push(JsValue::undefined()); // placeholder, set by wire_ctor_proto
ctor.ensure_hash_props().push(JsValue::undefined()); // placeholder, set by wire_ctor_proto
// Set the actual name value immediately (vec[1])
ctor.ensure_hash_props().push(JsValue::perm_string(string_forge.string_ptr(name_si)));
(P::new(proto), P::new(ctor))
}
@@ -1150,6 +1149,12 @@ impl BuiltinWorld {
// callers, all of which use fn-item expressions).
wrapper.set_native_fn(Some(native_fn_ptr));
wrapper.set_native_arg_count(arg_count);
// 设置 .length (ES spec: Function.length = formal parameter count, excluding rest/default)
let si_length = string_forge.intern("length").0;
let length_shape = shape_forge.make_shape(wrapper.shape_id(), si_length);
wrapper.set_shape_id(length_shape);
wrapper.ensure_hash_props().push(JsValue::int(arg_count as i32));
// 设置 .name
let si_name = string_forge.intern("name").0;
let name_shape = shape_forge.make_shape(wrapper.shape_id(), si_name);
wrapper.set_shape_id(name_shape);