1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-03 12:58:54 -05:00

fix(core): avoid panic on non-string Error.name (#14529)

Fixes #14518
This commit is contained in:
Aaron O'Mullan 2022-05-08 18:03:00 -03:00 committed by GitHub
parent bcd875030a
commit d0f5cd6a06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 2 deletions

View file

@ -2779,3 +2779,9 @@ itest!(spawn_stdout_inherit {
args: "run --quiet --unstable -A spawn_stdout_inherit.ts",
output: "spawn_stdout_inherit.ts.out",
});
itest!(error_name_non_string {
args: "run --quiet error_name_non_string.js",
output: "error_name_non_string.js.out",
exit_code: 1,
});

View file

@ -0,0 +1,8 @@
class ErrorNameNonString extends Error {
constructor() {
super();
this.name = 42;
}
}
throw new ErrorNameNonString();

View file

@ -0,0 +1,4 @@
error: Uncaught Error
throw new ErrorNameNonString();
^
at file:///[WILDCARD]/error_name_non_string.js:[WILDCARD]

View file

@ -164,7 +164,7 @@ fn get_property<'a>(
object.get(scope, key.into())
}
#[derive(serde::Deserialize)]
#[derive(Default, serde::Deserialize)]
pub(crate) struct NativeJsError {
pub name: Option<String>,
pub message: Option<String>,
@ -196,7 +196,7 @@ impl JsError {
let exception: v8::Local<v8::Object> = exception.try_into().unwrap();
let cause = get_property(scope, exception, "cause");
let e: NativeJsError =
serde_v8::from_v8(scope, exception.into()).unwrap();
serde_v8::from_v8(scope, exception.into()).unwrap_or_default();
// Get the message by formatting error.name and error.message.
let name = e.name.clone().unwrap_or_else(|| "Error".to_string());
let message_prop = e.message.clone().unwrap_or_else(|| "".to_string());