mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-24 02:31:13 +08:00
feat: 内核与内置层增 Atomics 对象槽位与十方法
This commit is contained in:
@@ -11,7 +11,7 @@ use crate::builtin::BuiltinWorld;
|
||||
/// 维护注意:每个新增的 `BuiltinWorld` 对象字段都必须加到这里以及
|
||||
/// `KernelSession::dirty_since_snapshot()`,以便选择性重置重建正确的
|
||||
/// builtin 家族。
|
||||
pub const NUM_BUILTINS: usize = 96;
|
||||
pub const NUM_BUILTINS: usize = 97;
|
||||
|
||||
/// 内置对象枚举 id,与 `BuiltinWorld` 中的存储槽一一对应。
|
||||
///
|
||||
@@ -117,6 +117,7 @@ pub enum BuiltinId {
|
||||
PlainYearMonthProto = 93,
|
||||
SharedArrayBufferProto = 94,
|
||||
SharedArrayBufferConstructor = 95,
|
||||
AtomicsObject = 96,
|
||||
}
|
||||
|
||||
impl BuiltinId {
|
||||
@@ -220,6 +221,7 @@ impl BuiltinId {
|
||||
BuiltinId::PlainYearMonthProto,
|
||||
BuiltinId::SharedArrayBufferProto,
|
||||
BuiltinId::SharedArrayBufferConstructor,
|
||||
BuiltinId::AtomicsObject,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -288,6 +290,7 @@ pub struct BuiltinDirtySet {
|
||||
pub regexp: bool,
|
||||
pub array_buffer: bool,
|
||||
pub shared_array_buffer: bool,
|
||||
pub atomics: bool,
|
||||
pub data_view: bool,
|
||||
pub typed_array_family: bool,
|
||||
pub temporal: bool,
|
||||
@@ -320,6 +323,7 @@ impl BuiltinDirtySet {
|
||||
regexp: true,
|
||||
array_buffer: true,
|
||||
shared_array_buffer: true,
|
||||
atomics: true,
|
||||
data_view: true,
|
||||
typed_array_family: true,
|
||||
temporal: true,
|
||||
@@ -347,6 +351,7 @@ impl BuiltinDirtySet {
|
||||
|| self.regexp
|
||||
|| self.array_buffer
|
||||
|| self.shared_array_buffer
|
||||
|| self.atomics
|
||||
|| self.data_view
|
||||
|| self.typed_array_family
|
||||
|| self.temporal
|
||||
@@ -364,18 +369,19 @@ impl BuiltinDirtySet {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// 槽对齐面:表尾追加 SAB 家族后总槽数 96,既有 94 个判别值零位移,
|
||||
/// 槽对齐面:表尾追加 Atomics 单例后总槽数 97,既有 96 个判别值零位移,
|
||||
/// 快照数组随 NUM_BUILTINS 自动扩维、逐槽对齐。
|
||||
#[test]
|
||||
fn builtin_snapshot_all_slots_aligned() {
|
||||
assert_eq!(NUM_BUILTINS, 96);
|
||||
assert_eq!(NUM_BUILTINS, 97);
|
||||
assert_eq!(BuiltinId::ALL.len(), NUM_BUILTINS);
|
||||
// 前 94 项判别值 0-93 逐项不变(尾追加零位移)。
|
||||
for i in 0..94usize {
|
||||
// 前 96 项判别值 0-95 逐项不变(尾追加零位移)。
|
||||
for i in 0..96usize {
|
||||
assert_eq!(BuiltinId::ALL[i] as usize, i);
|
||||
}
|
||||
assert_eq!(BuiltinId::ALL[94], BuiltinId::SharedArrayBufferProto);
|
||||
assert_eq!(BuiltinId::ALL[95], BuiltinId::SharedArrayBufferConstructor);
|
||||
assert_eq!(BuiltinId::ALL[96], BuiltinId::AtomicsObject);
|
||||
|
||||
// 快照经 session 全量构造路径采集,generations 数组维度 = 槽数。
|
||||
use crate::kernel::{KernelConfig, KernelCore, KernelSession};
|
||||
|
||||
@@ -159,6 +159,7 @@ impl KernelSession {
|
||||
|| gen(BuiltinId::ArrayBufferProto) != snap(BuiltinId::ArrayBufferProto),
|
||||
shared_array_buffer: gen(BuiltinId::SharedArrayBufferProto) != snap(BuiltinId::SharedArrayBufferProto)
|
||||
|| gen(BuiltinId::SharedArrayBufferConstructor) != snap(BuiltinId::SharedArrayBufferConstructor),
|
||||
atomics: gen(BuiltinId::AtomicsObject) != snap(BuiltinId::AtomicsObject),
|
||||
data_view: gen(BuiltinId::DataViewConstructor) != snap(BuiltinId::DataViewConstructor)
|
||||
|| gen(BuiltinId::DataViewProto) != snap(BuiltinId::DataViewProto),
|
||||
typed_array_family: gen(BuiltinId::TypedArrayProto) != snap(BuiltinId::TypedArrayProto)
|
||||
|
||||
Reference in New Issue
Block a user