feat: 七构造器绑定 Symbol.species 静态访问器

This commit is contained in:
2026-09-22 16:55:07 +00:00
parent 2252ed7bbc
commit 72f9a063a4
9 changed files with 176 additions and 8 deletions
@@ -1,7 +1,7 @@
use std::sync::Arc;
use crate::bind_constructor;
use crate::bindings::{apply_binding_table, configure_native_constructor};
use crate::bindings::{apply_binding_table, bind_accessor_getter_key, configure_native_constructor};
use oxide_kernel::kernel::{KernelCore, KernelSession};
use oxide_types::object::JsObject;
@@ -29,6 +29,17 @@ pub fn bind_array_buffer(core: &Arc<KernelCore>, session: &KernelSession, global
)],
);
// ArrayBuffer[Symbol.species] 访问器:getter 返回 receiver,派生类沿静态原型链
// 解析 @@species 得自身构造器(规范不给 class 默认 static @@species,类上无 own)。
bind_accessor_getter_key(
core,
session,
ctor,
oxide_types::private_key::make_well_known_symbol_key(oxide_types::private_key::WELL_KNOWN_SYMBOL_SPECIES),
"get [Symbol.species]",
oxide_builtins::array::array_species_get::<crate::vm::Vm> as *const (),
);
apply_binding_table(
session.builtin_world(),
proto,
+13 -1
View File
@@ -2,7 +2,8 @@ use std::sync::Arc;
use crate::bind_constructor;
use crate::bindings::{
apply_binding_table, bind_accessor_getter, bind_well_known_method_alias, configure_native_constructor,
apply_binding_table, bind_accessor_getter, bind_accessor_getter_key, bind_well_known_method_alias,
configure_native_constructor,
};
use oxide_kernel::kernel::{KernelCore, KernelSession};
use oxide_types::object::JsObject;
@@ -39,6 +40,17 @@ pub fn bind_map(core: &Arc<KernelCore>, session: &KernelSession, global: &mut Js
bind_well_known_method_alias(core, proto, "entries", 0);
bind_accessor_getter(core, session, proto, "size", oxide_builtins::map::map_size::<crate::vm::Vm> as *const ());
// Map[Symbol.species] 访问器:getter 返回 receiver,派生类沿静态原型链解析
// @@species 得自身构造器(规范不给 class 默认 static @@species,类上无 own)。
bind_accessor_getter_key(
core,
session,
ctor,
oxide_types::private_key::make_well_known_symbol_key(oxide_types::private_key::WELL_KNOWN_SYMBOL_SPECIES),
"get [Symbol.species]",
oxide_builtins::array::array_species_get::<crate::vm::Vm> as *const (),
);
// Map.groupBy 静态方法。
apply_binding_table(
session.builtin_world(),
+13 -1
View File
@@ -1,7 +1,8 @@
use std::sync::Arc;
use crate::bindings::{
apply_binding_table, bind_accessor_getter, bind_well_known_method, configure_native_constructor,
apply_binding_table, bind_accessor_getter, bind_accessor_getter_key, bind_well_known_method,
configure_native_constructor,
};
use oxide_kernel::kernel::{KernelCore, KernelSession};
use oxide_types::object::JsObject;
@@ -158,5 +159,16 @@ pub fn bind_regexp(core: &Arc<KernelCore>, session: &KernelSession, global: &mut
1,
);
// RegExp[Symbol.species] 访问器:getter 返回 receiver,派生类沿静态原型链解析
// @@species 得自身构造器(规范不给 class 默认 static @@species,类上无 own)。
bind_accessor_getter_key(
core,
session,
ctor,
oxide_types::private_key::make_well_known_symbol_key(oxide_types::private_key::WELL_KNOWN_SYMBOL_SPECIES),
"get [Symbol.species]",
oxide_builtins::array::array_species_get::<crate::vm::Vm> as *const (),
);
bind_constructor!(core, global, "RegExp", ctor_ptr, oxide_builtins::regexp::regexp_constructor::<crate::vm::Vm>, 2, hash: true);
}
+13 -2
View File
@@ -2,8 +2,8 @@ use std::sync::Arc;
use crate::bind_constructor;
use crate::bindings::{
apply_binding_table, bind_accessor_getter, bind_method_alias, bind_well_known_method_alias,
configure_native_constructor,
apply_binding_table, bind_accessor_getter, bind_accessor_getter_key, bind_method_alias,
bind_well_known_method_alias, configure_native_constructor,
};
use oxide_kernel::kernel::{KernelCore, KernelSession};
use oxide_types::object::JsObject;
@@ -53,5 +53,16 @@ pub fn bind_set(core: &Arc<KernelCore>, session: &KernelSession, global: &mut Js
bind_well_known_method_alias(core, proto, "values", 0);
bind_accessor_getter(core, session, proto, "size", oxide_builtins::set::set_size::<crate::vm::Vm> as *const ());
// Set[Symbol.species] 访问器:getter 返回 receiver,派生类沿静态原型链解析
// @@species 得自身构造器(规范不给 class 默认 static @@species,类上无 own)。
bind_accessor_getter_key(
core,
session,
ctor,
oxide_types::private_key::make_well_known_symbol_key(oxide_types::private_key::WELL_KNOWN_SYMBOL_SPECIES),
"get [Symbol.species]",
oxide_builtins::array::array_species_get::<crate::vm::Vm> as *const (),
);
bind_constructor!(core, global, "Set", ctor_ptr, oxide_builtins::set::set_constructor::<crate::vm::Vm>, 1, hash: true);
}
@@ -56,6 +56,22 @@ fn bind_typed_array_abstract_ctor(core: &Arc<KernelCore>, session: &KernelSessio
},
1,
);
// %TypedArray%[Symbol.species] 访问器:getter 返回 receiver,十一具体构造器
// (及派生类)沿原型链解析 @@species 得自身(具体构造器无 own 属性)。绑定站
// 与 TA 构造器后续消费面改造共用,先查槽位防重复绑定追加第二访问器槽。
let species_key =
oxide_types::private_key::make_well_known_symbol_key(oxide_types::private_key::WELL_KNOWN_SYMBOL_SPECIES);
if core.shape_forge().lookup_position(ctor.shape_id(), species_key).is_none() {
bind_accessor_getter_key(
core,
session,
ctor,
species_key,
"get [Symbol.species]",
oxide_builtins::array::array_species_get::<crate::vm::Vm> as *const (),
);
}
}
/// 给构造器与对应原型设置 `BYTES_PER_ELEMENT`(只读、不可枚举、不可配置)。
@@ -264,6 +264,17 @@ impl Vm {
// prototype 槽位在 length/name 之后(下标 2)。
ctor_mut.set_prop_at(2u32, JsValue::from_js_object(self.promise_proto.as_ptr() as *mut JsObject));
// Promise[Symbol.species] 访问器:getter 返回 receiver,派生类沿静态原型链
// 解析 @@species 得自身构造器。ctor 经本函数每次调用全新构造,同键槽不累积。
crate::bindings::bind_accessor_getter_key(
&self.kernel_core,
&self.session,
ctor_mut,
oxide_types::private_key::make_well_known_symbol_key(oxide_types::private_key::WELL_KNOWN_SYMBOL_SPECIES),
"get [Symbol.species]",
oxide_builtins::array::array_species_get::<crate::vm::Vm> as *const (),
);
// 绑定 global:槽已存在则更新(full_reset 未重建 global 时旧槽指向已弃 ctor)。
let global_ptr = self.session.global_object().as_ptr() as *mut JsObject;
// SAFETY: global 对象由 session 持有,存活整个 session;本函数内只改其