diff options
author | Kevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com> | 2019-08-05 04:23:41 -0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-08-05 07:23:41 -0400 |
commit | ddee2dff14772ade16e282ad18eda6f5054ce94e (patch) | |
tree | 473cdf935b8d0254a7ab8e0c89fd407201793ac6 /js/os.ts | |
parent | aaa7a3eac4df0de9a93dc8fc4717d38212a3de5b (diff) |
Provide option to delete Deno namespace in worker (#2717)
Diffstat (limited to 'js/os.ts')
-rw-r--r-- | js/os.ts | 20 |
1 files changed, 16 insertions, 4 deletions
@@ -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; } |