From c49eee551fdf78ab0230ec30d4537c98dd5d0c80 Mon Sep 17 00:00:00 2001 From: Andreu Botella Date: Tue, 31 Aug 2021 19:33:03 +0200 Subject: [PATCH] feat(workers): Make the `Deno` namespace configurable and unfrozen (#11888) This is the worker counterpart of PR #11062. --- cli/tests/testdata/workers/deno_worker.ts | 9 +++++++++ runtime/js/06_util.js | 14 -------------- runtime/js/99_main.js | 3 +-- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/cli/tests/testdata/workers/deno_worker.ts b/cli/tests/testdata/workers/deno_worker.ts index 2a29c8c4df..a4dca15068 100644 --- a/cli/tests/testdata/workers/deno_worker.ts +++ b/cli/tests/testdata/workers/deno_worker.ts @@ -1,7 +1,16 @@ +import { assert } from "../../../../test_util/std/testing/asserts.ts"; + onmessage = function (e) { if (typeof self.Deno === "undefined") { throw new Error("Deno namespace not available in worker"); } + assert(!Object.isFrozen(self.Deno)); + + const desc = Object.getOwnPropertyDescriptor(self, "Deno"); + assert(desc); + assert(desc.configurable); + assert(!desc.writable); + postMessage(e.data); }; diff --git a/runtime/js/06_util.js b/runtime/js/06_util.js index b6a3c3438d..97c0adea4e 100644 --- a/runtime/js/06_util.js +++ b/runtime/js/06_util.js @@ -3,7 +3,6 @@ ((window) => { const { - ObjectDefineProperty, StringPrototypeReplace, TypeError, Promise, @@ -55,18 +54,6 @@ return promise; } - function immutableDefine( - o, - p, - value, - ) { - ObjectDefineProperty(o, p, { - value, - configurable: false, - writable: false, - }); - } - // Keep in sync with `fromFileUrl()` in `std/path/win32.ts`. function pathFromURLWin32(url) { let p = StringPrototypeReplace( @@ -164,7 +151,6 @@ createResolvable, assert, AssertionError, - immutableDefine, pathFromURL, writable, nonEnumerable, diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index fc3eeeccae..c9dd611da5 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -695,8 +695,7 @@ delete Object.prototype.__proto__; }); // Setup `Deno` global - we're actually overriding already // existing global `Deno` with `Deno` namespace from "./deno.ts". - util.immutableDefine(globalThis, "Deno", finalDenoNs); - ObjectFreeze(globalThis.Deno); + ObjectDefineProperty(globalThis, "Deno", util.readOnly(finalDenoNs)); ObjectFreeze(globalThis.Deno.core); signals.setSignals(); } else {