Skip to content

Commit 917f98b

Browse files
jasnelladuh95
authored andcommitted
test: replace more uses of global with globalThis
PR-URL: #56712 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent bf34a49 commit 917f98b

File tree

74 files changed

+246
-242
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+246
-242
lines changed

test/parallel/test-aborted-util.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ test('Aborted with gc cleanup', async () => {
3232
const { promise, resolve } = Promise.withResolvers();
3333

3434
setImmediate(() => {
35-
global.gc();
35+
globalThis.gc();
3636
ac.abort();
3737
strictEqual(ac.signal.aborted, true);
3838
strictEqual(getEventListeners(ac.signal, 'abort').length, 0);

test/parallel/test-abortsignal-drop-settled-signals.mjs

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function makeSubsequentCalls(limit, done, holdReferences = false) {
1616
// This setImmediate is necessary to ensure that in the last iteration the remaining signal is GCed (if not
1717
// retained)
1818
setImmediate(() => {
19-
global.gc();
19+
globalThis.gc();
2020
done(ac.signal, dependantSymbol);
2121
});
2222
return;
@@ -50,7 +50,7 @@ function runShortLivedSourceSignal(limit, done) {
5050

5151
function run(iteration) {
5252
if (iteration > limit) {
53-
global.gc();
53+
globalThis.gc();
5454
done(signalRefs);
5555
return;
5656
}
@@ -74,9 +74,9 @@ function runWithOrphanListeners(limit, done) {
7474
const ac = new AbortController();
7575
if (iteration > limit) {
7676
setImmediate(() => {
77-
global.gc();
77+
globalThis.gc();
7878
setImmediate(() => {
79-
global.gc();
79+
globalThis.gc();
8080

8181
done(composedSignalRefs);
8282
});
@@ -147,7 +147,7 @@ it('drops settled dependant signals when signal is composite', (t, done) => {
147147
t.assert.strictEqual(controllers[1].signal[kDependantSignals].size, 1);
148148

149149
setImmediate(() => {
150-
global.gc({ execution: 'async' }).then(async () => {
150+
globalThis.gc({ execution: 'async' }).then(async () => {
151151
await gcUntil('all signals are GCed', () => {
152152
const totalDependantSignals = Math.max(
153153
controllers[0].signal[kDependantSignals].size,

test/parallel/test-assert-checktag.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ test('', { skip: !hasCrypto }, () => {
4949

5050
{ // At the moment global has its own type tag
5151
const fakeGlobal = {};
52-
Object.setPrototypeOf(fakeGlobal, Object.getPrototypeOf(global));
53-
for (const prop of Object.keys(global)) {
52+
Object.setPrototypeOf(fakeGlobal, Object.getPrototypeOf(globalThis));
53+
for (const prop of Object.keys(globalThis)) {
5454
fakeGlobal[prop] = global[prop];
5555
}
56-
assert.notDeepEqual(fakeGlobal, global);
56+
assert.notDeepEqual(fakeGlobal, globalThis);
5757
// Message will be truncated anyway, don't validate
58-
assert.throws(() => assert.deepStrictEqual(fakeGlobal, global),
58+
assert.throws(() => assert.deepStrictEqual(fakeGlobal, globalThis),
5959
assert.AssertionError);
6060
}
6161

test/parallel/test-async-hooks-destroy-on-gc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ let asyncId = null;
2222
}
2323

2424
setImmediate(() => {
25-
global.gc();
25+
globalThis.gc();
2626
setImmediate(() => assert.ok(destroyedIds.has(asyncId)));
2727
});

test/parallel/test-async-hooks-disable-gc-tracking.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const hook = async_hooks.createHook({
1414
new async_hooks.AsyncResource('foobar', { requireManualDestroy: true });
1515

1616
setImmediate(() => {
17-
global.gc();
17+
globalThis.gc();
1818
setImmediate(() => {
1919
hook.disable();
2020
});

test/parallel/test-async-hooks-prevent-double-destroy.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const hook = async_hooks.createHook({
1717
}
1818

1919
setImmediate(() => {
20-
global.gc();
20+
globalThis.gc();
2121
setImmediate(() => {
2222
hook.disable();
2323
});

test/parallel/test-cli-eval.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ child.exec(
345345
// Regression test for https://github.com/nodejs/node/issues/45336
346346
child.execFile(process.execPath,
347347
['-p',
348-
'Object.defineProperty(global, "fs", { configurable: false });' +
348+
'Object.defineProperty(globalThis, "fs", { configurable: false });' +
349349
'fs === require("node:fs")'],
350350
common.mustSucceed((stdout) => {
351351
assert.match(stdout, /^true/);

test/parallel/test-common-gc.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ const { onGC } = require('../common/gc');
55

66
{
77
onGC({}, { ongc: common.mustCall() });
8-
global.gc();
8+
globalThis.gc();
99
}
1010

1111
{
1212
onGC(process, { ongc: common.mustNotCall() });
13-
global.gc();
13+
globalThis.gc();
1414
}
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
'use strict';
22

3-
// Patch global.console before importing modules that may modify the console
3+
// Patch globalThis.console before importing modules that may modify the console
44
// object.
55

6-
const tmp = global.console;
7-
global.console = 42;
6+
const tmp = globalThis.console;
7+
globalThis.console = 42;
88

99
require('../common');
1010
const assert = require('assert');
1111

1212
// Originally the console had a getter. Test twice to verify it had no side
1313
// effect.
14-
assert.strictEqual(global.console, 42);
15-
assert.strictEqual(global.console, 42);
14+
assert.strictEqual(globalThis.console, 42);
15+
assert.strictEqual(globalThis.console, 42);
1616

1717
assert.throws(
1818
() => console.log('foo'),
1919
{ name: 'TypeError' }
2020
);
2121

22-
global.console = 1;
23-
assert.strictEqual(global.console, 1);
22+
globalThis.console = 1;
23+
assert.strictEqual(globalThis.console, 1);
2424
assert.strictEqual(console, 1);
2525

2626
// Reset the console
27-
global.console = tmp;
27+
globalThis.console = tmp;
2828
console.log('foo');

test/parallel/test-console-instance.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ process.stdout.write = process.stderr.write = common.mustNotCall();
3636
// Make sure that the "Console" function exists.
3737
assert.strictEqual(typeof Console, 'function');
3838

39-
assert.strictEqual(requiredConsole, global.console);
39+
assert.strictEqual(requiredConsole, globalThis.console);
4040
// Make sure the custom instanceof of Console works
41-
assert.ok(global.console instanceof Console);
41+
assert.ok(globalThis.console instanceof Console);
4242
assert.ok(!({} instanceof Console));
4343

4444
// Make sure that the Console constructor throws

test/parallel/test-console-self-assign.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
require('../common');
44

55
// Assigning to itself should not throw.
6-
global.console = global.console; // eslint-disable-line no-self-assign
6+
globalThis.console = globalThis.console; // eslint-disable-line no-self-assign

test/parallel/test-crypto-dh-leak.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const before = process.memoryUsage.rss();
2222
dh.setPrivateKey(privateKey);
2323
}
2424
}
25-
global.gc();
25+
globalThis.gc();
2626
const after = process.memoryUsage.rss();
2727

2828
// RSS should stay the same, ceteris paribus, but allow for

test/parallel/test-domain-crypto.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const crypto = require('crypto');
3131
// Pollution of global is intentional as part of test.
3232
common.allowGlobals(require('domain'));
3333
// See https://github.com/nodejs/node/commit/d1eff9ab
34-
global.domain = require('domain');
34+
globalThis.domain = require('domain');
3535

3636
// Should not throw a 'TypeError: undefined is not a function' exception
3737
crypto.randomBytes(8);

test/parallel/test-eventtarget-memoryleakwarning.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ common.expectWarning({
103103
});
104104

105105
await setTimeout(0);
106-
global.gc();
106+
globalThis.gc();
107107
}
108108
})().then(common.mustCall(), common.mustNotCall());
109109
}

test/parallel/test-eventtarget.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ let asyncTest = Promise.resolve();
683683
const et = new EventTarget();
684684
et.addEventListener('foo', common.mustNotCall(), { [kWeakHandler]: {} });
685685
setImmediate(() => {
686-
global.gc();
686+
globalThis.gc();
687687
et.dispatchEvent(new Event('foo'));
688688
});
689689
}

test/parallel/test-finalization-registry-shutdown.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ process.on('exit', () => {
1919
// This is the final chance to execute JavaScript.
2020
register();
2121
// Queue a FinalizationRegistryCleanupTask by a testing gc request.
22-
global.gc();
22+
globalThis.gc();
2323
});

test/parallel/test-fs-filehandle.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ common.expectWarning({
3535
'DeprecationWarning': [[deprecationWarning, 'DEP0137']]
3636
});
3737

38-
global.gc();
38+
globalThis.gc();
3939

4040
setTimeout(() => {}, 10);

test/parallel/test-fs-promises-file-handle-close.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ doOpen().then(common.mustCall((fd) => {
3232
})).then(common.mustCall(() => {
3333
setImmediate(() => {
3434
// The FileHandle should be out-of-scope and no longer accessed now.
35-
global.gc();
35+
globalThis.gc();
3636

3737
// Wait an extra event loop turn, as the warning is emitted from the
3838
// native layer in an unref()'ed setImmediate() callback.

test/parallel/test-fs-write-reuse-callback.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let done = 0;
2020

2121
const ondone = common.mustSucceed(() => {
2222
if (++done < writes) {
23-
if (done % 25 === 0) global.gc();
23+
if (done % 25 === 0) globalThis.gc();
2424
setImmediate(write);
2525
} else {
2626
assert.strictEqual(

test/parallel/test-fs-write.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,18 @@ const {
3939
createExternalizableString,
4040
externalizeString,
4141
isOneByteString,
42-
} = global;
42+
} = globalThis;
43+
44+
assert.notStrictEqual(createExternalizableString, undefined);
45+
assert.notStrictEqual(externalizeString, undefined);
46+
assert.notStrictEqual(isOneByteString, undefined);
4347

4448
// Account for extra globals exposed by --expose_externalize_string.
4549
common.allowGlobals(
4650
createExternalizableString,
4751
externalizeString,
4852
isOneByteString,
49-
global.x,
53+
globalThis.x,
5054
);
5155

5256
{

test/parallel/test-gc-http-client-connaborted.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ setImmediate(status);
5353
function status() {
5454
if (done > 0) {
5555
createClients = false;
56-
global.gc();
56+
globalThis.gc();
5757
console.log(`done/collected/total: ${done}/${countGC}/${count}`);
5858
if (countGC === count) {
5959
server.close();

test/parallel/test-gc-net-timeout.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ setImmediate(status);
6464
function status() {
6565
if (done > 0) {
6666
createClients = false;
67-
global.gc();
67+
globalThis.gc();
6868
console.log(`done/collected/total: ${done}/${countGC}/${count}`);
6969
if (countGC === count) {
7070
server.close();

test/parallel/test-gc-tls-external-memory.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ connect();
2727

2828
function connect() {
2929
if (runs % 64 === 0)
30-
global.gc();
30+
globalThis.gc();
3131
const externalMemoryUsage = process.memoryUsage().external;
3232
assert(externalMemoryUsage >= 0, `${externalMemoryUsage} < 0`);
3333
if (runs++ === 512) {

test/parallel/test-global-setters.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ assert.strictEqual(process, _process);
88
// eslint-disable-next-line no-global-assign
99
process = 'asdf';
1010
assert.strictEqual(process, 'asdf');
11-
assert.strictEqual(global.process, 'asdf');
12-
global.process = _process;
11+
assert.strictEqual(globalThis.process, 'asdf');
12+
globalThis.process = _process;
1313
assert.strictEqual(process, _process);
1414
assert.strictEqual(
15-
typeof Object.getOwnPropertyDescriptor(global, 'process').get,
15+
typeof Object.getOwnPropertyDescriptor(globalThis, 'process').get,
1616
'function');
1717

1818
assert.strictEqual(Buffer, _Buffer);
1919
// eslint-disable-next-line no-global-assign
2020
Buffer = 'asdf';
2121
assert.strictEqual(Buffer, 'asdf');
22-
assert.strictEqual(global.Buffer, 'asdf');
23-
global.Buffer = _Buffer;
22+
assert.strictEqual(globalThis.Buffer, 'asdf');
23+
globalThis.Buffer = _Buffer;
2424
assert.strictEqual(Buffer, _Buffer);
2525
assert.strictEqual(
26-
typeof Object.getOwnPropertyDescriptor(global, 'Buffer').get,
26+
typeof Object.getOwnPropertyDescriptor(globalThis, 'Buffer').get,
2727
'function');

test/parallel/test-global.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ for (const moduleName of builtinModules) {
6060
'crypto',
6161
'navigator',
6262
];
63-
assert.deepStrictEqual(new Set(Object.keys(global)), new Set(expected));
63+
assert.deepStrictEqual(new Set(Object.keys(globalThis)), new Set(expected));
6464
expected.forEach((value) => {
65-
const desc = Object.getOwnPropertyDescriptor(global, value);
65+
const desc = Object.getOwnPropertyDescriptor(globalThis, value);
6666
if (typeof desc.value === 'function') {
6767
assert.strictEqual(desc.value.name, value);
6868
} else if (typeof desc.get === 'function') {
@@ -74,15 +74,15 @@ for (const moduleName of builtinModules) {
7474
common.allowGlobals('bar', 'foo');
7575

7676
baseFoo = 'foo'; // eslint-disable-line no-undef
77-
global.baseBar = 'bar';
77+
globalThis.baseBar = 'bar';
7878

79-
assert.strictEqual(global.baseFoo, 'foo',
80-
`x -> global.x failed: global.baseFoo = ${global.baseFoo}`);
79+
assert.strictEqual(globalThis.baseFoo, 'foo',
80+
`x -> globalThis.x failed: globalThis.baseFoo = ${globalThis.baseFoo}`);
8181

8282
assert.strictEqual(baseBar, // eslint-disable-line no-undef
8383
'bar',
8484
// eslint-disable-next-line no-undef
85-
`global.x -> x failed: baseBar = ${baseBar}`);
85+
`globalThis.x -> x failed: baseBar = ${baseBar}`);
8686

8787
const mod = require(fixtures.path('global', 'plain'));
8888
const fooBar = mod.fooBar;
@@ -91,4 +91,4 @@ assert.strictEqual(fooBar.foo, 'foo');
9191

9292
assert.strictEqual(fooBar.bar, 'bar');
9393

94-
assert.strictEqual(Object.prototype.toString.call(global), '[object global]');
94+
assert.strictEqual(Object.prototype.toString.call(globalThis), '[object global]');

test/parallel/test-h2leak-destroy-session-on-socket-ended.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ server.on('secureConnection', (s) => {
3131
firstServerStream = null;
3232

3333
setImmediate(() => {
34-
global.gc();
35-
global.gc();
34+
globalThis.gc();
35+
globalThis.gc();
3636

3737
server.close();
3838
});

test/parallel/test-heapdump-async-hooks-init-promise.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ async_hooks.createHook({
4343

4444

4545
Promise.resolve().then(() => {});
46-
setImmediate(global.gc);
46+
setImmediate(globalThis.gc);

test/parallel/test-http-agent-domain-reused-gc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async_hooks.createHook({
2626
},
2727
before(id) {
2828
if (id === reusedHandleId) {
29-
global.gc();
29+
globalThis.gc();
3030
checkBeforeCalled();
3131
}
3232
}

test/parallel/test-http-parser-bad-ref.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ let messagesComplete = 0;
1818

1919
function flushPool() {
2020
Buffer.allocUnsafe(Buffer.poolSize - 1);
21-
global.gc();
21+
globalThis.gc();
2222
}
2323

2424
function demoBug(part1, part2) {

test/parallel/test-http-server-connections-checking-leak.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ for (let i = 0; i < max; i++) {
2020
}
2121

2222
setImmediate(() => {
23-
global.gc();
23+
globalThis.gc();
2424
});

0 commit comments

Comments
 (0)