@@ -37,10 +37,7 @@ const bits = ['arm64', 'mips', 'mipsel', 'ppc64', 'riscv64', 's390x', 'x64']
37
37
. includes ( process . arch ) ? 64 : 32 ;
38
38
const hasIntl = ! ! process . config . variables . v8_enable_i18n_support ;
39
39
40
- const {
41
- atob,
42
- btoa
43
- } = require ( 'buffer' ) ;
40
+ const parseEslintConfigForGlobals = require ( './parseEslintConfigForGlobals' ) ;
44
41
45
42
// Some tests assume a umask of 0o022 so set that up front. Tests that need a
46
43
// different umask will set it themselves.
@@ -257,67 +254,10 @@ function platformTimeout(ms) {
257
254
return ms ; // ARMv8+
258
255
}
259
256
260
- let knownGlobals = [
261
- atob ,
262
- btoa ,
263
- clearImmediate ,
264
- clearInterval ,
265
- clearTimeout ,
266
- global ,
267
- setImmediate ,
268
- setInterval ,
269
- setTimeout ,
270
- queueMicrotask ,
271
- ] ;
272
-
273
- // TODO(@jasnell): This check can be temporary. AbortController is
274
- // not currently supported in either Node.js 12 or 10, making it
275
- // difficult to run tests comparatively on those versions. Once
276
- // all supported versions have AbortController as a global, this
277
- // check can be removed and AbortController can be added to the
278
- // knownGlobals list above.
279
- if ( global . AbortController )
280
- knownGlobals . push ( global . AbortController ) ;
281
-
282
- if ( global . gc ) {
283
- knownGlobals . push ( global . gc ) ;
284
- }
285
-
286
- if ( global . performance ) {
287
- knownGlobals . push ( global . performance ) ;
288
- }
289
- if ( global . PerformanceMark ) {
290
- knownGlobals . push ( global . PerformanceMark ) ;
291
- }
292
- if ( global . PerformanceMeasure ) {
293
- knownGlobals . push ( global . PerformanceMeasure ) ;
294
- }
295
-
296
- // TODO(@ethan-arrowood): Similar to previous checks, this can be temporary
297
- // until v16.x is EOL. Once all supported versions have structuredClone we
298
- // can add this to the list above instead.
299
- if ( global . structuredClone ) {
300
- knownGlobals . push ( global . structuredClone ) ;
301
- }
302
-
303
- if ( global . fetch ) {
304
- knownGlobals . push (
305
- global . fetch ,
306
- global . FormData ,
307
- global . Request ,
308
- global . Response ,
309
- global . Headers ,
310
- ) ;
311
- }
312
- if ( hasCrypto && global . crypto ) {
313
- knownGlobals . push ( global . crypto ) ;
314
- knownGlobals . push ( global . Crypto ) ;
315
- knownGlobals . push ( global . CryptoKey ) ;
316
- knownGlobals . push ( global . SubtleCrypto ) ;
317
- }
257
+ const knownGlobals = parseEslintConfigForGlobals ( ) ;
318
258
319
259
function allowGlobals ( ...allowlist ) {
320
- knownGlobals = knownGlobals . concat ( allowlist ) ;
260
+ knownGlobals . push ( ... allowlist ) ;
321
261
}
322
262
323
263
if ( process . env . NODE_TEST_KNOWN_GLOBALS !== '0' ) {
@@ -329,9 +269,10 @@ if (process.env.NODE_TEST_KNOWN_GLOBALS !== '0') {
329
269
function leakedGlobals ( ) {
330
270
const leaked = [ ] ;
331
271
332
- for ( const val in global ) {
333
- if ( ! knownGlobals . includes ( global [ val ] ) ) {
334
- leaked . push ( val ) ;
272
+ const globals = Object . getOwnPropertyDescriptors ( global ) ;
273
+ for ( const val in globals ) {
274
+ if ( ! knownGlobals . includes ( global [ val ] ) && globals [ val ] . configurable ) {
275
+ leaked . push ( val . toString ( ) ) ;
335
276
}
336
277
}
337
278
@@ -341,7 +282,7 @@ if (process.env.NODE_TEST_KNOWN_GLOBALS !== '0') {
341
282
process . on ( 'exit' , function ( ) {
342
283
const leaked = leakedGlobals ( ) ;
343
284
if ( leaked . length > 0 ) {
344
- assert . fail ( `Unexpected global(s) found: ${ leaked . join ( ', ' ) } ` ) ;
285
+ assert . fail ( `Unexpected global(s) found: ${ leaked . join ( ', ' ) } . Add it to lib/.eslint.yaml or call common.allowGlobals(). ` ) ;
345
286
}
346
287
} ) ;
347
288
}
0 commit comments