1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

fix(ext/node): do not expose self global in node (#24637)

closes #23727
This commit is contained in:
Yoshiya Hinosawa 2024-07-19 12:37:08 +09:00 committed by GitHub
parent 3bda8eb4fe
commit 76b8ecbb6d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 22 additions and 6 deletions

View file

@ -67,7 +67,7 @@ const fn str_to_utf16<const N: usize>(s: &str) -> [u16; N] {
// UTF-16 encodings of the managed globals. THIS LIST MUST BE SORTED.
#[rustfmt::skip]
const MANAGED_GLOBALS: [&[u16]; 12] = [
const MANAGED_GLOBALS: [&[u16]; 13] = [
&str_to_utf16::<6>("Buffer"),
&str_to_utf16::<14>("clearImmediate"),
&str_to_utf16::<13>("clearInterval"),
@ -76,13 +76,14 @@ const MANAGED_GLOBALS: [&[u16]; 12] = [
&str_to_utf16::<6>("global"),
&str_to_utf16::<11>("performance"),
&str_to_utf16::<7>("process"),
&str_to_utf16::<4>("self"),
&str_to_utf16::<12>("setImmediate"),
&str_to_utf16::<11>("setInterval"),
&str_to_utf16::<10>("setTimeout"),
&str_to_utf16::<6>("window"),
];
const SHORTEST_MANAGED_GLOBAL: usize = 6;
const SHORTEST_MANAGED_GLOBAL: usize = 4;
const LONGEST_MANAGED_GLOBAL: usize = 14;
#[derive(Debug, Clone, Copy)]

View file

@ -356,7 +356,7 @@ internals.__initWorkerThreads = (
(ev: any) => any
>();
parentPort = self as ParentPort;
parentPort = globalThis as ParentPort;
threadId = workerId;
if (maybeWorkerMetadata) {
const { 0: metadata, 1: _ } = maybeWorkerMetadata;

View file

@ -17,5 +17,6 @@ export function getSetTimeout(): typeof setTimeout;
export function checkProcessGlobal(): void;
export function checkWindowGlobal(): void;
export function checkSelfGlobal(): void;
export function getFoo(): string;
export function getFoo(): string;

View file

@ -20,6 +20,11 @@ exports.checkWindowGlobal = function () {
console.log(Object.getOwnPropertyDescriptor(globalThis, "window") !== undefined);
}
exports.checkSelfGlobal = function () {
console.log("self" in globalThis);
console.log(Object.getOwnPropertyDescriptor(globalThis, "self") !== undefined);
}
exports.getFoo = function () {
return globalThis.foo;
}
}

View file

@ -21,6 +21,10 @@ true
true
true
true
true
true
false
false
false
false
bar

View file

@ -37,12 +37,17 @@ console.log(
);
globals.checkProcessGlobal();
// In Deno, the window global is defined, but in Node it is not.
// In Deno, the window and self globals are defined, but in Node they are not.
console.log("window" in globalThis);
console.log("self" in globalThis);
console.log(
Object.getOwnPropertyDescriptor(globalThis, "window") !== undefined,
);
console.log(
Object.getOwnPropertyDescriptor(globalThis, "self") !== undefined,
);
globals.checkWindowGlobal();
globals.checkSelfGlobal();
// "Non-managed" globals are shared between Node and Deno.
(globalThis as any).foo = "bar";