fix: capture object keys and scope loop bindings

This commit is contained in:
爱特每羊队
2026-08-11 14:17:45 +08:00
parent 925ca358e9
commit ec2efa7b6b
8 changed files with 77 additions and 10 deletions
+12
View File
@@ -92,6 +92,18 @@ fn closure_nested_expr_capture() {
assert_eq!(result.as_double(), 2.0);
}
#[test]
fn closure_captures_computed_object_key_across_caller_frame() {
let result = eval("let key='answer'; const call=fn=>fn(); const make=()=>({[key]:42}); call(make).answer").unwrap();
assert_eq!(result.as_int(), 42);
}
#[test]
fn closure_captures_object_spread_source_across_caller_frame() {
let result = eval("let source={x:7}; const call=fn=>fn(); const make=()=>({...source}); call(make).x").unwrap();
assert_eq!(result.as_int(), 7);
}
#[test]
fn for_let_per_iteration_independent() {
let _ = eval("var fns=[]; for(let i=0;i<3;i++){ fns.push(function(){return i}); } fns[0]()+fns[1]()+fns[2]()");