1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 15:24:46 -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 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;
use deno_core::serde_json::Value; use deno_core::serde_json::Value;
use serde::Deserialize; use serde::Deserialize;
use serde::Deserializer;
use serde::Serialize; use serde::Serialize;
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#method-awaitPromise /// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#method-awaitPromise
@ -245,6 +246,7 @@ pub struct RemoteObject {
pub kind: String, pub kind: String,
pub subtype: Option<String>, pub subtype: Option<String>,
pub class_name: Option<String>, pub class_name: Option<String>,
#[serde(default, deserialize_with = "deserialize_some")]
pub value: Option<Value>, pub value: Option<Value>,
pub unserializable_value: Option<UnserializableValue>, pub unserializable_value: Option<UnserializableValue>,
pub description: Option<String>, pub description: Option<String>,
@ -253,6 +255,16 @@ pub struct RemoteObject {
pub custom_preview: Option<CustomPreview>, 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 /// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-ObjectPreview
#[derive(Debug, Clone, Deserialize)] #[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")] #[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] #[test]
fn pty_unpaired_braces() { fn pty_unpaired_braces() {
util::with_pty(&["repl"], |mut console| { util::with_pty(&["repl"], |mut console| {