fix: defineProperty 纯属性描述符按 ES 规范默认创建 value=undefined,不再错误抛 TypeError

This commit is contained in:
爱特每羊队
2026-06-27 17:23:50 +08:00
parent ec380802a8
commit 19bc8e64a4
2 changed files with 11 additions and 8 deletions
@@ -92,11 +92,11 @@ fn get_own_property_descriptor_accessor_fields() {
);
}
// -- New property without value or accessor throws --
// -- New property without value or accessor defaults to data descriptor (ES spec behavior) --
#[test]
fn define_property_new_without_value_throws() {
let result = eval_str("var obj={}; Object.defineProperty(obj,'x',{enumerable:true})");
assert_err_contains(result, "Cannot define new property without value or accessor");
fn define_property_new_attributes_only_defaults_value_undefined() {
let r = eval_str("var obj={}; Object.defineProperty(obj,'x',{enumerable:true}); obj.x").unwrap();
assert!(r.is_undefined(), "new prop with only enumerable should default value to undefined, got {:?}", r);
}
// -- Partial configurable on existing property preserves value --