summaryrefslogtreecommitdiff
path: root/js/os.ts
diff options
context:
space:
mode:
authorKevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com>2019-08-05 04:23:41 -0700
committerRyan Dahl <ry@tinyclouds.org>2019-08-05 07:23:41 -0400
commitddee2dff14772ade16e282ad18eda6f5054ce94e (patch)
tree473cdf935b8d0254a7ab8e0c89fd407201793ac6 /js/os.ts
parentaaa7a3eac4df0de9a93dc8fc4717d38212a3de5b (diff)
Provide option to delete Deno namespace in worker (#2717)
Diffstat (limited to 'js/os.ts')
-rw-r--r--js/os.ts20
1 files changed, 16 insertions, 4 deletions
diff --git a/js/os.ts b/js/os.ts
index 558f47efd..e7d588a52 100644
--- a/js/os.ts
+++ b/js/os.ts
@@ -112,7 +112,10 @@ function sendStart(): msg.StartRes {
// This function bootstraps an environment within Deno, it is shared both by
// the runtime and the compiler environments.
// @internal
-export function start(source?: string): msg.StartRes {
+export function start(
+ preserveDenoNamespace = true,
+ source?: string
+): msg.StartRes {
core.setAsyncHandler(handleAsyncMsgFromRust);
// First we send an empty `Start` message to let the privileged side know we
@@ -124,9 +127,18 @@ export function start(source?: string): msg.StartRes {
setGlobals(startResMsg.pid(), startResMsg.noColor(), startResMsg.execPath()!);
- // Deno.core could ONLY be safely frozen here (not in globals.ts)
- // since shared_queue.js will modify core properties.
- Object.freeze(window.Deno.core);
+ if (preserveDenoNamespace) {
+ util.immutableDefine(window, "Deno", window.Deno);
+ // Deno.core could ONLY be safely frozen here (not in globals.ts)
+ // since shared_queue.js will modify core properties.
+ Object.freeze(window.Deno.core);
+ // core.sharedQueue is an object so we should also freeze it.
+ Object.freeze(window.Deno.core.sharedQueue);
+ } else {
+ // Remove window.Deno
+ delete window.Deno;
+ assert(window.Deno === undefined);
+ }
return startResMsg;
}