mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 02:48:24 +00:00
fix: use static Reflect methods in nodeGlobalThis proxy (#17696)
Co-authored-by: David Sherret <dsherret@gmail.com>
This commit is contained in:
parent
286e5d0be9
commit
ef9b66950f
5 changed files with 50 additions and 32 deletions
|
@ -5,3 +5,6 @@ Download http://localhost:4545/npm/registry/@types/node/node-18.8.2.tgz
|
|||
Check file:///[WILDCARD]/npm/compare_globals/main.ts
|
||||
true
|
||||
[]
|
||||
5
|
||||
undefined
|
||||
undefined
|
||||
|
|
13
cli/tests/testdata/npm/compare_globals/main.ts
vendored
13
cli/tests/testdata/npm/compare_globals/main.ts
vendored
|
@ -12,3 +12,16 @@ type _TestHasNodeJsGlobal = NodeJS.Architecture;
|
|||
|
||||
const controller = new AbortController();
|
||||
controller.abort("reason"); // in the NodeJS declaration it doesn't have a reason
|
||||
|
||||
// Super edge case where some Node code deletes a global where the
|
||||
// Node code has its own global and the Deno code has the same global,
|
||||
// but it's different. Basically if some Node code deletes
|
||||
// one of these globals then we don't want it to suddenly inherit
|
||||
// the Deno global.
|
||||
globals.withNodeGlobalThis((nodeGlobalThis: any) => {
|
||||
(globalThis as any).setTimeout = 5;
|
||||
console.log(setTimeout);
|
||||
delete nodeGlobalThis["setTimeout"];
|
||||
console.log(nodeGlobalThis["setTimeout"]); // should be undefined
|
||||
console.log(globalThis["setTimeout"]); // should be undefined
|
||||
});
|
||||
|
|
|
@ -11,3 +11,5 @@ type AssertTrue<T extends true> = never;
|
|||
type _TestHasProcessGlobal = AssertTrue<
|
||||
typeof globalThis extends { process: any } ? true : false
|
||||
>;
|
||||
|
||||
export function withNodeGlobalThis(action: (global: typeof globalThis) => void): void;
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
exports.globalThis = globalThis;
|
||||
exports.global = global;
|
||||
exports.process = process;
|
||||
|
||||
exports.withNodeGlobalThis = function (action) {
|
||||
action(globalThis);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue