From 36e7c5b199dba27ce2811024e3531b6cf28390fd Mon Sep 17 00:00:00 2001 From: pjh456 <147148383@qq.com> Date: Mon, 8 Jun 2026 23:19:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=B8=BA=20FOR=5FOF=20=E6=8C=87?= =?UTF-8?q?=E4=BB=A4=E6=8F=90=E4=BE=9B=E6=98=BE=E5=BC=8F=E6=9C=AA=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/oxide_vm/src/vm.rs | 53 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/crates/oxide_vm/src/vm.rs b/crates/oxide_vm/src/vm.rs index c86ea8a2..dd66d2cc 100644 --- a/crates/oxide_vm/src/vm.rs +++ b/crates/oxide_vm/src/vm.rs @@ -1797,13 +1797,21 @@ impl Vm { self.for_in_iters.pop(); } - OpCode::FOR_OF_INIT => {} + OpCode::FOR_OF_INIT => { + return Err("opcode FOR_OF_INIT not yet implemented".into()); + } - OpCode::FOR_OF_NEXT => {} + OpCode::FOR_OF_NEXT => { + return Err("opcode FOR_OF_NEXT not yet implemented".into()); + } - OpCode::FOR_OF_DONE => {} + OpCode::FOR_OF_DONE => { + return Err("opcode FOR_OF_DONE not yet implemented".into()); + } - OpCode::FOR_OF_CLOSE => {} + OpCode::FOR_OF_CLOSE => { + return Err("opcode FOR_OF_CLOSE not yet implemented".into()); + } OpCode::THROW => { let exc_value = self.regs[rd]; @@ -1875,6 +1883,7 @@ impl Default for Vm { #[cfg(test)] mod tests { use super::{opcode, JsValue, TryHandler, Vm}; + use oxide_compiler::module::CompiledModule; #[test] fn reset_clears_runtime_state_like_rerun() { @@ -1918,4 +1927,40 @@ mod tests { assert!(vm.bytecode.is_empty()); assert!(vm.constants.is_empty()); } + + #[test] + fn for_of_opcodes_fail_explicitly() { + for (op, expected) in [ + ( + opcode::OpCode::FOR_OF_INIT, + "opcode FOR_OF_INIT not yet implemented", + ), + ( + opcode::OpCode::FOR_OF_NEXT, + "opcode FOR_OF_NEXT not yet implemented", + ), + ( + opcode::OpCode::FOR_OF_DONE, + "opcode FOR_OF_DONE not yet implemented", + ), + ( + opcode::OpCode::FOR_OF_CLOSE, + "opcode FOR_OF_CLOSE not yet implemented", + ), + ] { + let module = CompiledModule { + bytecode: vec![ + opcode::encode(op, 0, 0, 0), + opcode::encode(opcode::OpCode::HALT, 0, 0, 0), + ], + n_registers: 1, + ..CompiledModule::new() + }; + let mut vm = Vm::new(); + let err = vm + .run(&module) + .expect_err("FOR_OF opcode should fail explicitly"); + assert_eq!(err, expected); + } + } }