Skip to content

Commit

Permalink
fix(repl): fix null eval result (#13804)
Browse files Browse the repository at this point in the history
Co-authored-by: Satya Rohith <me@satyarohith.com>
  • Loading branch information
kt3k and satyarohith committed Mar 3, 2022
1 parent 1f45bc0 commit bd46d32
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cli/cdp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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>,
Expand All @@ -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")]
Expand Down
11 changes: 11 additions & 0 deletions cli/tests/integration/repl_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down

0 comments on commit bd46d32

Please sign in to comment.