Skip to content

Commit

Permalink
deno_core_test passes
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Mar 15, 2019
1 parent 99a270d commit e532a18
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
31 changes: 19 additions & 12 deletions core/isolate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ pub trait Behavior {

/// Called whenever libdeno.send() is called in JavaScript. zero_copy_buf
/// corresponds to the second argument of libdeno.send().
fn recv(&mut self, control: &[u8], zero_copy_buf: deno_buf) -> (bool, Box<Op>);
fn recv(
&mut self,
control: &[u8],
zero_copy_buf: deno_buf,
) -> (bool, Box<Op>);
}

/// A single execution context of JavaScript. Corresponds roughly to the "Web
Expand Down Expand Up @@ -121,21 +125,23 @@ impl<B: Behavior> Isolate<B> {
let control_shared = isolate.shared.shift();

let (is_sync, op) = if control_argv0.len() > 0 {
// The user called libdeno.send(control)
assert!(control_shared.is_none());
isolate.behavior.recv(control_argv0.as_ref(), zero_copy_buf)
// The user called libdeno.send(control)
assert!(control_shared.is_none());
isolate.behavior.recv(control_argv0.as_ref(), zero_copy_buf)
} else if let Some(c) = control_shared {
// The user called Deno._sharedQueue.push(control)
// At this point the SharedQueue should be empty.
assert!(isolate.shared.shift().is_none());
isolate.behavior.recv(&c, zero_copy_buf)
// The user called Deno._sharedQueue.push(control)
// At this point the SharedQueue should be empty.
assert!(isolate.shared.shift().is_none());
isolate.behavior.recv(&c, zero_copy_buf)
} else {
// The sharedQueue is empty. The shouldn't happen usually, but it's also
// not technically a failure.
return;
// The sharedQueue is empty. The shouldn't happen usually, but it's also
// not technically a failure.
#[cfg(test)]
unreachable!();
#[cfg(not(test))]
return;
};


if is_sync {
let res_record = op.wait().unwrap();
let push_success = isolate.shared.push(res_record);
Expand Down Expand Up @@ -365,6 +371,7 @@ impl<B: Behavior> Future for Isolate<B> {
if completed_count > 0 {
debug!("respond");
self.respond()?;
self.shared.reset();
debug!("after respond");
}
}
Expand Down
1 change: 1 addition & 0 deletions core/shared_queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
numRecords,
activeRecords,
push,
reset,
shift
};
})();
15 changes: 10 additions & 5 deletions core/shared_queue.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(dead_code)]

use crate::libdeno::deno_buf;
use crate::isolate::Buf;
use crate::libdeno::deno_buf;

const MAX_RECORDS: usize = 100;

Expand Down Expand Up @@ -217,17 +217,22 @@ mod tests {
assert!(!q.push(alloc_buf(1)));
}

use crate::test_util::*;
use crate::isolate::Isolate;
use futures::Future;
use crate::test_util::*;
use futures::Async;
use futures::Future;

#[test]
fn test_js() {
let behavior = TestBehavior::new();
let mut isolate = Isolate::new(behavior);
js_check(isolate.execute("shared_queue.js", include_str!("shared_queue.js")));
js_check(isolate.execute("shared_queue_test.js", include_str!("shared_queue_test.js")));
js_check(
isolate.execute("shared_queue.js", include_str!("shared_queue.js")),
);
js_check(
isolate
.execute("shared_queue_test.js", include_str!("shared_queue_test.js")),
);
js_check(isolate.execute("<main>", "main()"));
assert_eq!(Ok(Async::Ready(())), isolate.poll());
}
Expand Down

0 comments on commit e532a18

Please sign in to comment.