From 073e0dab868256f038e17716a375e5633b61fca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=88=B1=E7=89=B9=E6=AF=8F=E7=BE=8A=E9=98=9F?= Date: Mon, 8 Jun 2026 23:06:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20NEW=5FEXPRESSION=20?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E6=9C=AA=E8=BF=9B=E5=85=A5=20unwind?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/oxide_vm/src/vm.rs | 19 +++++++++++++++---- crates/oxide_vm/tests/regression_tests.rs | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/crates/oxide_vm/src/vm.rs b/crates/oxide_vm/src/vm.rs index 6696675..26da773 100644 --- a/crates/oxide_vm/src/vm.rs +++ b/crates/oxide_vm/src/vm.rs @@ -964,14 +964,25 @@ impl Vm { } } Err(err_val) => { - return Err(format!("Native constructor error: {:?}", err_val)); + self.exception_value = Some(err_val); + self.pending_error_kind = Some("Error"); + match self.unwind() { + Ok(()) => continue, + Err(e) => return Err(e), + } } } } else { - // Bytecode constructor - wired in plan 12.1-03 - return Err( - "NEW_EXPRESSION: bytecode constructors not yet supported".into() + let error = crate::builtins::error::create_error( + self, + "NEW_EXPRESSION: bytecode constructors not yet supported", ); + self.exception_value = Some(error); + self.pending_error_kind = Some("Error"); + match self.unwind() { + Ok(()) => continue, + Err(e) => return Err(e), + } } } diff --git a/crates/oxide_vm/tests/regression_tests.rs b/crates/oxide_vm/tests/regression_tests.rs index 8375024..38adee3 100644 --- a/crates/oxide_vm/tests/regression_tests.rs +++ b/crates/oxide_vm/tests/regression_tests.rs @@ -106,3 +106,21 @@ fn regression_vm_step_limit_is_configurable() { "expected configurable step limit error, got: {result}" ); } + +#[test] +fn regression_new_expression_native_constructor_error_is_catchable() { + assert_eq!( + eval("try { new RegExp('['); 0 } catch (e) { 1 }"), + "1", + "expected native constructor error to enter catch" + ); +} + +#[test] +fn regression_new_expression_bytecode_constructor_error_is_catchable() { + assert_eq!( + eval("try { function C() {} new C(); 0 } catch (e) { 1 }"), + "1", + "expected bytecode constructor capability error to enter catch" + ); +}