chore: 清理 well-known symbol 对象冒充路径的读侧死代码

This commit is contained in:
2026-10-05 17:58:13 +00:00
parent 75810cb8e7
commit 3330c0fb8c
5 changed files with 24 additions and 75 deletions
Generated
+18 -18
View File
@@ -1095,7 +1095,7 @@ dependencies = [
[[package]]
name = "oxide_builtins"
version = "0.8.11"
version = "0.8.12"
dependencies = [
"chrono",
"fast-float",
@@ -1120,7 +1120,7 @@ dependencies = [
[[package]]
name = "oxide_bytecode"
version = "0.8.11"
version = "0.8.12"
dependencies = [
"num-bigint",
"oxide_log",
@@ -1128,7 +1128,7 @@ dependencies = [
[[package]]
name = "oxide_cfg"
version = "0.8.11"
version = "0.8.12"
dependencies = [
"oxide_bytecode",
"oxide_emit",
@@ -1139,7 +1139,7 @@ dependencies = [
[[package]]
name = "oxide_cli"
version = "0.8.11"
version = "0.8.12"
dependencies = [
"ansi_term",
"bumpalo",
@@ -1159,7 +1159,7 @@ dependencies = [
[[package]]
name = "oxide_code_cache"
version = "0.8.11"
version = "0.8.12"
dependencies = [
"lru",
"oxide_bytecode",
@@ -1168,7 +1168,7 @@ dependencies = [
[[package]]
name = "oxide_compiler"
version = "0.8.11"
version = "0.8.12"
dependencies = [
"oxide_bytecode",
"oxide_cfg",
@@ -1187,7 +1187,7 @@ dependencies = [
[[package]]
name = "oxide_dce"
version = "0.8.11"
version = "0.8.12"
dependencies = [
"oxide_bytecode",
"oxide_cfg",
@@ -1201,7 +1201,7 @@ dependencies = [
[[package]]
name = "oxide_emit"
version = "0.8.11"
version = "0.8.12"
dependencies = [
"num-bigint",
"oxc_allocator",
@@ -1216,7 +1216,7 @@ dependencies = [
[[package]]
name = "oxide_ir"
version = "0.8.11"
version = "0.8.12"
dependencies = [
"oxide_bytecode",
"oxide_log",
@@ -1225,7 +1225,7 @@ dependencies = [
[[package]]
name = "oxide_kernel"
version = "0.8.11"
version = "0.8.12"
dependencies = [
"bumpalo",
"dashmap",
@@ -1240,7 +1240,7 @@ dependencies = [
[[package]]
name = "oxide_liveness"
version = "0.8.11"
version = "0.8.12"
dependencies = [
"oxide_bytecode",
"oxide_cfg",
@@ -1252,7 +1252,7 @@ dependencies = [
[[package]]
name = "oxide_log"
version = "0.8.11"
version = "0.8.12"
dependencies = [
"tracing",
"tracing-appender",
@@ -1261,7 +1261,7 @@ dependencies = [
[[package]]
name = "oxide_parser"
version = "0.8.11"
version = "0.8.12"
dependencies = [
"oxc_allocator",
"oxc_ast",
@@ -1276,7 +1276,7 @@ dependencies = [
[[package]]
name = "oxide_regalloc"
version = "0.8.11"
version = "0.8.12"
dependencies = [
"oxide_bytecode",
"oxide_cfg",
@@ -1292,7 +1292,7 @@ dependencies = [
[[package]]
name = "oxide_runtime_api"
version = "0.8.11"
version = "0.8.12"
dependencies = [
"num-bigint",
"num-traits",
@@ -1304,7 +1304,7 @@ dependencies = [
[[package]]
name = "oxide_test262"
version = "0.8.11"
version = "0.8.12"
dependencies = [
"oxide_bytecode",
"oxide_compiler",
@@ -1321,7 +1321,7 @@ dependencies = [
[[package]]
name = "oxide_types"
version = "0.8.11"
version = "0.8.12"
dependencies = [
"bumpalo",
"hashbrown 0.14.5",
@@ -1333,7 +1333,7 @@ dependencies = [
[[package]]
name = "oxide_vm"
version = "0.8.11"
version = "0.8.12"
dependencies = [
"bumpalo",
"chrono",
+1 -1
View File
@@ -22,7 +22,7 @@ members = [
]
[workspace.package]
version = "0.8.11"
version = "0.8.12"
edition = "2021"
license = "MIT"
rust-version = "1.80"
+3 -49
View File
@@ -977,18 +977,10 @@ fn string_to_bigint_full<H: VmHost>(host: &mut H, s: &str) -> Result<JsValue, St
Ok(host.new_bigint(if neg { -m } else { m }))
}
/// `String()` 构造器的字符串转换(§21.1.1.1):原始 Symbol 值(及本引擎以空对象
/// 表示的 well-known symbol)返回描述串 `Symbol(desc)`(步骤 2a);其余走完整
/// ToString(步骤 3)——装箱 Symbol 的 ToPrimitive 返回 Symbol 本体,ToString 抛
/// TypeError。
/// `String()` 构造器的字符串转换(§21.1.1.1):原始 Symbol 值返回描述串
/// `Symbol(desc)`(步骤 2a);其余走完整 ToString(步骤 3)——装箱 Symbol 的
/// ToPrimitive 返回 Symbol 本体,ToString 抛 TypeError。
pub fn to_string_for_string_constructor<H: VmHost>(val: JsValue, host: &mut H) -> Result<String, String> {
if val.is_object() {
if let Some(id) = well_known_symbol_id(host, val.as_js_object_ptr()) {
if let Some(name) = well_known_symbol_name(id) {
return Ok(format!("Symbol({name})"));
}
}
}
// 原始 Symbol:步骤 2a,SymbolDescriptiveString(不经 ToString)。
if val.is_symbol() {
let desc = host.symbol_description(val.as_symbol_index()).unwrap_or("");
@@ -1002,44 +994,6 @@ pub fn to_string_for_string_constructor<H: VmHost>(val: JsValue, host: &mut H) -
Ok(to_string(primitive))
}
/// well-known symbol 以空对象存于 builtin world;把一个对象指针反查回它的
/// well-known symbol id(0..WELL_KNOWN_SYMBOL_COUNT),非 well-known symbol 返回 None。
pub fn well_known_symbol_id<H: VmHost + ?Sized>(host: &H, ptr: *mut JsObject) -> Option<u32> {
if ptr.is_null() {
return None;
}
let world = host.session().builtin_world();
if std::ptr::eq(ptr, world.sym_iterator.as_ptr()) {
Some(0)
} else if std::ptr::eq(ptr, world.sym_match.as_ptr()) {
Some(1)
} else if std::ptr::eq(ptr, world.sym_replace.as_ptr()) {
Some(2)
} else if std::ptr::eq(ptr, world.sym_search.as_ptr()) {
Some(3)
} else if std::ptr::eq(ptr, world.sym_split.as_ptr()) {
Some(4)
} else if std::ptr::eq(ptr, world.sym_to_primitive.as_ptr()) {
Some(5)
} else if std::ptr::eq(ptr, world.sym_has_instance.as_ptr()) {
Some(6)
} else if std::ptr::eq(ptr, world.sym_match_all.as_ptr()) {
Some(7)
} else if std::ptr::eq(ptr, world.sym_async_iterator.as_ptr()) {
Some(8)
} else if std::ptr::eq(ptr, world.sym_to_string_tag.as_ptr()) {
Some(9)
} else if std::ptr::eq(ptr, world.sym_species.as_ptr()) {
Some(10)
} else if std::ptr::eq(ptr, world.sym_async_dispose.as_ptr()) {
Some(11)
} else if std::ptr::eq(ptr, world.sym_dispose.as_ptr()) {
Some(12)
} else {
None
}
}
/// well-known symbol id 的描述名(如 id 9 对应 `Symbol.toStringTag`)。
pub fn well_known_symbol_name(id: u32) -> Option<&'static str> {
oxide_types::private_key::WELL_KNOWN_SYMBOL_NAMES.get(id as usize).copied()
+2 -2
View File
@@ -23,8 +23,8 @@ pub use coercion::{
materialize_string_box, push_to_string, push_units_to, relational_compare, same_value, same_value_zero,
strict_equality, string_concat, string_value_eq, to_bigint_full, to_boolean, to_int32, to_integer_or_infinity,
to_length, to_number, to_number_full, to_object, to_primitive, to_string, to_string_for_string_constructor,
to_string_full, to_string_value_full, to_uint32, to_units_full, well_known_symbol_id, well_known_symbol_name,
write_number_into, ToPrimitiveHint,
to_string_full, to_string_value_full, to_uint32, to_units_full, well_known_symbol_name, write_number_into,
ToPrimitiveHint,
};
pub use host::VmHost;
pub use native_result::NativeResult;
-5
View File
@@ -59,12 +59,7 @@ impl Vm {
if val.is_symbol() {
return Ok(symbol_value_key(val.as_symbol_index()));
}
// 遗留的 well-known symbol 空对象:按指针比对映射到各自的 well-known Symbol 键,
// 避免全部塌缩成同一个键。
if val.is_object() {
if let Some(id) = oxide_runtime_api::well_known_symbol_id(self, val.as_js_object_ptr()) {
return Ok(make_well_known_symbol_key(id));
}
// ToPropertyKey:对象经 ToPrimitive(string hint),结果为 Symbol 时直接作键;
// 其余字符串按单元序列推导键(避免 lossy 文本桥接破坏孤立 surrogate 键)。
let prim = coercion::to_primitive(val, coercion::ToPrimitiveHint::String, self)?;