mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-24 02:31:13 +08:00
feat: 内核预留 MessagePort 原型与 MessageChannel 构造器槽位
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
//! 内置对象 id 枚举(`BuiltinId` 85 变体 + `ALL` 顺序钉表)、世代快照
|
||||
//! 内置对象 id 枚举(`BuiltinId` 87 变体 + `ALL` 顺序钉表)、世代快照
|
||||
//! (`BuiltinSnapshot`)与按家族划分的脏标记位集(`BuiltinDirtySet`);
|
||||
//! `NUM_BUILTINS` 文档承载"新增 BuiltinWorld 字段须同步"四处约束注记。
|
||||
|
||||
@@ -11,7 +11,7 @@ use crate::builtin::BuiltinWorld;
|
||||
/// 维护注意:每个新增的 `BuiltinWorld` 对象字段都必须加到这里以及
|
||||
/// `KernelSession::dirty_since_snapshot()`,以便选择性重置重建正确的
|
||||
/// builtin 家族。
|
||||
pub const NUM_BUILTINS: usize = 85;
|
||||
pub const NUM_BUILTINS: usize = 87;
|
||||
|
||||
/// 内置对象枚举 id,与 `BuiltinWorld` 中的存储槽一一对应。
|
||||
///
|
||||
@@ -105,6 +105,8 @@ pub enum BuiltinId {
|
||||
SharedArrayBufferConstructor = 82,
|
||||
AtomicsObject = 83,
|
||||
AsyncIteratorProto = 84,
|
||||
MessagePortProto = 85,
|
||||
MessageChannelCtor = 86,
|
||||
}
|
||||
|
||||
impl BuiltinId {
|
||||
@@ -197,6 +199,8 @@ impl BuiltinId {
|
||||
BuiltinId::SharedArrayBufferConstructor,
|
||||
BuiltinId::AtomicsObject,
|
||||
BuiltinId::AsyncIteratorProto,
|
||||
BuiltinId::MessagePortProto,
|
||||
BuiltinId::MessageChannelCtor,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -272,6 +276,7 @@ pub struct BuiltinDirtySet {
|
||||
pub stubs: bool,
|
||||
pub global: bool,
|
||||
pub console: bool,
|
||||
pub message_channel: bool,
|
||||
}
|
||||
|
||||
impl BuiltinDirtySet {
|
||||
@@ -305,6 +310,7 @@ impl BuiltinDirtySet {
|
||||
stubs: true,
|
||||
global: true,
|
||||
console: true,
|
||||
message_channel: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,6 +338,7 @@ impl BuiltinDirtySet {
|
||||
|| self.temporal
|
||||
|| self.stubs
|
||||
|| self.console
|
||||
|| self.message_channel
|
||||
}
|
||||
|
||||
/// 是否存在任何污染(builtin world 或 global object)。
|
||||
@@ -344,19 +351,21 @@ impl BuiltinDirtySet {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// 槽对齐面:ALL 表与判别值 0..84 严格同序,快照数组随 NUM_BUILTINS
|
||||
/// 槽对齐面:ALL 表与判别值 0..86 严格同序,快照数组随 NUM_BUILTINS
|
||||
/// 自动扩维、逐槽对齐。
|
||||
#[test]
|
||||
fn builtin_snapshot_all_slots_aligned() {
|
||||
assert_eq!(NUM_BUILTINS, 85);
|
||||
assert_eq!(NUM_BUILTINS, 87);
|
||||
assert_eq!(BuiltinId::ALL.len(), NUM_BUILTINS);
|
||||
for i in 0..84usize {
|
||||
for i in 0..86usize {
|
||||
assert_eq!(BuiltinId::ALL[i] as usize, i);
|
||||
}
|
||||
assert_eq!(BuiltinId::ALL[81], BuiltinId::SharedArrayBufferProto);
|
||||
assert_eq!(BuiltinId::ALL[82], BuiltinId::SharedArrayBufferConstructor);
|
||||
assert_eq!(BuiltinId::ALL[83], BuiltinId::AtomicsObject);
|
||||
assert_eq!(BuiltinId::ALL[84], BuiltinId::AsyncIteratorProto);
|
||||
assert_eq!(BuiltinId::ALL[85], BuiltinId::MessagePortProto);
|
||||
assert_eq!(BuiltinId::ALL[86], BuiltinId::MessageChannelCtor);
|
||||
|
||||
// 快照经 session 全量构造路径采集,generations 数组维度 = 槽数。
|
||||
use crate::kernel::{KernelConfig, KernelCore, KernelSession};
|
||||
|
||||
@@ -196,6 +196,8 @@ impl KernelSession {
|
||||
|| gen(BuiltinId::BigIntProto) != snap(BuiltinId::BigIntProto),
|
||||
global: BuiltinSnapshot::gen(&self.global_object) != snapshot.global_object_generation,
|
||||
console: gen(BuiltinId::Console) != snap(BuiltinId::Console),
|
||||
message_channel: gen(BuiltinId::MessagePortProto) != snap(BuiltinId::MessagePortProto)
|
||||
|| gen(BuiltinId::MessageChannelCtor) != snap(BuiltinId::MessageChannelCtor),
|
||||
};
|
||||
// wrapper 本体被写不落在任何家族位上(写的是 wrapper 自身而非所属 P
|
||||
// 对象):收缩为全脏,强制重建全部家族与 global,使被写的可复用
|
||||
|
||||
Reference in New Issue
Block a user