feat: Reflect.construct 实现正确 construct 语义

This commit is contained in:
爱特每羊队
2026-06-30 15:47:05 +08:00
parent 0772fc09b3
commit c871396300
2 changed files with 30 additions and 12 deletions
@@ -92,16 +92,23 @@ fn reflect_apply_calls_function() {
}
#[test]
fn reflect_construct_throws_clear_type_error() {
fn reflect_construct_returns_new_instance() {
let mut vm = Vm::new();
let result = eval(
&mut vm,
"try { Reflect.construct(function(){}, []) } catch (e) { e instanceof TypeError }",
"var o = Reflect.construct(function(){ this.x = 5; }, []); typeof o === 'object' && o.x === 5",
)
.unwrap();
assert!(result.as_bool());
}
#[test]
fn reflect_construct_non_callable_target_throws_type_error() {
let mut vm = Vm::new();
let result = eval(&mut vm, "try { Reflect.construct(123, []) } catch (e) { e instanceof TypeError }").unwrap();
assert!(result.as_bool());
}
#[test]
fn reflect_non_object_target_throws_type_error() {
let mut vm = Vm::new();