Avoid throwing when register is void

This commit is contained in:
Andrew Morris
2023-03-23 10:30:57 +11:00
parent 56b35e06e2
commit 45294cec47
3 changed files with 19 additions and 4 deletions

View File

@@ -132,7 +132,10 @@ impl BytecodeDecoder {
}
BytecodeType::Function => self.decode_function_header(),
BytecodeType::Pointer => self.decode_pointer(),
BytecodeType::Register => registers[self.decode_register_index().unwrap()].clone(),
BytecodeType::Register => match registers[self.decode_register_index().unwrap()].clone() {
Val::Void => Val::Undefined,
val => val,
},
BytecodeType::Builtin => Val::Static(BUILTIN_VALS[self.decode_varsize_uint()]),
BytecodeType::Class => Val::Class(Rc::new(VsClass {
constructor: self.decode_val(registers),

View File

@@ -403,8 +403,20 @@ impl StackFrameTrait for BytecodeStackFrame {
}
Throw => {
let error = self.decoder.decode_val(&self.registers);
return Err(error);
return match self.decoder.peek_type() {
BytecodeType::Register => {
self.decoder.decode_type();
// Avoid the void->undefined conversion here
let error = self.registers[self.decoder.decode_register_index().unwrap()].clone();
match error {
Val::Void => Ok(FrameStepOk::Continue),
_ => Err(error),
}
}
_ => Err(self.decoder.decode_val(&self.registers)),
};
}
Import | ImportStar => {

View File

@@ -42,7 +42,7 @@ impl VsFunction {
}
while registers.len() < registers.capacity() {
registers.push(Val::Undefined);
registers.push(Val::Void);
}
return Box::new(BytecodeStackFrame {