1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -05:00

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 Satya Rohith
parent e33522b87a
commit 0d6c4f9796
No known key found for this signature in database
GPG key ID: B2705CF40523EB05
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| {