mirror of
https://github.com/denoland/deno.git
synced 2025-01-03 12:58:54 -05:00
feat(workers): Make the Deno
namespace configurable and unfrozen (#11888)
This is the worker counterpart of PR #11062.
This commit is contained in:
parent
b518f5e1ba
commit
c49eee551f
3 changed files with 10 additions and 16 deletions
9
cli/tests/testdata/workers/deno_worker.ts
vendored
9
cli/tests/testdata/workers/deno_worker.ts
vendored
|
@ -1,7 +1,16 @@
|
||||||
|
import { assert } from "../../../../test_util/std/testing/asserts.ts";
|
||||||
|
|
||||||
onmessage = function (e) {
|
onmessage = function (e) {
|
||||||
if (typeof self.Deno === "undefined") {
|
if (typeof self.Deno === "undefined") {
|
||||||
throw new Error("Deno namespace not available in worker");
|
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);
|
postMessage(e.data);
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
((window) => {
|
((window) => {
|
||||||
const {
|
const {
|
||||||
ObjectDefineProperty,
|
|
||||||
StringPrototypeReplace,
|
StringPrototypeReplace,
|
||||||
TypeError,
|
TypeError,
|
||||||
Promise,
|
Promise,
|
||||||
|
@ -55,18 +54,6 @@
|
||||||
return promise;
|
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`.
|
// Keep in sync with `fromFileUrl()` in `std/path/win32.ts`.
|
||||||
function pathFromURLWin32(url) {
|
function pathFromURLWin32(url) {
|
||||||
let p = StringPrototypeReplace(
|
let p = StringPrototypeReplace(
|
||||||
|
@ -164,7 +151,6 @@
|
||||||
createResolvable,
|
createResolvable,
|
||||||
assert,
|
assert,
|
||||||
AssertionError,
|
AssertionError,
|
||||||
immutableDefine,
|
|
||||||
pathFromURL,
|
pathFromURL,
|
||||||
writable,
|
writable,
|
||||||
nonEnumerable,
|
nonEnumerable,
|
||||||
|
|
|
@ -695,8 +695,7 @@ delete Object.prototype.__proto__;
|
||||||
});
|
});
|
||||||
// Setup `Deno` global - we're actually overriding already
|
// Setup `Deno` global - we're actually overriding already
|
||||||
// existing global `Deno` with `Deno` namespace from "./deno.ts".
|
// existing global `Deno` with `Deno` namespace from "./deno.ts".
|
||||||
util.immutableDefine(globalThis, "Deno", finalDenoNs);
|
ObjectDefineProperty(globalThis, "Deno", util.readOnly(finalDenoNs));
|
||||||
ObjectFreeze(globalThis.Deno);
|
|
||||||
ObjectFreeze(globalThis.Deno.core);
|
ObjectFreeze(globalThis.Deno.core);
|
||||||
signals.setSignals();
|
signals.setSignals();
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue