fix: 修复 THROW 错误类型与 Error 子类构造器

This commit is contained in:
爱特每羊队
2026-06-08 23:14:02 +08:00
parent 073e0dab86
commit bbe1fa78af
4 changed files with 136 additions and 19 deletions
@@ -137,3 +137,25 @@ fn reference_error_is_defined() {
let result = eval("typeof ReferenceError").unwrap();
assert!(result.is_string());
}
#[test]
fn error_subtype_constructors_produce_named_objects() {
assert_eq!(
format!("{}", eval("new Error('boom').name == 'Error'").unwrap()),
"true"
);
assert_eq!(
format!(
"{}",
eval("new TypeError('boom').name == 'TypeError'").unwrap()
),
"true"
);
assert_eq!(
format!(
"{}",
eval("new SyntaxError('boom').name == 'SyntaxError'").unwrap()
),
"true"
);
}
+28
View File
@@ -84,6 +84,34 @@ fn regression_throw_statement_errors() {
result.contains("uncaught"),
"expected uncaught, got: {result}"
);
assert!(
result.contains("uncaught Error"),
"expected string throw to default to Error, got: {result}"
);
}
#[test]
fn regression_throw_statement_preserves_type_error_kind() {
assert_eq!(
eval("try { throw new TypeError('boom') } catch (e) { e.name == 'TypeError' }"),
"true"
);
assert_eq!(
eval("throw new TypeError('boom')"),
"vm error: uncaught TypeError: {object}"
);
}
#[test]
fn regression_throw_statement_preserves_syntax_error_kind() {
assert_eq!(
eval("try { throw new SyntaxError('boom') } catch (e) { e.name == 'SyntaxError' }"),
"true"
);
assert_eq!(
eval("throw new SyntaxError('boom')"),
"vm error: uncaught SyntaxError: {object}"
);
}
#[test]