summaryrefslogtreecommitdiff
path: root/core/isolate.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2019-10-22 16:49:58 +0200
committerRy Dahl <ry@tinyclouds.org>2019-10-22 10:49:58 -0400
commit6257b4044a181fcaa462aba6c361e3c8fdcad2c9 (patch)
tree6bc5bcff1289123a428512e1dd4359d58508f303 /core/isolate.rs
parentec44b5b6af1b70bb4041c909989b5f94138ecaf5 (diff)
core: gracefully handle bad op id (#3131)
Diffstat (limited to 'core/isolate.rs')
-rw-r--r--core/isolate.rs36
1 files changed, 35 insertions, 1 deletions
diff --git a/core/isolate.rs b/core/isolate.rs
index ede07b1c5..8b15befa3 100644
--- a/core/isolate.rs
+++ b/core/isolate.rs
@@ -311,12 +311,19 @@ impl Isolate {
) {
let isolate = unsafe { Isolate::from_raw_ptr(user_data) };
- let op = isolate.op_registry.call(
+ let maybe_op = isolate.op_registry.call(
op_id,
control_buf.as_ref(),
PinnedBuf::new(zero_copy_buf),
);
+ let op = match maybe_op {
+ Some(op) => op,
+ None => {
+ return isolate.throw_exception(&format!("Unknown op id: {}", op_id))
+ }
+ };
+
// To avoid latency problems we eagerly poll 50 futures and then
// allow to poll ops from `pending_ops`
let op = if isolate.eager_poll_count != 50 {
@@ -414,6 +421,13 @@ impl Isolate {
}
}
+ fn throw_exception(&mut self, exception_text: &str) {
+ let text = CString::new(exception_text).unwrap();
+ unsafe {
+ libdeno::deno_throw_exception(self.libdeno_isolate, text.as_ptr())
+ }
+ }
+
fn respond(
&mut self,
maybe_buf: Option<(OpId, &[u8])>,
@@ -1419,6 +1433,26 @@ pub mod tests {
}
#[test]
+ fn test_pre_dispatch() {
+ run_in_task(|| {
+ let (mut isolate, _dispatch_count) = setup(Mode::OverflowResAsync);
+ js_check(isolate.execute(
+ "bad_op_id.js",
+ r#"
+ let thrown;
+ try {
+ Deno.core.dispatch(100, []);
+ } catch (e) {
+ thrown = e;
+ }
+ assert(thrown == "Unknown op id: 100");
+ "#,
+ ));
+ assert_eq!(Async::Ready(()), isolate.poll().unwrap());
+ });
+ }
+
+ #[test]
fn test_js() {
run_in_task(|| {
let (mut isolate, _dispatch_count) = setup(Mode::AsyncImmediate);