@@ -37,11 +37,6 @@ 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' ) ;
44
-
45
40
// Some tests assume a umask of 0o022 so set that up front. Tests that need a
46
41
// different umask will set it themselves.
47
42
//
@@ -257,61 +252,16 @@ function platformTimeout(ms) {
257
252
return ms ; // ARMv8+
258
253
}
259
254
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 ( fetch ) ;
305
- }
306
- if ( hasCrypto && global . crypto ) {
307
- knownGlobals . push ( global . crypto ) ;
308
- knownGlobals . push ( global . Crypto ) ;
309
- knownGlobals . push ( global . CryptoKey ) ;
310
- knownGlobals . push ( global . SubtleCrypto ) ;
255
+ let knownGlobals ;
256
+ try {
257
+ knownGlobals = require ( './knownGlobals.json' ) ;
258
+ } catch ( err ) {
259
+ console . info ( 'You may need to run `make test/common/knownGlobals.json`.' ) ;
260
+ throw err ;
311
261
}
312
262
313
263
function allowGlobals ( ...allowlist ) {
314
- knownGlobals = knownGlobals . concat ( allowlist ) ;
264
+ knownGlobals . push ( ... allowlist ) ;
315
265
}
316
266
317
267
if ( process . env . NODE_TEST_KNOWN_GLOBALS !== '0' ) {
@@ -323,9 +273,10 @@ if (process.env.NODE_TEST_KNOWN_GLOBALS !== '0') {
323
273
function leakedGlobals ( ) {
324
274
const leaked = [ ] ;
325
275
326
- for ( const val in global ) {
327
- if ( ! knownGlobals . includes ( global [ val ] ) ) {
328
- leaked . push ( val ) ;
276
+ const globals = Object . getOwnPropertyDescriptors ( global ) ;
277
+ for ( const val in globals ) {
278
+ if ( globals [ val ] . configurable && ! knownGlobals . includes ( val ) && ! knownGlobals . includes ( global [ val ] ) ) {
279
+ leaked . push ( val . toString ( ) ) ;
329
280
}
330
281
}
331
282
@@ -335,7 +286,7 @@ if (process.env.NODE_TEST_KNOWN_GLOBALS !== '0') {
335
286
process . on ( 'exit' , function ( ) {
336
287
const leaked = leakedGlobals ( ) ;
337
288
if ( leaked . length > 0 ) {
338
- assert . fail ( `Unexpected global(s) found: ${ leaked . join ( ', ' ) } ` ) ;
289
+ assert . fail ( `Unexpected global(s) found: ${ leaked . join ( ', ' ) } . Add it to lib/.eslint.yaml or call common.allowGlobals(). ` ) ;
339
290
}
340
291
} ) ;
341
292
}
0 commit comments