1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

fix(repl): do not panic when Deno.inspect throws (#11292)

This commit is contained in:
Casper Beyer 2021-07-07 05:33:06 +08:00 committed by GitHub
parent 7edb1d713c
commit 78ac19f51f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View file

@ -611,3 +611,24 @@ fn assign_underscore_error() {
));
assert!(err.is_empty());
}
#[test]
fn custom_inspect() {
let (out, err) = util::run_and_collect_output(
true,
"repl",
Some(vec![
r#"const o = {
[Symbol.for("Deno.customInspect")]() {
throw new Error('Oops custom inspect error');
},
};"#,
"o",
]),
Some(vec![("NO_COLOR".to_owned(), "1".to_owned())]),
false,
);
assert!(out.contains("Oops custom inspect error"));
assert!(err.is_empty());
}

View file

@ -564,7 +564,13 @@ impl ReplSession {
"Runtime.callFunctionOn",
Some(json!({
"executionContextId": self.context_id,
"functionDeclaration": "function (object) { return Deno[Deno.internal].inspectArgs(['%o', object], { colors: !Deno.noColor }); }",
"functionDeclaration": r#"function (object) {
try {
return Deno[Deno.internal].inspectArgs(["%o", object], { colors: !Deno.noColor });
} catch (err) {
return Deno[Deno.internal].inspectArgs(["%o", err]);
}
}"#,
"arguments": [
evaluate_result,
],