Skip to content
Permalink
Browse files

deno_core_test passes

  • Loading branch information...
ry committed Mar 15, 2019
1 parent 99a270d commit e532a18e9c28a7e22bed22757d69168ec66d7784
Showing with 30 additions and 17 deletions.
  1. +19 −12 core/isolate.rs
  2. +1 −0 core/shared_queue.js
  3. +10 −5 core/shared_queue.rs
@@ -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
@@ -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);
@@ -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");
}
}
@@ -105,6 +105,7 @@
numRecords,
activeRecords,
push,
reset,
shift
};
})();
@@ -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;

@@ -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());
}

0 comments on commit e532a18

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.