forked from denoland/deno
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "refactor(repl): use an inspector session (denoland#7763)"
This reverts commit 4c779b5.
- Loading branch information
Showing
13 changed files
with
349 additions
and
282 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. | ||
|
||
use crate::repl; | ||
use crate::repl::Repl; | ||
use deno_core::error::bad_resource_id; | ||
use deno_core::error::AnyError; | ||
use deno_core::serde_json; | ||
use deno_core::serde_json::json; | ||
use deno_core::serde_json::Value; | ||
use deno_core::BufVec; | ||
use deno_core::OpState; | ||
use deno_core::ZeroCopyBuf; | ||
use serde::Deserialize; | ||
use std::cell::RefCell; | ||
use std::rc::Rc; | ||
use std::sync::Arc; | ||
use std::sync::Mutex; | ||
|
||
pub fn init(rt: &mut deno_core::JsRuntime) { | ||
super::reg_json_sync(rt, "op_repl_start", op_repl_start); | ||
super::reg_json_async(rt, "op_repl_readline", op_repl_readline); | ||
} | ||
|
||
struct ReplResource(Arc<Mutex<Repl>>); | ||
|
||
#[derive(Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
struct ReplStartArgs { | ||
history_file: String, | ||
} | ||
|
||
fn op_repl_start( | ||
state: &mut OpState, | ||
args: Value, | ||
_zero_copy: &mut [ZeroCopyBuf], | ||
) -> Result<Value, AnyError> { | ||
let args: ReplStartArgs = serde_json::from_value(args)?; | ||
debug!("op_repl_start {}", args.history_file); | ||
let history_path = { | ||
let cli_state = super::global_state(state); | ||
repl::history_path(&cli_state.dir, &args.history_file) | ||
}; | ||
let repl = repl::Repl::new(history_path); | ||
let resource = ReplResource(Arc::new(Mutex::new(repl))); | ||
let rid = state.resource_table.add("repl", Box::new(resource)); | ||
Ok(json!(rid)) | ||
} | ||
|
||
#[derive(Deserialize)] | ||
struct ReplReadlineArgs { | ||
rid: i32, | ||
prompt: String, | ||
} | ||
|
||
async fn op_repl_readline( | ||
state: Rc<RefCell<OpState>>, | ||
args: Value, | ||
_zero_copy: BufVec, | ||
) -> Result<Value, AnyError> { | ||
let args: ReplReadlineArgs = serde_json::from_value(args)?; | ||
let rid = args.rid as u32; | ||
let prompt = args.prompt; | ||
debug!("op_repl_readline {} {}", rid, prompt); | ||
let repl = { | ||
let state = state.borrow(); | ||
let resource = state | ||
.resource_table | ||
.get::<ReplResource>(rid) | ||
.ok_or_else(bad_resource_id)?; | ||
resource.0.clone() | ||
}; | ||
tokio::task::spawn_blocking(move || { | ||
let line = repl.lock().unwrap().readline(&prompt)?; | ||
Ok(json!(line)) | ||
}) | ||
.await | ||
.unwrap() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.