fix(repl): fix null eval result (#13804)

Co-authored-by: Satya Rohith <me@satyarohith.com>
This commit is contained in:
Yoshiya Hinosawa 2022-03-02 13:39:08 +09:00 committed by GitHub
parent 7fc5bfe51b
commit b751e97a01
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 0 deletions

View file

@ -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<String>,
pub class_name: Option<String>,
#[serde(default, deserialize_with = "deserialize_some")]
pub value: Option<Value>,
pub unserializable_value: Option<UnserializableValue>,
pub description: Option<String>,
@ -253,6 +255,16 @@ pub struct RemoteObject {
pub custom_preview: Option<CustomPreview>,
}
// 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<Option<T>, 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")]

View file

@ -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| {