fix: SET 原始值接收者按严格性分流并补脏重建本体标

This commit is contained in:
2026-09-24 19:37:26 +00:00
parent f9e6eb3b2b
commit 4787f2180f
9 changed files with 56 additions and 30 deletions
@@ -427,9 +427,9 @@ fn error_to_string_tag_is_error() {
)
.unwrap();
assert_eq!(vm.lookup_str(r), Some("[object Error]".to_string()));
// Error.prototype 自身同样判定为 Error。
// Error.prototype 本体无 OBJ_TYPE_ERROR 标(普通对象),按规范品牌为 Object。
let r = eval_in(&mut vm, "Object.prototype.toString.call(Error.prototype)").unwrap();
assert_eq!(vm.lookup_str(r), Some("[object Error]".to_string()));
assert_eq!(vm.lookup_str(r), Some("[object Object]".to_string()));
}
#[test]
@@ -573,9 +573,10 @@ fn suppressed_error_call_without_new_creates_object() {
#[test]
fn suppressed_error_prototype_chain_and_shape() {
let mut vm = make_vm();
// 原型仅挂 constructor/name(name 与既有子类型一致排在 constructor 前),无 error/suppressed。
// 原型挂 name/message/constructor(name 与既有子类型一致排在 constructor 前,
// message 为规范空串自身属性),无 error/suppressed。
let r = eval_in(&mut vm, "Object.getOwnPropertyNames(SuppressedError.prototype).join(',')").unwrap();
assert_eq!(vm.lookup_str(r), Some("name,constructor".to_string()));
assert_eq!(vm.lookup_str(r), Some("name,message,constructor".to_string()));
// instanceof Error 走原型链,原型 [[Prototype]] = Error.prototype。
assert_eq!(
format!("{}", eval_in(&mut vm, "new SuppressedError('e','s') instanceof Error").unwrap()),
+12 -2
View File
@@ -102,9 +102,19 @@ fn test_to_int32_and_to_uint32() {
}
#[test]
fn primitive_property_write_throws_clean_type_error() {
fn primitive_property_write_sloppy_auto_boxes() {
// sloppy 模式:原始值接收者 auto-box,写盒后丢弃盒,不抛 TypeError。
for source in ["'abc'.x = 1", "(5).foo = 1", "true.foo = 1"] {
let err = eval(source);
let result = eval(source);
assert_eq!(result, "1", "sloppy auto-box should return 1 for {source}, got {result}");
}
}
#[test]
fn primitive_property_write_strict_throws_clean_type_error() {
// strict 模式:原始值接收者抛 clean TypeError(非内部 opcode 消息)。
for source in ["'abc'.x = 1", "(5).foo = 1", "true.foo = 1"] {
let err = eval(&format!("\"use strict\"; {source}"));
assert!(err.contains("TypeError"), "expected TypeError for {source}, got {err}");
assert!(
!err.contains("IC_SET_PROP on non-object")