mirror of
https://github.com/denoland/deno.git
synced 2025-02-08 07:16:56 -05:00
fix(ext/node): do not expose self
global in node (#24637)
closes #23727
This commit is contained in:
parent
1469d61055
commit
600b32fdc1
6 changed files with 22 additions and 6 deletions
|
@ -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.
|
// UTF-16 encodings of the managed globals. THIS LIST MUST BE SORTED.
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
const MANAGED_GLOBALS: [&[u16]; 12] = [
|
const MANAGED_GLOBALS: [&[u16]; 13] = [
|
||||||
&str_to_utf16::<6>("Buffer"),
|
&str_to_utf16::<6>("Buffer"),
|
||||||
&str_to_utf16::<14>("clearImmediate"),
|
&str_to_utf16::<14>("clearImmediate"),
|
||||||
&str_to_utf16::<13>("clearInterval"),
|
&str_to_utf16::<13>("clearInterval"),
|
||||||
|
@ -76,13 +76,14 @@ const MANAGED_GLOBALS: [&[u16]; 12] = [
|
||||||
&str_to_utf16::<6>("global"),
|
&str_to_utf16::<6>("global"),
|
||||||
&str_to_utf16::<11>("performance"),
|
&str_to_utf16::<11>("performance"),
|
||||||
&str_to_utf16::<7>("process"),
|
&str_to_utf16::<7>("process"),
|
||||||
|
&str_to_utf16::<4>("self"),
|
||||||
&str_to_utf16::<12>("setImmediate"),
|
&str_to_utf16::<12>("setImmediate"),
|
||||||
&str_to_utf16::<11>("setInterval"),
|
&str_to_utf16::<11>("setInterval"),
|
||||||
&str_to_utf16::<10>("setTimeout"),
|
&str_to_utf16::<10>("setTimeout"),
|
||||||
&str_to_utf16::<6>("window"),
|
&str_to_utf16::<6>("window"),
|
||||||
];
|
];
|
||||||
|
|
||||||
const SHORTEST_MANAGED_GLOBAL: usize = 6;
|
const SHORTEST_MANAGED_GLOBAL: usize = 4;
|
||||||
const LONGEST_MANAGED_GLOBAL: usize = 14;
|
const LONGEST_MANAGED_GLOBAL: usize = 14;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
|
|
@ -356,7 +356,7 @@ internals.__initWorkerThreads = (
|
||||||
(ev: any) => any
|
(ev: any) => any
|
||||||
>();
|
>();
|
||||||
|
|
||||||
parentPort = self as ParentPort;
|
parentPort = globalThis as ParentPort;
|
||||||
threadId = workerId;
|
threadId = workerId;
|
||||||
if (maybeWorkerMetadata) {
|
if (maybeWorkerMetadata) {
|
||||||
const { 0: metadata, 1: _ } = maybeWorkerMetadata;
|
const { 0: metadata, 1: _ } = maybeWorkerMetadata;
|
||||||
|
|
|
@ -17,5 +17,6 @@ export function getSetTimeout(): typeof setTimeout;
|
||||||
|
|
||||||
export function checkProcessGlobal(): void;
|
export function checkProcessGlobal(): void;
|
||||||
export function checkWindowGlobal(): void;
|
export function checkWindowGlobal(): void;
|
||||||
|
export function checkSelfGlobal(): void;
|
||||||
|
|
||||||
export function getFoo(): string;
|
export function getFoo(): string;
|
||||||
|
|
|
@ -20,6 +20,11 @@ exports.checkWindowGlobal = function () {
|
||||||
console.log(Object.getOwnPropertyDescriptor(globalThis, "window") !== undefined);
|
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 () {
|
exports.getFoo = function () {
|
||||||
return globalThis.foo;
|
return globalThis.foo;
|
||||||
}
|
}
|
||||||
|
|
4
tests/testdata/npm/compare_globals/main.out
vendored
4
tests/testdata/npm/compare_globals/main.out
vendored
|
@ -21,6 +21,10 @@ true
|
||||||
true
|
true
|
||||||
true
|
true
|
||||||
true
|
true
|
||||||
|
true
|
||||||
|
true
|
||||||
|
false
|
||||||
|
false
|
||||||
false
|
false
|
||||||
false
|
false
|
||||||
bar
|
bar
|
||||||
|
|
7
tests/testdata/npm/compare_globals/main.ts
vendored
7
tests/testdata/npm/compare_globals/main.ts
vendored
|
@ -37,12 +37,17 @@ console.log(
|
||||||
);
|
);
|
||||||
globals.checkProcessGlobal();
|
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("window" in globalThis);
|
||||||
|
console.log("self" in globalThis);
|
||||||
console.log(
|
console.log(
|
||||||
Object.getOwnPropertyDescriptor(globalThis, "window") !== undefined,
|
Object.getOwnPropertyDescriptor(globalThis, "window") !== undefined,
|
||||||
);
|
);
|
||||||
|
console.log(
|
||||||
|
Object.getOwnPropertyDescriptor(globalThis, "self") !== undefined,
|
||||||
|
);
|
||||||
globals.checkWindowGlobal();
|
globals.checkWindowGlobal();
|
||||||
|
globals.checkSelfGlobal();
|
||||||
|
|
||||||
// "Non-managed" globals are shared between Node and Deno.
|
// "Non-managed" globals are shared between Node and Deno.
|
||||||
(globalThis as any).foo = "bar";
|
(globalThis as any).foo = "bar";
|
||||||
|
|
Loading…
Add table
Reference in a new issue