0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 09:31:22 -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]
fn console_log() {
let (out, err) = util::run_and_collect_output(

View file

@ -103,25 +103,25 @@ impl Completer for Helper {
if let Some(result) = evaluate_response.get("result") {
if let Some(object_id) = result.get("objectId") {
let get_properties_response = self
.post_message(
"Runtime.getProperties",
Some(json!({
"objectId": object_id,
})),
)
.unwrap();
let get_properties_response = self.post_message(
"Runtime.getProperties",
Some(json!({
"objectId": object_id,
})),
);
if let Some(result) = get_properties_response.get("result") {
let candidates = result
.as_array()
.unwrap()
.iter()
.map(|r| r.get("name").unwrap().as_str().unwrap().to_string())
.filter(|r| r.starts_with(&suffix[1..]))
.collect();
if let Ok(get_properties_response) = get_properties_response {
if let Some(result) = get_properties_response.get("result") {
let candidates = result
.as_array()
.unwrap()
.iter()
.map(|r| r.get("name").unwrap().as_str().unwrap().to_string())
.filter(|r| r.starts_with(&suffix[1..]))
.collect();
return Ok((pos - (suffix.len() - 1), candidates));
return Ok((pos - (suffix.len() - 1), candidates));
}
}
}
}