feat: DisposableStack/AsyncDisposableStack 对象类型标签与两栈原型字段入世界

This commit is contained in:
2026-08-16 19:14:48 +08:00
parent 75b429fac7
commit fbfa3f5ccf
2 changed files with 38 additions and 3 deletions
+22 -3
View File
@@ -288,6 +288,11 @@ pub struct BuiltinWorld {
pub regexp_string_iterator_proto: P<JsObject>, pub regexp_string_iterator_proto: P<JsObject>,
/// `%IteratorHelperPrototype%`:Iterator helpers 结果对象的共享原型,链到 %IteratorPrototype%。 /// `%IteratorHelperPrototype%`:Iterator helpers 结果对象的共享原型,链到 %IteratorPrototype%。
pub iterator_helper_proto: P<JsObject>, pub iterator_helper_proto: P<JsObject>,
/// `DisposableStack.prototype`:同步资源栈原型(链到 Object.prototype),
/// 方法/别名/@@toStringTag 由绑定层安装。
pub disposable_stack_proto: P<JsObject>,
/// `AsyncDisposableStack.prototype`:异步资源栈原型(步3 用,形状与同步栈一致)。
pub async_disposable_stack_proto: P<JsObject>,
pub stub_objects: Vec<P<JsObject>>, pub stub_objects: Vec<P<JsObject>>,
} }
@@ -576,7 +581,7 @@ fn wire_builtin_world_links(world: &BuiltinWorld) {
} }
let obj_proto_val = JsValue::from_js_object(world.object_proto.as_ptr() as *mut JsObject); let obj_proto_val = JsValue::from_js_object(world.object_proto.as_ptr() as *mut JsObject);
let non_object_protos: [&P<JsObject>; 21] = [ let non_object_protos: [&P<JsObject>; 23] = [
&world.array_proto, &world.array_proto,
&world.function_proto, &world.function_proto,
&world.string_proto, &world.string_proto,
@@ -598,6 +603,8 @@ fn wire_builtin_world_links(world: &BuiltinWorld) {
&world.zoned_date_time_proto, &world.zoned_date_time_proto,
&world.plain_date_time_proto, &world.plain_date_time_proto,
&world.bigint_proto, &world.bigint_proto,
&world.disposable_stack_proto,
&world.async_disposable_stack_proto,
]; ];
for proto in &non_object_protos { for proto in &non_object_protos {
set_proto_if_changed(proto, obj_proto_val); set_proto_if_changed(proto, obj_proto_val);
@@ -830,6 +837,8 @@ impl BuiltinWorld {
let string_iterator_proto = P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null())); let string_iterator_proto = P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null()));
let regexp_string_iterator_proto = P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null())); let regexp_string_iterator_proto = P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null()));
let iterator_helper_proto = P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null())); let iterator_helper_proto = P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null()));
let disposable_stack_proto = P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null()));
let async_disposable_stack_proto = P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null()));
let world = Self { let world = Self {
object_proto, object_proto,
@@ -929,6 +938,8 @@ impl BuiltinWorld {
string_iterator_proto, string_iterator_proto,
regexp_string_iterator_proto, regexp_string_iterator_proto,
iterator_helper_proto, iterator_helper_proto,
disposable_stack_proto,
async_disposable_stack_proto,
stub_objects, stub_objects,
}; };
wire_builtin_world_links(&world); wire_builtin_world_links(&world);
@@ -1195,8 +1206,8 @@ impl BuiltinWorld {
}; };
let stub_objects = if dirty.stubs { Vec::new() } else { current.stub_objects.clone() }; let stub_objects = if dirty.stubs { Vec::new() } else { current.stub_objects.clone() };
// 迭代器原型依赖 Object.prototype(链到其上):object 家族重建时一并重建, // 迭代器原型与资源栈原型依赖 Object.prototype(链到其上):object 家族重建时
// 否则旧原型链指向已释放的 object_proto。 // 一并重建,否则旧原型链指向已释放的 object_proto。
let ( let (
iterator_proto, iterator_proto,
array_iterator_proto, array_iterator_proto,
@@ -1205,6 +1216,8 @@ impl BuiltinWorld {
string_iterator_proto, string_iterator_proto,
regexp_string_iterator_proto, regexp_string_iterator_proto,
iterator_helper_proto, iterator_helper_proto,
disposable_stack_proto,
async_disposable_stack_proto,
) = if dirty.object { ) = if dirty.object {
( (
P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null())), P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null())),
@@ -1214,6 +1227,8 @@ impl BuiltinWorld {
P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null())), P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null())),
P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null())), P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null())),
P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null())), P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null())),
P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null())),
P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null())),
) )
} else { } else {
( (
@@ -1224,6 +1239,8 @@ impl BuiltinWorld {
current.string_iterator_proto.clone(), current.string_iterator_proto.clone(),
current.regexp_string_iterator_proto.clone(), current.regexp_string_iterator_proto.clone(),
current.iterator_helper_proto.clone(), current.iterator_helper_proto.clone(),
current.disposable_stack_proto.clone(),
current.async_disposable_stack_proto.clone(),
) )
}; };
@@ -1325,6 +1342,8 @@ impl BuiltinWorld {
string_iterator_proto, string_iterator_proto,
regexp_string_iterator_proto, regexp_string_iterator_proto,
iterator_helper_proto, iterator_helper_proto,
disposable_stack_proto,
async_disposable_stack_proto,
stub_objects, stub_objects,
}; };
wire_builtin_world_links(&world); wire_builtin_world_links(&world);
+16
View File
@@ -657,6 +657,10 @@ impl JsObject {
/// [[BoundThis]] / [[BoundArguments]] 存于 dense 槽 4/5/6+,构造与 instanceof /// [[BoundThis]] / [[BoundArguments]] 存于 dense 槽 4/5/6+,构造与 instanceof
/// 语义转发到 target。 /// 语义转发到 target。
pub const OBJ_TYPE_BOUND: u8 = 23; pub const OBJ_TYPE_BOUND: u8 = 23;
/// DisposableStack 对象:状态盒(Pending/Disposed + entries)存于 `native_data`。
pub const OBJ_TYPE_DISPOSABLE_STACK: u8 = 24;
/// AsyncDisposableStack 对象(步3 用):状态盒与同步栈同构,预留 type_tag。
pub const OBJ_TYPE_ASYNC_DISPOSABLE_STACK: u8 = 25;
/// `is_session_epoch` 字段中的 session 标记位。 /// `is_session_epoch` 字段中的 session 标记位。
pub const SESSION_EPOCH_BIT: u8 = 0x01; pub const SESSION_EPOCH_BIT: u8 = 0x01;
/// `is_session_epoch` 字段中的 GC 标记位。 /// `is_session_epoch` 字段中的 GC 标记位。
@@ -770,6 +774,18 @@ impl JsObject {
self.type_tag == Self::OBJ_TYPE_ERROR self.type_tag == Self::OBJ_TYPE_ERROR
} }
/// 是否 DisposableStack 对象(同步资源栈)。
#[inline]
pub fn is_disposable_stack_obj(&self) -> bool {
self.type_tag == Self::OBJ_TYPE_DISPOSABLE_STACK
}
/// 是否 AsyncDisposableStack 对象(异步资源栈,步3 用)。
#[inline]
pub fn is_async_disposable_stack_obj(&self) -> bool {
self.type_tag == Self::OBJ_TYPE_ASYNC_DISPOSABLE_STACK
}
/// 构造无属性、可扩展的空对象(`new Object()` 的基础对象)。 /// 构造无属性、可扩展的空对象(`new Object()` 的基础对象)。
pub fn new_empty(shape_id: ShapeId, proto: JsValue) -> Self { pub fn new_empty(shape_id: ShapeId, proto: JsValue) -> Self {
Self { Self {