feat: SuppressedError 内置错误实现(三字段属性序 + 构造器接线)

This commit is contained in:
2026-08-16 19:04:09 +08:00
parent 554a69078f
commit e100bfb8b4
7 changed files with 272 additions and 11 deletions
+16
View File
@@ -120,6 +120,7 @@ pub struct ErrorMethods {
pub syntax_error: *const (),
pub uri_error: *const (),
pub eval_error: *const (),
pub suppressed_error: *const (),
pub to_string: *const (),
pub stack: *const (),
}
@@ -205,6 +206,7 @@ pub struct BuiltinWorld {
pub syntax_error_proto: P<JsObject>,
pub uri_error_proto: P<JsObject>,
pub eval_error_proto: P<JsObject>,
pub suppressed_error_proto: P<JsObject>,
pub math_object: P<JsObject>,
pub json_object: P<JsObject>,
pub date_constructor: P<JsObject>,
@@ -362,6 +364,7 @@ fn make_error_subtypes(error_proto: &P<JsObject>) -> ErrorSubtypeProtos {
syntax_error_proto: P::new(JsObject::new_empty(EMPTY_SHAPE_ID, error_proto_val)),
uri_error_proto: P::new(JsObject::new_empty(EMPTY_SHAPE_ID, error_proto_val)),
eval_error_proto: P::new(JsObject::new_empty(EMPTY_SHAPE_ID, error_proto_val)),
suppressed_error_proto: P::new(JsObject::new_empty(EMPTY_SHAPE_ID, error_proto_val)),
}
}
@@ -372,6 +375,7 @@ struct ErrorSubtypeProtos {
syntax_error_proto: P<JsObject>,
uri_error_proto: P<JsObject>,
eval_error_proto: P<JsObject>,
suppressed_error_proto: P<JsObject>,
}
struct TypedArrayFamily {
@@ -690,6 +694,7 @@ impl BuiltinWorld {
BuiltinId::SyntaxErrorProto => &self.syntax_error_proto,
BuiltinId::UriErrorProto => &self.uri_error_proto,
BuiltinId::EvalErrorProto => &self.eval_error_proto,
BuiltinId::SuppressedErrorProto => &self.suppressed_error_proto,
BuiltinId::MathObject => &self.math_object,
BuiltinId::JsonObject => &self.json_object,
BuiltinId::DateConstructor => &self.date_constructor,
@@ -849,6 +854,7 @@ impl BuiltinWorld {
syntax_error_proto: error_subtypes.syntax_error_proto,
uri_error_proto: error_subtypes.uri_error_proto,
eval_error_proto: error_subtypes.eval_error_proto,
suppressed_error_proto: error_subtypes.suppressed_error_proto,
math_object,
json_object,
date_constructor,
@@ -993,6 +999,7 @@ impl BuiltinWorld {
syntax_error_proto: current.syntax_error_proto.clone(),
uri_error_proto: current.uri_error_proto.clone(),
eval_error_proto: current.eval_error_proto.clone(),
suppressed_error_proto: current.suppressed_error_proto.clone(),
},
)
};
@@ -1243,6 +1250,7 @@ impl BuiltinWorld {
syntax_error_proto: error_subtypes.syntax_error_proto,
uri_error_proto: error_subtypes.uri_error_proto,
eval_error_proto: error_subtypes.eval_error_proto,
suppressed_error_proto: error_subtypes.suppressed_error_proto,
math_object,
json_object,
date_constructor,
@@ -1464,6 +1472,7 @@ impl BuiltinWorld {
("SyntaxError", methods.syntax_error, 1),
("URIError", methods.uri_error, 1),
("EvalError", methods.eval_error, 1),
("SuppressedError", methods.suppressed_error, 3),
);
let proto_ptr = P::as_ptr(&self.error_proto) as *mut JsObject;
@@ -1500,6 +1509,13 @@ impl BuiltinWorld {
self.set_subtype_proto_name(string_forge, shape_forge, &self.syntax_error_proto, "SyntaxError", si_name);
self.set_subtype_proto_name(string_forge, shape_forge, &self.uri_error_proto, "URIError", si_name);
self.set_subtype_proto_name(string_forge, shape_forge, &self.eval_error_proto, "EvalError", si_name);
self.set_subtype_proto_name(
string_forge,
shape_forge,
&self.suppressed_error_proto,
"SuppressedError",
si_name,
);
}
fn set_subtype_proto_name(
+9 -5
View File
@@ -225,12 +225,13 @@ pub struct KernelSession {
/// 维护注意:每个新增的 `BuiltinWorld` 对象字段都必须加到这里以及
/// `KernelSession::dirty_since_snapshot()`,以便选择性重置重建正确的
/// builtin 家族。
pub const NUM_BUILTINS: usize = 88;
pub const NUM_BUILTINS: usize = 89;
/// 内置对象枚举 id,与 `BuiltinWorld` 中的存储槽一一对应。
///
/// 覆盖各构造器/原型、Error 家族、集合类型、TypedArray 家族与 well-known symbols;
/// `repr(u8)` 使其可直接作为数组下标(`u8` 值即下标)。
/// 覆盖各构造器/原型、Error 家族(含 SuppressedError 原型)、集合类型、
/// TypedArray 家族与 well-known symbols;`repr(u8)` 使其可直接作为数组下标
/// (`u8` 值即下标)。
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[repr(u8)]
pub enum BuiltinId {
@@ -322,10 +323,11 @@ pub enum BuiltinId {
PlainDateTimeProto = 84,
SymAsyncDispose = 86,
SymDispose = 87,
SuppressedErrorProto = 88,
}
impl BuiltinId {
/// 全部 86 个内置对象的 id 常量表,供快照/脏检查按序遍历。
/// 全部内置对象的 id 常量表,供快照/脏检查按序遍历。
/// 顺序必须与枚举判别值一致(`ALL[i]` 的 `u8` 值 == `i`):
/// 快照数组按下标填充,脏检查按下标回读,错位会误判 builtin 家族永久脏。
pub const ALL: [BuiltinId; NUM_BUILTINS] = [
@@ -417,6 +419,7 @@ impl BuiltinId {
BuiltinId::SymSpecies,
BuiltinId::SymAsyncDispose,
BuiltinId::SymDispose,
BuiltinId::SuppressedErrorProto,
];
}
@@ -607,7 +610,8 @@ impl KernelSession {
|| gen(BuiltinId::RangeErrorProto) != snap(BuiltinId::RangeErrorProto)
|| gen(BuiltinId::SyntaxErrorProto) != snap(BuiltinId::SyntaxErrorProto)
|| gen(BuiltinId::UriErrorProto) != snap(BuiltinId::UriErrorProto)
|| gen(BuiltinId::EvalErrorProto) != snap(BuiltinId::EvalErrorProto),
|| gen(BuiltinId::EvalErrorProto) != snap(BuiltinId::EvalErrorProto)
|| gen(BuiltinId::SuppressedErrorProto) != snap(BuiltinId::SuppressedErrorProto),
symbol_family: gen(BuiltinId::SymbolProto) != snap(BuiltinId::SymbolProto)
|| gen(BuiltinId::SymbolConstructor) != snap(BuiltinId::SymbolConstructor)
|| gen(BuiltinId::SymMatch) != snap(BuiltinId::SymMatch)