mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-24 10:41:11 +08:00
feat: Event 体系内核接线九 P 字段加 BuiltinId 加脏位加 ProtoKind
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
//! 内置对象 id 枚举(`BuiltinId` 89 变体 + `ALL` 顺序钉表)、世代快照
|
||||
//! 内置对象 id 枚举(`BuiltinId` 98 变体 + `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 = 89;
|
||||
pub const NUM_BUILTINS: usize = 98;
|
||||
|
||||
/// 内置对象枚举 id,与 `BuiltinWorld` 中的存储槽一一对应。
|
||||
///
|
||||
@@ -109,6 +109,15 @@ pub enum BuiltinId {
|
||||
MessageChannelCtor = 86,
|
||||
BroadcastChannelProto = 87,
|
||||
BroadcastChannelCtor = 88,
|
||||
EventProto = 89,
|
||||
EventCtor = 90,
|
||||
MessageEventProto = 91,
|
||||
MessageEventCtor = 92,
|
||||
ErrorEventProto = 93,
|
||||
ErrorEventCtor = 94,
|
||||
CustomEventProto = 95,
|
||||
CustomEventCtor = 96,
|
||||
EventTargetProto = 97,
|
||||
}
|
||||
|
||||
impl BuiltinId {
|
||||
@@ -205,6 +214,15 @@ impl BuiltinId {
|
||||
BuiltinId::MessageChannelCtor,
|
||||
BuiltinId::BroadcastChannelProto,
|
||||
BuiltinId::BroadcastChannelCtor,
|
||||
BuiltinId::EventProto,
|
||||
BuiltinId::EventCtor,
|
||||
BuiltinId::MessageEventProto,
|
||||
BuiltinId::MessageEventCtor,
|
||||
BuiltinId::ErrorEventProto,
|
||||
BuiltinId::ErrorEventCtor,
|
||||
BuiltinId::CustomEventProto,
|
||||
BuiltinId::CustomEventCtor,
|
||||
BuiltinId::EventTargetProto,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -282,6 +300,7 @@ pub struct BuiltinDirtySet {
|
||||
pub console: bool,
|
||||
pub message_channel: bool,
|
||||
pub broadcast_channel: bool,
|
||||
pub event: bool,
|
||||
}
|
||||
|
||||
impl BuiltinDirtySet {
|
||||
@@ -317,6 +336,7 @@ impl BuiltinDirtySet {
|
||||
console: true,
|
||||
message_channel: true,
|
||||
broadcast_channel: true,
|
||||
event: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -346,6 +366,7 @@ impl BuiltinDirtySet {
|
||||
|| self.console
|
||||
|| self.message_channel
|
||||
|| self.broadcast_channel
|
||||
|| self.event
|
||||
}
|
||||
|
||||
/// 是否存在任何污染(builtin world 或 global object)。
|
||||
@@ -358,13 +379,13 @@ impl BuiltinDirtySet {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// 槽对齐面:ALL 表与判别值 0..88 严格同序,快照数组随 NUM_BUILTINS
|
||||
/// 槽对齐面:ALL 表与判别值 0..97 严格同序,快照数组随 NUM_BUILTINS
|
||||
/// 自动扩维、逐槽对齐。
|
||||
#[test]
|
||||
fn builtin_snapshot_all_slots_aligned() {
|
||||
assert_eq!(NUM_BUILTINS, 89);
|
||||
assert_eq!(NUM_BUILTINS, 98);
|
||||
assert_eq!(BuiltinId::ALL.len(), NUM_BUILTINS);
|
||||
for i in 0..88usize {
|
||||
for i in 0..97usize {
|
||||
assert_eq!(BuiltinId::ALL[i] as usize, i);
|
||||
}
|
||||
assert_eq!(BuiltinId::ALL[81], BuiltinId::SharedArrayBufferProto);
|
||||
@@ -375,6 +396,15 @@ mod tests {
|
||||
assert_eq!(BuiltinId::ALL[86], BuiltinId::MessageChannelCtor);
|
||||
assert_eq!(BuiltinId::ALL[87], BuiltinId::BroadcastChannelProto);
|
||||
assert_eq!(BuiltinId::ALL[88], BuiltinId::BroadcastChannelCtor);
|
||||
assert_eq!(BuiltinId::ALL[89], BuiltinId::EventProto);
|
||||
assert_eq!(BuiltinId::ALL[90], BuiltinId::EventCtor);
|
||||
assert_eq!(BuiltinId::ALL[91], BuiltinId::MessageEventProto);
|
||||
assert_eq!(BuiltinId::ALL[92], BuiltinId::MessageEventCtor);
|
||||
assert_eq!(BuiltinId::ALL[93], BuiltinId::ErrorEventProto);
|
||||
assert_eq!(BuiltinId::ALL[94], BuiltinId::ErrorEventCtor);
|
||||
assert_eq!(BuiltinId::ALL[95], BuiltinId::CustomEventProto);
|
||||
assert_eq!(BuiltinId::ALL[96], BuiltinId::CustomEventCtor);
|
||||
assert_eq!(BuiltinId::ALL[97], BuiltinId::EventTargetProto);
|
||||
|
||||
// 快照经 session 全量构造路径采集,generations 数组维度 = 槽数。
|
||||
use crate::kernel::{KernelConfig, KernelCore, KernelSession};
|
||||
|
||||
@@ -200,6 +200,15 @@ impl KernelSession {
|
||||
|| gen(BuiltinId::MessageChannelCtor) != snap(BuiltinId::MessageChannelCtor),
|
||||
broadcast_channel: gen(BuiltinId::BroadcastChannelProto) != snap(BuiltinId::BroadcastChannelProto)
|
||||
|| gen(BuiltinId::BroadcastChannelCtor) != snap(BuiltinId::BroadcastChannelCtor),
|
||||
event: gen(BuiltinId::EventProto) != snap(BuiltinId::EventProto)
|
||||
|| gen(BuiltinId::EventCtor) != snap(BuiltinId::EventCtor)
|
||||
|| gen(BuiltinId::MessageEventProto) != snap(BuiltinId::MessageEventProto)
|
||||
|| gen(BuiltinId::MessageEventCtor) != snap(BuiltinId::MessageEventCtor)
|
||||
|| gen(BuiltinId::ErrorEventProto) != snap(BuiltinId::ErrorEventProto)
|
||||
|| gen(BuiltinId::ErrorEventCtor) != snap(BuiltinId::ErrorEventCtor)
|
||||
|| gen(BuiltinId::CustomEventProto) != snap(BuiltinId::CustomEventProto)
|
||||
|| gen(BuiltinId::CustomEventCtor) != snap(BuiltinId::CustomEventCtor)
|
||||
|| gen(BuiltinId::EventTargetProto) != snap(BuiltinId::EventTargetProto),
|
||||
};
|
||||
// wrapper 本体被写不落在任何家族位上(写的是 wrapper 自身而非所属 P
|
||||
// 对象):收缩为全脏,强制重建全部家族与 global,使被写的可复用
|
||||
|
||||
Reference in New Issue
Block a user