mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-23 18:21:13 +08:00
perf: indexOf/includes/lastIndexOf 支持 ArrayLike,补 .name/.length 属性
- Array indexOf/includes/lastIndexOf:ArrayLike 接收者 + fromIndex + SameValueZero - Function.prototype 方法补 .length 属性,经 bind_method_static 绑定 - Error 对象补 .name 属性,经 create_kind_error 生成 - 构造器函数补 .name 与 .length,经 make_pair / bind_constructor! 绑定
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user