0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-04 01:44:26 -05:00

fix(repl): prevent symbol completion panic (#9400)

This commit is contained in:
Casper Beyer 2021-02-05 19:09:52 +08:00 committed by GitHub
parent 5b9376908a
commit c83e261b42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 17 deletions

View file

@ -1751,6 +1751,31 @@ mod integration {
} }
} }
#[cfg(unix)]
#[test]
fn pty_complete_symbol() {
use std::io::Read;
use util::pty::fork::*;
let deno_exe = util::deno_exe_path();
let fork = Fork::from_ptmx().unwrap();
if let Ok(mut master) = fork.is_parent() {
master.write_all(b"Deno.internal\t\n").unwrap();
master.write_all(b"close();\n").unwrap();
let mut output = String::new();
master.read_to_string(&mut output).unwrap();
assert!(output.contains("Symbol(Deno.internal)"));
fork.wait().unwrap();
} else {
std::env::set_var("NO_COLOR", "1");
let err = exec::Command::new(deno_exe).arg("repl").exec();
println!("err {}", err);
unreachable!()
}
}
#[test] #[test]
fn console_log() { fn console_log() {
let (out, err) = util::run_and_collect_output( let (out, err) = util::run_and_collect_output(

View file

@ -103,15 +103,14 @@ impl Completer for Helper {
if let Some(result) = evaluate_response.get("result") { if let Some(result) = evaluate_response.get("result") {
if let Some(object_id) = result.get("objectId") { if let Some(object_id) = result.get("objectId") {
let get_properties_response = self let get_properties_response = self.post_message(
.post_message(
"Runtime.getProperties", "Runtime.getProperties",
Some(json!({ Some(json!({
"objectId": object_id, "objectId": object_id,
})), })),
) );
.unwrap();
if let Ok(get_properties_response) = get_properties_response {
if let Some(result) = get_properties_response.get("result") { if let Some(result) = get_properties_response.get("result") {
let candidates = result let candidates = result
.as_array() .as_array()
@ -125,6 +124,7 @@ impl Completer for Helper {
} }
} }
} }
}
Ok((pos, Vec::new())) Ok((pos, Vec::new()))
} }