refactor: 字符串值改用 JsString 指针表示,键与字面量改用 PermInterner

This commit is contained in:
2026-06-24 20:15:15 +08:00
parent 9a62cf1610
commit ddffa8504e
73 changed files with 768 additions and 860 deletions
+11 -18
View File
@@ -85,25 +85,18 @@ fn test_strict_equality_null_undefined() {
#[test]
fn test_to_int32_and_to_uint32() {
let vm = Vm::new();
let sf = vm.kernel_core().string_forge().as_ref();
let string_three = {
let (idx, hash) = vm.kernel_core().string_forge().intern("3");
JsValue::string(idx, hash)
};
let string_bad = {
let (idx, hash) = vm.kernel_core().string_forge().intern("x");
JsValue::string(idx, hash)
};
let mut vm = Vm::new();
let string_three = vm.new_string("3");
let string_bad = vm.new_string("x");
assert_eq!(coercion::to_int32(string_three, sf), 3);
assert_eq!(coercion::to_int32(string_bad, sf), 0);
assert_eq!(coercion::to_int32(JsValue::undefined(), sf), 0);
assert_eq!(coercion::to_int32(JsValue::float(1.9), sf), 1);
assert_eq!(coercion::to_int32(JsValue::float(-1.9), sf), -1);
assert_eq!(coercion::to_int32(JsValue::float(f64::NAN), sf), 0);
assert_eq!(coercion::to_int32(JsValue::float(f64::INFINITY), sf), 0);
assert_eq!(coercion::to_uint32(JsValue::int(-1), sf), 4_294_967_295);
assert_eq!(coercion::to_int32(string_three), 3);
assert_eq!(coercion::to_int32(string_bad), 0);
assert_eq!(coercion::to_int32(JsValue::undefined()), 0);
assert_eq!(coercion::to_int32(JsValue::float(1.9)), 1);
assert_eq!(coercion::to_int32(JsValue::float(-1.9)), -1);
assert_eq!(coercion::to_int32(JsValue::float(f64::NAN)), 0);
assert_eq!(coercion::to_int32(JsValue::float(f64::INFINITY)), 0);
assert_eq!(coercion::to_uint32(JsValue::int(-1)), 4_294_967_295);
}
#[test]