diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2020-05-12 11:09:28 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-12 11:09:28 -0400 |
commit | 593c3aa857bec2992aba7b7ec588dc031e379572 (patch) | |
tree | f0c3773ee7d8cd6e727837778ca5f7e6e75b90ae | |
parent | 35e8bc8de65b523e082d446dc25f114ed81264a8 (diff) |
Clean up core/shared_queue.js (#5237)
-rw-r--r-- | core/core.js (renamed from core/shared_queue.js) | 30 | ||||
-rw-r--r-- | core/core_test.js (renamed from core/shared_queue_test.js) | 0 | ||||
-rw-r--r-- | core/isolate.rs | 13 |
3 files changed, 14 insertions, 29 deletions
diff --git a/core/shared_queue.js b/core/core.js index 1750740d6..4c6f708bb 100644 --- a/core/shared_queue.js +++ b/core/core.js @@ -19,8 +19,6 @@ SharedQueue Binary Layout /* eslint-disable @typescript-eslint/no-use-before-define */ ((window) => { - const GLOBAL_NAMESPACE = "Deno"; - const CORE_NAMESPACE = "core"; const MAX_RECORDS = 100; const INDEX_NUM_RECORDS = 0; const INDEX_NUM_SHIFTED_OFF = 1; @@ -30,11 +28,8 @@ SharedQueue Binary Layout const HEAD_INIT = 4 * INDEX_RECORDS; // Available on start due to bindings. - const Deno = window[GLOBAL_NAMESPACE]; - const core = Deno[CORE_NAMESPACE]; - // Warning: DO NOT use window.Deno after this point. - // It is possible that the Deno namespace has been deleted. - // Use the above local Deno and core variable instead. + const core = window.Deno.core; + const { recv, send } = core; let sharedBytes; let shared32; @@ -51,20 +46,20 @@ SharedQueue Binary Layout } function init() { - const shared = Deno.core.shared; + const shared = core.shared; assert(shared.byteLength > 0); assert(sharedBytes == null); assert(shared32 == null); sharedBytes = new Uint8Array(shared); shared32 = new Int32Array(shared); asyncHandlers = []; - // Callers should not call Deno.core.recv, use setAsyncHandler. - Deno.core.recv(handleAsyncMsgFromRust); + // Callers should not call core.recv, use setAsyncHandler. + recv(handleAsyncMsgFromRust); } function ops() { // op id 0 is a special value to retrieve the map of registered ops. - const opsMapBytes = Deno.core.send(0, new Uint8Array([]), null); + const opsMapBytes = send(0, new Uint8Array([]), null); const opsMapJson = String.fromCharCode.apply(null, opsMapBytes); return JSON.parse(opsMapJson); } @@ -187,12 +182,14 @@ SharedQueue Binary Layout } function dispatch(opId, control, zeroCopy = null) { - return Deno.core.send(opId, control, zeroCopy); + return send(opId, control, zeroCopy); } - const denoCore = { + Object.assign(window.Deno.core, { setAsyncHandler, dispatch, + ops, + // sharedQueue is private but exposed for testing. sharedQueue: { MAX_RECORDS, head, @@ -202,10 +199,5 @@ SharedQueue Binary Layout reset, shift, }, - ops, - }; - - assert(window[GLOBAL_NAMESPACE] != null); - assert(window[GLOBAL_NAMESPACE][CORE_NAMESPACE] != null); - Object.assign(core, denoCore); + }); })(this); diff --git a/core/shared_queue_test.js b/core/core_test.js index 7821f93a6..7821f93a6 100644 --- a/core/shared_queue_test.js +++ b/core/core_test.js diff --git a/core/isolate.rs b/core/isolate.rs index e3db18663..112af3045 100644 --- a/core/isolate.rs +++ b/core/isolate.rs @@ -348,9 +348,7 @@ impl CoreIsolate { pub(crate) fn shared_init(&mut self) { if self.needs_init { self.needs_init = false; - js_check( - self.execute("shared_queue.js", include_str!("shared_queue.js")), - ); + js_check(self.execute("core.js", include_str!("core.js"))); // Maybe execute the startup script. if let Some(s) = self.startup_script.take() { self.execute(&s.filename, &s.source).unwrap() @@ -1126,15 +1124,10 @@ pub mod tests { } #[test] - fn test_js() { + fn core_test_js() { run_in_task(|mut cx| { let (mut isolate, _dispatch_count) = setup(Mode::Async); - js_check( - isolate.execute( - "shared_queue_test.js", - include_str!("shared_queue_test.js"), - ), - ); + js_check(isolate.execute("core_test.js", include_str!("core_test.js"))); if let Poll::Ready(Err(_)) = isolate.poll_unpin(&mut cx) { unreachable!(); } |