fix: 为未实现指令返回显式错误

This commit is contained in:
爱特每羊队
2026-06-08 23:33:59 +08:00
parent d809521fd1
commit afcc76a222
+17 -3
View File
@@ -1854,9 +1854,6 @@ impl Vm {
}
_ => {
if !op.is_implemented() {
return Ok(JsValue::undefined());
}
return Err(format!("opcode {op} not yet implemented"));
}
}
@@ -2015,4 +2012,21 @@ mod tests {
assert_eq!(vm.bytecode[1], ptr as u32);
assert_eq!(vm.bytecode[2], (ptr as u64 >> 32) as u32);
}
#[test]
fn unimplemented_profile_opcode_fails_explicitly() {
let module = CompiledModule {
bytecode: vec![
opcode::encode(opcode::OpCode::PROFILE_TYPE, 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("unimplemented opcode should fail explicitly");
assert_eq!(err, "opcode PROFILE_TYPE not yet implemented");
}
}