diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2019-03-26 23:22:07 +1100 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-03-26 08:22:07 -0400 |
commit | c43cfedeba5d6ac96e1b1febed8549e750606e3f (patch) | |
tree | 7b3799259895acadf25294704ea03a9465051e9c /core/isolate.rs | |
parent | ed2977d3c0e9ab3295a3bb47b844b2953d608197 (diff) |
namespace reorg: libdeno and DenoCore to Deno.core (#1998)
Diffstat (limited to 'core/isolate.rs')
-rw-r--r-- | core/isolate.rs | 68 |
1 files changed, 34 insertions, 34 deletions
diff --git a/core/isolate.rs b/core/isolate.rs index 74b8a7270..b28730ba6 100644 --- a/core/isolate.rs +++ b/core/isolate.rs @@ -63,8 +63,8 @@ pub trait Behavior { /// Isolate is created. fn startup_data(&mut self) -> Option<StartupData>; - /// Called whenever libdeno.send() is called in JavaScript. zero_copy_buf - /// corresponds to the second argument of libdeno.send(). + /// Called whenever Deno.core.send() is called in JavaScript. zero_copy_buf + /// corresponds to the second argument of Deno.core.send(). fn dispatch( &mut self, control: &[u8], @@ -77,7 +77,7 @@ pub trait Behavior { /// Tokio. The Isolate future complete when there is an error or when all /// pending ops have completed. /// -/// Ops are created in JavaScript by calling libdeno.send(), and in Rust by +/// Ops are created in JavaScript by calling Deno.core.send(), and in Rust by /// implementing Behavior::dispatch. An Op corresponds exactly to a Promise in /// JavaScript. pub struct Isolate<B: Behavior> { @@ -125,7 +125,7 @@ impl<B: Behavior> Isolate<B> { None => libdeno::deno_buf::empty(), }, shared: shared.as_deno_buf(), - recv_cb: Self::pre_dispatch, + recv_cb: Self::predispatch, }; let libdeno_isolate = unsafe { libdeno::deno_new(config) }; @@ -157,7 +157,7 @@ impl<B: Behavior> Isolate<B> { } } - /// Executes a bit of built-in JavaScript to provide Deno._sharedQueue. + /// Executes a bit of built-in JavaScript to provide Deno.sharedQueue. pub fn shared_init(&mut self) { if self.needs_init { self.needs_init = false; @@ -167,7 +167,7 @@ impl<B: Behavior> Isolate<B> { } } - extern "C" fn pre_dispatch( + extern "C" fn predispatch( user_data: *mut c_void, control_argv0: deno_buf, zero_copy_buf: deno_buf, @@ -178,12 +178,12 @@ 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) + // The user called Deno.core.send(control) isolate .behavior .dispatch(control_argv0.as_ref(), zero_copy_buf) } else if let Some(c) = control_shared { - // The user called Deno._sharedQueue.push(control) + // The user called Deno.sharedQueue.push(control) isolate.behavior.dispatch(&c, zero_copy_buf) } else { // The sharedQueue is empty. The shouldn't happen usually, but it's also @@ -199,7 +199,7 @@ impl<B: Behavior> Isolate<B> { if is_sync { let res_record = op.wait().unwrap(); - // For sync messages, we always return the response via libdeno.send's + // For sync messages, we always return the response via Deno.core.send's // return value. // TODO(ry) check that if JSError thrown during respond(), that it will be // picked up. @@ -614,15 +614,15 @@ mod tests { } #[test] - fn test_dispatch() { + fn testdispatch() { let mut isolate = TestBehavior::setup(TestBehaviorMode::AsyncImmediate); js_check(isolate.execute( "filename.js", r#" let control = new Uint8Array([42]); - libdeno.send(control); + Deno.core.send(control); async function main() { - libdeno.send(control); + Deno.core.send(control); } main(); "#, @@ -641,7 +641,7 @@ mod tests { import { b } from 'b.js' if (b() != 'b') throw Error(); let control = new Uint8Array([42]); - libdeno.send(control); + Deno.core.send(control); "#, ).unwrap(); assert_eq!(isolate.behavior.dispatch_count, 0); @@ -685,7 +685,7 @@ mod tests { "setup2.js", r#" let nrecv = 0; - DenoCore.setAsyncHandler((buf) => { + Deno.core.setAsyncHandler((buf) => { nrecv++; }); "#, @@ -696,7 +696,7 @@ mod tests { r#" assert(nrecv == 0); let control = new Uint8Array([42]); - libdeno.send(control); + Deno.core.send(control); assert(nrecv == 0); "#, )); @@ -707,7 +707,7 @@ mod tests { "check2.js", r#" assert(nrecv == 1); - libdeno.send(control); + Deno.core.send(control); assert(nrecv == 1); "#, )); @@ -727,7 +727,7 @@ mod tests { "setup2.js", r#" let nrecv = 0; - DenoCore.setAsyncHandler((buf) => { + Deno.core.setAsyncHandler((buf) => { assert(buf.byteLength === 1); assert(buf[0] === 43); nrecv++; @@ -740,12 +740,12 @@ mod tests { "send1.js", r#" let control = new Uint8Array([42]); - DenoCore.shared.push(control); - libdeno.send(); + Deno.core.sharedQueue.push(control); + Deno.core.send(); assert(nrecv === 0); - DenoCore.shared.push(control); - libdeno.send(); + Deno.core.sharedQueue.push(control); + Deno.core.send(); assert(nrecv === 0); "#, )); @@ -832,10 +832,10 @@ mod tests { "overflow_req_sync.js", r#" let asyncRecv = 0; - DenoCore.setAsyncHandler((buf) => { asyncRecv++ }); + Deno.core.setAsyncHandler((buf) => { asyncRecv++ }); // Large message that will overflow the shared space. let control = new Uint8Array(100 * 1024 * 1024); - let response = DenoCore.dispatch(control); + let response = Deno.core.dispatch(control); assert(response instanceof Uint8Array); assert(response.length == 1); assert(response[0] == 43); @@ -854,10 +854,10 @@ mod tests { "overflow_res_sync.js", r#" let asyncRecv = 0; - DenoCore.setAsyncHandler((buf) => { asyncRecv++ }); + Deno.core.setAsyncHandler((buf) => { asyncRecv++ }); // Large message that will overflow the shared space. let control = new Uint8Array([42]); - let response = DenoCore.dispatch(control); + let response = Deno.core.dispatch(control); assert(response instanceof Uint8Array); assert(response.length == 100 * 1024 * 1024); assert(response[0] == 99); @@ -874,14 +874,14 @@ mod tests { "overflow_req_async.js", r#" let asyncRecv = 0; - DenoCore.setAsyncHandler((buf) => { + Deno.core.setAsyncHandler((buf) => { assert(buf.byteLength === 1); assert(buf[0] === 43); asyncRecv++; }); // Large message that will overflow the shared space. let control = new Uint8Array(100 * 1024 * 1024); - let response = DenoCore.dispatch(control); + let response = Deno.core.dispatch(control); // Async messages always have null response. assert(response == null); assert(asyncRecv == 0); @@ -901,14 +901,14 @@ mod tests { "overflow_res_async.js", r#" let asyncRecv = 0; - DenoCore.setAsyncHandler((buf) => { + Deno.core.setAsyncHandler((buf) => { assert(buf.byteLength === 100 * 1024 * 1024); assert(buf[0] === 4); asyncRecv++; }); // Large message that will overflow the shared space. let control = new Uint8Array([42]); - let response = DenoCore.dispatch(control); + let response = Deno.core.dispatch(control); assert(response == null); assert(asyncRecv == 0); "#, @@ -919,27 +919,27 @@ mod tests { } #[test] - fn overflow_res_multiple_dispatch_async() { + fn overflow_res_multipledispatch_async() { // TODO(ry) This test is quite slow due to memcpy-ing 100MB into JS. We // should optimize this. let mut isolate = TestBehavior::setup(TestBehaviorMode::OverflowResAsync); js_check(isolate.execute( - "overflow_res_multiple_dispatch_async.js", + "overflow_res_multipledispatch_async.js", r#" let asyncRecv = 0; - DenoCore.setAsyncHandler((buf) => { + Deno.core.setAsyncHandler((buf) => { assert(buf.byteLength === 100 * 1024 * 1024); assert(buf[0] === 4); asyncRecv++; }); // Large message that will overflow the shared space. let control = new Uint8Array([42]); - let response = DenoCore.dispatch(control); + let response = Deno.core.dispatch(control); assert(response == null); assert(asyncRecv == 0); // Dispatch another message to verify that pending ops // are done even if shared space overflows - DenoCore.dispatch(control); + Deno.core.dispatch(control); "#, )); assert_eq!(isolate.behavior.dispatch_count, 2); |