use oxide_compiler::compiler::Compiler; use oxide_parser::Allocator; use oxide_vm::vm::Vm; fn eval(source: &str) -> String { let allocator = Allocator::default(); let program = match oxide_parser::parse(&allocator, source) { Ok(p) => p, Err(e) => return format!("parse error: {}", e[0].message), }; let module = match Compiler::new().compile(&program) { Ok(m) => m, Err(e) => return format!("compile error: {e}"), }; let mut vm = Vm::new(); match vm.run(&module) { Ok(result) => format!("{result}"), Err(e) => format!("vm error: {e}"), } } // Destructured parameter followed by a loop body: the counter must count the parameter // destructuring prologue or the loop's back-jump lands at the wrong PC. #[test] fn param_array_pattern_with_loop_body() { assert_eq!(eval("function f([a]){var s=0; while(a>0){s=s+1;a=a-1;} return s;} f([3])"), "3"); } #[test] fn param_array_pattern_default_element() { assert_eq!(eval("function f([a=5]){return a;} f([])"), "5"); } // Array assignment target with a default element followed by a loop. #[test] fn array_assignment_default_element_then_loop() { assert_eq!(eval("var a,c=0; [a=5]=[]; while(c