From 0d6c4f97961b50e95484ecf57880077304578a90 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Wed, 2 Mar 2022 13:39:08 +0900 Subject: [PATCH] fix(repl): fix null eval result (#13804) Co-authored-by: Satya Rohith --- cli/cdp.rs | 12 ++++++++++++ cli/tests/integration/repl_tests.rs | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/cli/cdp.rs b/cli/cdp.rs index 55229947db..d1b09565d7 100644 --- a/cli/cdp.rs +++ b/cli/cdp.rs @@ -4,6 +4,7 @@ use deno_core::serde_json; use deno_core::serde_json::Value; use serde::Deserialize; +use serde::Deserializer; use serde::Serialize; /// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#method-awaitPromise @@ -245,6 +246,7 @@ pub struct RemoteObject { pub kind: String, pub subtype: Option, pub class_name: Option, + #[serde(default, deserialize_with = "deserialize_some")] pub value: Option, pub unserializable_value: Option, pub description: Option, @@ -253,6 +255,16 @@ pub struct RemoteObject { pub custom_preview: Option, } +// Any value that is present is considered Some value, including null. +// ref: https://github.com/serde-rs/serde/issues/984#issuecomment-314143738 +fn deserialize_some<'de, T, D>(deserializer: D) -> Result, D::Error> +where + T: Deserialize<'de>, + D: Deserializer<'de>, +{ + Deserialize::deserialize(deserializer).map(Some) +} + /// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-ObjectPreview #[derive(Debug, Clone, Deserialize)] #[serde(rename_all = "camelCase")] diff --git a/cli/tests/integration/repl_tests.rs b/cli/tests/integration/repl_tests.rs index 571b65fa24..edade5d929 100644 --- a/cli/tests/integration/repl_tests.rs +++ b/cli/tests/integration/repl_tests.rs @@ -33,6 +33,17 @@ fn pty_multiline() { }); } +#[test] +fn pty_null() { + util::with_pty(&["repl"], |mut console| { + console.write_line("null"); + console.write_line("close();"); + + let output = console.read_all_output(); + assert!(output.contains("null")); + }); +} + #[test] fn pty_unpaired_braces() { util::with_pty(&["repl"], |mut console| {