@@ -49,6 +49,7 @@ const {
49
49
ReflectGet,
50
50
ReflectSet,
51
51
SymbolToStringTag,
52
+ globalThis,
52
53
} = primordials ;
53
54
const config = internalBinding ( 'config' ) ;
54
55
const { deprecate } = require ( 'internal/util' ) ;
@@ -189,61 +190,62 @@ if (!config.noBrowserGlobals) {
189
190
// Override global console from the one provided by the VM
190
191
// to the one implemented by Node.js
191
192
// https://console.spec.whatwg.org/#console-namespace
192
- exposeNamespace ( global , 'console' , createGlobalConsole ( global . console ) ) ;
193
+ exposeNamespace ( globalThis , 'console' ,
194
+ createGlobalConsole ( globalThis . console ) ) ;
193
195
194
196
const { URL , URLSearchParams } = require ( 'internal/url' ) ;
195
197
// https://url.spec.whatwg.org/#url
196
- exposeInterface ( global , 'URL' , URL ) ;
198
+ exposeInterface ( globalThis , 'URL' , URL ) ;
197
199
// https://url.spec.whatwg.org/#urlsearchparams
198
- exposeInterface ( global , 'URLSearchParams' , URLSearchParams ) ;
200
+ exposeInterface ( globalThis , 'URLSearchParams' , URLSearchParams ) ;
199
201
200
202
const {
201
203
TextEncoder, TextDecoder
202
204
} = require ( 'internal/encoding' ) ;
203
205
// https://encoding.spec.whatwg.org/#textencoder
204
- exposeInterface ( global , 'TextEncoder' , TextEncoder ) ;
206
+ exposeInterface ( globalThis , 'TextEncoder' , TextEncoder ) ;
205
207
// https://encoding.spec.whatwg.org/#textdecoder
206
- exposeInterface ( global , 'TextDecoder' , TextDecoder ) ;
208
+ exposeInterface ( globalThis , 'TextDecoder' , TextDecoder ) ;
207
209
208
210
const {
209
211
AbortController,
210
212
AbortSignal,
211
213
} = require ( 'internal/abort_controller' ) ;
212
- exposeInterface ( global , 'AbortController' , AbortController ) ;
213
- exposeInterface ( global , 'AbortSignal' , AbortSignal ) ;
214
+ exposeInterface ( globalThis , 'AbortController' , AbortController ) ;
215
+ exposeInterface ( globalThis , 'AbortSignal' , AbortSignal ) ;
214
216
215
217
const {
216
218
EventTarget,
217
219
Event,
218
220
} = require ( 'internal/event_target' ) ;
219
- exposeInterface ( global , 'EventTarget' , EventTarget ) ;
220
- exposeInterface ( global , 'Event' , Event ) ;
221
+ exposeInterface ( globalThis , 'EventTarget' , EventTarget ) ;
222
+ exposeInterface ( globalThis , 'Event' , Event ) ;
221
223
const {
222
224
MessageChannel,
223
225
MessagePort,
224
226
MessageEvent,
225
227
} = require ( 'internal/worker/io' ) ;
226
- exposeInterface ( global , 'MessageChannel' , MessageChannel ) ;
227
- exposeInterface ( global , 'MessagePort' , MessagePort ) ;
228
- exposeInterface ( global , 'MessageEvent' , MessageEvent ) ;
228
+ exposeInterface ( globalThis , 'MessageChannel' , MessageChannel ) ;
229
+ exposeInterface ( globalThis , 'MessagePort' , MessagePort ) ;
230
+ exposeInterface ( globalThis , 'MessageEvent' , MessageEvent ) ;
229
231
230
232
// https://html.spec.whatwg.org/multipage/webappapis.html#windoworworkerglobalscope
231
233
const timers = require ( 'timers' ) ;
232
- defineOperation ( global , 'clearInterval' , timers . clearInterval ) ;
233
- defineOperation ( global , 'clearTimeout' , timers . clearTimeout ) ;
234
- defineOperation ( global , 'setInterval' , timers . setInterval ) ;
235
- defineOperation ( global , 'setTimeout' , timers . setTimeout ) ;
234
+ defineOperation ( globalThis , 'clearInterval' , timers . clearInterval ) ;
235
+ defineOperation ( globalThis , 'clearTimeout' , timers . clearTimeout ) ;
236
+ defineOperation ( globalThis , 'setInterval' , timers . setInterval ) ;
237
+ defineOperation ( globalThis , 'setTimeout' , timers . setTimeout ) ;
236
238
237
- defineOperation ( global , 'queueMicrotask' , queueMicrotask ) ;
239
+ defineOperation ( globalThis , 'queueMicrotask' , queueMicrotask ) ;
238
240
239
- defineLazyGlobal ( global , 'performance' , ( ) => {
241
+ defineLazyGlobal ( globalThis , 'performance' , ( ) => {
240
242
const { performance } = require ( 'perf_hooks' ) ;
241
243
return performance ;
242
244
} ) ;
243
245
244
246
// Non-standard extensions:
245
- defineOperation ( global , 'clearImmediate' , timers . clearImmediate ) ;
246
- defineOperation ( global , 'setImmediate' , timers . setImmediate ) ;
247
+ defineOperation ( globalThis , 'clearImmediate' , timers . clearImmediate ) ;
248
+ defineOperation ( globalThis , 'setImmediate' , timers . setImmediate ) ;
247
249
}
248
250
249
251
// Set the per-Environment callback that will be called
@@ -388,7 +390,7 @@ function setupProcessObject() {
388
390
value : 'process'
389
391
} ) ;
390
392
// Make process globally available to users by putting it on the global proxy
391
- ObjectDefineProperty ( global , 'process' , {
393
+ ObjectDefineProperty ( globalThis , 'process' , {
392
394
value : process ,
393
395
enumerable : false ,
394
396
writable : true ,
@@ -397,7 +399,7 @@ function setupProcessObject() {
397
399
}
398
400
399
401
function setupGlobalProxy ( ) {
400
- ObjectDefineProperty ( global , SymbolToStringTag , {
402
+ ObjectDefineProperty ( globalThis , SymbolToStringTag , {
401
403
value : 'global' ,
402
404
writable : false ,
403
405
enumerable : false ,
@@ -418,7 +420,7 @@ function setupBuffer() {
418
420
delete bufferBinding . setBufferPrototype ;
419
421
delete bufferBinding . zeroFill ;
420
422
421
- ObjectDefineProperties ( global , {
423
+ ObjectDefineProperties ( globalThis , {
422
424
'Buffer' : {
423
425
value : Buffer ,
424
426
enumerable : false ,
0 commit comments