summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com>2019-02-09 13:55:40 -0800
committerRyan Dahl <ry@tinyclouds.org>2019-02-09 16:55:40 -0500
commit1d36eb47eb882cb9305a6338019fa2a2b375d7b1 (patch)
tree4584aff9da784f3e05c4fb5314d5911772b4d655 /src
parent1502051453bf16787a59f43004b24d553d39bd26 (diff)
Support scoped variables, unblock REPL async op, and REPL error colors (#1721)
Diffstat (limited to 'src')
-rw-r--r--src/libdeno.rs1
-rw-r--r--src/msg.fbs10
-rw-r--r--src/ops.rs40
-rw-r--r--src/resources.rs13
4 files changed, 54 insertions, 10 deletions
diff --git a/src/libdeno.rs b/src/libdeno.rs
index ddf025aba..a3a711b65 100644
--- a/src/libdeno.rs
+++ b/src/libdeno.rs
@@ -178,5 +178,4 @@ extern "C" {
user_data: *const c_void,
id: deno_mod,
);
-
}
diff --git a/src/msg.fbs b/src/msg.fbs
index de69c31ad..7d8b89175 100644
--- a/src/msg.fbs
+++ b/src/msg.fbs
@@ -1,6 +1,8 @@
union Any {
Start,
StartRes,
+ FormatError,
+ FormatErrorRes,
WorkerGetMessage,
WorkerGetMessageRes,
WorkerPostMessage,
@@ -163,6 +165,14 @@ table StartRes {
no_color: bool;
}
+table FormatError {
+ error: string;
+}
+
+table FormatErrorRes {
+ error: string;
+}
+
table WorkerGetMessage {
unused: int8;
}
diff --git a/src/ops.rs b/src/ops.rs
index 2b4136208..a0646e923 100644
--- a/src/ops.rs
+++ b/src/ops.rs
@@ -10,6 +10,7 @@ use crate::isolate::Buf;
use crate::isolate::Isolate;
use crate::isolate::IsolateState;
use crate::isolate::Op;
+use crate::js_errors::JSError;
use crate::libdeno;
use crate::msg;
use crate::msg_util;
@@ -97,6 +98,7 @@ pub fn dispatch(
msg::Any::Environ => op_env,
msg::Any::Exit => op_exit,
msg::Any::Fetch => op_fetch,
+ msg::Any::FormatError => op_format_error,
msg::Any::Listen => op_listen,
msg::Any::MakeTempDir => op_make_temp_dir,
msg::Any::Metrics => op_metrics,
@@ -283,6 +285,41 @@ fn op_start(
))
}
+fn op_format_error(
+ state: &Arc<IsolateState>,
+ base: &msg::Base<'_>,
+ data: libdeno::deno_buf,
+) -> Box<Op> {
+ assert_eq!(data.len(), 0);
+ let inner = base.inner_as_format_error().unwrap();
+ let orig_error = String::from(inner.error().unwrap());
+
+ let js_error = JSError::from_v8_exception(&orig_error).unwrap();
+ let js_error_mapped = js_error.apply_source_map(&state.dir);
+ let js_error_string = js_error_mapped.to_string();
+
+ let mut builder = FlatBufferBuilder::new();
+ let new_error = builder.create_string(&js_error_string);
+
+ let inner = msg::FormatErrorRes::create(
+ &mut builder,
+ &msg::FormatErrorResArgs {
+ error: Some(new_error),
+ ..Default::default()
+ },
+ );
+
+ ok_future(serialize_response(
+ base.cmd_id(),
+ &mut builder,
+ msg::BaseArgs {
+ inner_type: msg::Any::FormatErrorRes,
+ inner: Some(inner.as_union_value()),
+ ..Default::default()
+ },
+ ))
+}
+
fn serialize_response(
cmd_id: u32,
builder: &mut FlatBufferBuilder<'_>,
@@ -1271,7 +1308,8 @@ fn op_repl_readline(
debug!("op_repl_readline {} {}", rid, prompt);
blocking(base.sync(), move || -> OpResult {
- let line = resources::readline(rid, &prompt)?;
+ let repl = resources::get_repl(rid)?;
+ let line = repl.lock().unwrap().readline(&prompt)?;
let builder = &mut FlatBufferBuilder::new();
let line_off = builder.create_string(&line);
diff --git a/src/resources.rs b/src/resources.rs
index 1f5a121de..59167275b 100644
--- a/src/resources.rs
+++ b/src/resources.rs
@@ -35,7 +35,7 @@ use std::net::{Shutdown, SocketAddr};
use std::process::ExitStatus;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering;
-use std::sync::Mutex;
+use std::sync::{Arc, Mutex};
use tokio;
use tokio::io::{AsyncRead, AsyncWrite};
use tokio::net::TcpStream;
@@ -95,7 +95,7 @@ enum Repr {
TcpListener(tokio::net::TcpListener, Option<futures::task::Task>),
TcpStream(tokio::net::TcpStream),
HttpBody(HttpBody),
- Repl(Repl),
+ Repl(Arc<Mutex<Repl>>),
// Enum size is bounded by the largest variant.
// Use `Box` around large `Child` struct.
// https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant
@@ -334,7 +334,7 @@ pub fn add_hyper_body(body: hyper::Body) -> Resource {
pub fn add_repl(repl: Repl) -> Resource {
let rid = new_rid();
let mut tg = RESOURCE_TABLE.lock().unwrap();
- let r = tg.insert(rid, Repr::Repl(repl));
+ let r = tg.insert(rid, Repr::Repl(Arc::new(Mutex::new(repl))));
assert!(r.is_none());
Resource { rid }
}
@@ -462,14 +462,11 @@ pub fn child_status(rid: ResourceId) -> DenoResult<ChildStatus> {
}
}
-pub fn readline(rid: ResourceId, prompt: &str) -> DenoResult<String> {
+pub fn get_repl(rid: ResourceId) -> DenoResult<Arc<Mutex<Repl>>> {
let mut table = RESOURCE_TABLE.lock().unwrap();
let maybe_repr = table.get_mut(&rid);
match maybe_repr {
- Some(Repr::Repl(ref mut r)) => {
- let line = r.readline(&prompt)?;
- Ok(line)
- }
+ Some(Repr::Repl(ref mut r)) => Ok(r.clone()),
_ => Err(bad_resource()),
}
}