diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2020-09-04 21:52:19 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-04 07:52:19 -0400 |
commit | 9e50b3ee61b88b8767ecd1165f2aee62a81842de (patch) | |
tree | 6064237d5d7edf6339816b3620c33c8e18ca8a50 | |
parent | 15649b61bd7ac5d868f2df2825e242a39582a622 (diff) |
fix: don't expose globalThis.__bootstrap (#7344)
-rw-r--r-- | cli/rt/06_util.js | 1 | ||||
-rw-r--r-- | cli/rt/99_main.js | 14 | ||||
-rw-r--r-- | cli/tests/unit/globals_test.ts | 7 | ||||
-rw-r--r-- | cli/tsc/99_main_compiler.js | 3 | ||||
-rw-r--r-- | op_crates/web/08_text_encoding.js | 1 | ||||
-rw-r--r-- | op_crates/web/event_test.js | 1 |
6 files changed, 14 insertions, 13 deletions
diff --git a/cli/rt/06_util.js b/cli/rt/06_util.js index b0ed5696f..011fa6de5 100644 --- a/cli/rt/06_util.js +++ b/cli/rt/06_util.js @@ -53,7 +53,6 @@ function immutableDefine( o, p, - // eslint-disable-next-line @typescript-eslint/no-explicit-any value, ) { Object.defineProperty(o, p, { diff --git a/cli/rt/99_main.js b/cli/rt/99_main.js index 846216ec4..c6d6d1395 100644 --- a/cli/rt/99_main.js +++ b/cli/rt/99_main.js @@ -1,7 +1,6 @@ // Removes the `__proto__` for security reasons. This intentionally makes // Deno non compliant with ECMA-262 Annex B.2.2.1 // -// eslint-disable-next-line @typescript-eslint/no-explicit-any delete Object.prototype.__proto__; ((window) => { @@ -292,9 +291,9 @@ delete Object.prototype.__proto__; if (hasBootstrapped) { throw new Error("Worker runtime already bootstrapped"); } - // Remove bootstrapping methods from global scope - globalThis.__bootstrap = undefined; - globalThis.bootstrap = undefined; + // Remove bootstrapping data from the global scope + delete globalThis.__bootstrap; + delete globalThis.bootstrap; util.log("bootstrapMainRuntime"); hasBootstrapped = true; Object.defineProperties(globalThis, windowOrWorkerGlobalScopeMethods); @@ -360,9 +359,9 @@ delete Object.prototype.__proto__; if (hasBootstrapped) { throw new Error("Worker runtime already bootstrapped"); } - // Remove bootstrapping methods from global scope - globalThis.__bootstrap = undefined; - globalThis.bootstrap = undefined; + // Remove bootstrapping data from the global scope + delete globalThis.__bootstrap; + delete globalThis.bootstrap; util.log("bootstrapWorkerRuntime"); hasBootstrapped = true; Object.defineProperties(globalThis, windowOrWorkerGlobalScopeMethods); @@ -412,7 +411,6 @@ delete Object.prototype.__proto__; workerRuntime: bootstrapWorkerRuntime, }, configurable: true, - writable: true, }, }); })(this); diff --git a/cli/tests/unit/globals_test.ts b/cli/tests/unit/globals_test.ts index dabe3c08e..5fc125296 100644 --- a/cli/tests/unit/globals_test.ts +++ b/cli/tests/unit/globals_test.ts @@ -5,6 +5,13 @@ unitTest(function globalThisExists(): void { assert(globalThis != null); }); +unitTest(function noInternalGlobals(): void { + // globalThis.__bootstrap should not be there. + for (const key of Object.keys(globalThis)) { + assert(!key.startsWith("_")); + } +}); + unitTest(function windowExists(): void { assert(window != null); }); diff --git a/cli/tsc/99_main_compiler.js b/cli/tsc/99_main_compiler.js index aa334907a..dede279c1 100644 --- a/cli/tsc/99_main_compiler.js +++ b/cli/tsc/99_main_compiler.js @@ -14,7 +14,6 @@ // Removes the `__proto__` for security reasons. This intentionally makes // Deno non compliant with ECMA-262 Annex B.2.2.1 // -// eslint-disable-next-line @typescript-eslint/no-explicit-any delete Object.prototype.__proto__; ((window) => { @@ -1528,7 +1527,7 @@ delete Object.prototype.__proto__; core.registerErrorClass("TypeError", TypeError); core.registerErrorClass("Other", Error); core.registerErrorClass("Busy", errors.Busy); - globalThis.__bootstrap = undefined; + delete globalThis.__bootstrap; runtimeStart("TS"); } diff --git a/op_crates/web/08_text_encoding.js b/op_crates/web/08_text_encoding.js index e938eecd1..f759fb66c 100644 --- a/op_crates/web/08_text_encoding.js +++ b/op_crates/web/08_text_encoding.js @@ -393,7 +393,6 @@ } } - // eslint-disable-next-line @typescript-eslint/no-explicit-any function isEitherArrayBuffer(x) { return x instanceof SharedArrayBuffer || x instanceof ArrayBuffer || typeof x === "undefined"; diff --git a/op_crates/web/event_test.js b/op_crates/web/event_test.js index 4f9f94fa9..f533d78fb 100644 --- a/op_crates/web/event_test.js +++ b/op_crates/web/event_test.js @@ -72,7 +72,6 @@ function eventPreventDefaultSuccess() { } function eventInitializedWithNonStringType() { - // eslint-disable-next-line @typescript-eslint/no-explicit-any const type = undefined; const event = new Event(type); |