| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ea9003a commit d4f96bb
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,6 +29,8 @@ rules: | |||
| 29 | 29 | - error | |
| 30 | 30 | - name: globalThis | |
| 31 | 31 | message: "Use `const { globalThis } = primordials;` instead of the global." | |
| 32 | + - name: global | ||
| 33 | + message: "Use `const { globalThis } = primordials;` instead of `global`." | ||
| 32 | 34 | # Custom rules in tools/eslint-rules | |
| 33 | 35 | node-core/lowercase-name-for-primitive: error | |
| 34 | 36 | node-core/non-ascii-character: error | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,6 +45,7 @@ const { | |||
| 45 | 45 | ObjectGetPrototypeOf, | |
| 46 | 46 | ObjectSetPrototypeOf, | |
| 47 | 47 | SymbolToStringTag, | |
| 48 | + globalThis, | ||
| 48 | 49 | } = primordials; | |
| 49 | 50 | const config = internalBinding('config'); | |
| 50 | 51 | const { deprecate } = require('internal/util'); | |
@@ -119,34 +120,35 @@ if (!config.noBrowserGlobals) { | |||
| 119 | 120 | // Override global console from the one provided by the VM | |
| 120 | 121 | // to the one implemented by Node.js | |
| 121 | 122 | // https://console.spec.whatwg.org/#console-namespace | |
| 122 | - exposeNamespace(global, 'console', createGlobalConsole(global.console)); | ||
| 123 | + exposeNamespace(globalThis, 'console', | ||
| 124 | + createGlobalConsole(globalThis.console)); | ||
| 123 | 125 | ||
| 124 | 126 | const { URL, URLSearchParams } = require('internal/url'); | |
| 125 | 127 | // https://url.spec.whatwg.org/#url | |
| 126 | - exposeInterface(global, 'URL', URL); | ||
| 128 | + exposeInterface(globalThis, 'URL', URL); | ||
| 127 | 129 | // https://url.spec.whatwg.org/#urlsearchparams | |
| 128 | - exposeInterface(global, 'URLSearchParams', URLSearchParams); | ||
| 130 | + exposeInterface(globalThis, 'URLSearchParams', URLSearchParams); | ||
| 129 | 131 | ||
| 130 | 132 | const { | |
| 131 | 133 | TextEncoder, TextDecoder | |
| 132 | 134 | } = require('internal/encoding'); | |
| 133 | 135 | // https://encoding.spec.whatwg.org/#textencoder | |
| 134 | - exposeInterface(global, 'TextEncoder', TextEncoder); | ||
| 136 | + exposeInterface(globalThis, 'TextEncoder', TextEncoder); | ||
| 135 | 137 | // https://encoding.spec.whatwg.org/#textdecoder | |
| 136 | - exposeInterface(global, 'TextDecoder', TextDecoder); | ||
| 138 | + exposeInterface(globalThis, 'TextDecoder', TextDecoder); | ||
| 137 | 139 | ||
| 138 | 140 | // https://html.spec.whatwg.org/multipage/webappapis.html#windoworworkerglobalscope | |
| 139 | 141 | const timers = require('timers'); | |
| 140 | - defineOperation(global, 'clearInterval', timers.clearInterval); | ||
| 141 | - defineOperation(global, 'clearTimeout', timers.clearTimeout); | ||
| 142 | - defineOperation(global, 'setInterval', timers.setInterval); | ||
| 143 | - defineOperation(global, 'setTimeout', timers.setTimeout); | ||
| 142 | + defineOperation(globalThis, 'clearInterval', timers.clearInterval); | ||
| 143 | + defineOperation(globalThis, 'clearTimeout', timers.clearTimeout); | ||
| 144 | + defineOperation(globalThis, 'setInterval', timers.setInterval); | ||
| 145 | + defineOperation(globalThis, 'setTimeout', timers.setTimeout); | ||
| 144 | 146 | ||
| 145 | - defineOperation(global, 'queueMicrotask', queueMicrotask); | ||
| 147 | + defineOperation(globalThis, 'queueMicrotask', queueMicrotask); | ||
| 146 | 148 | ||
| 147 | 149 | // Non-standard extensions: | |
| 148 | - defineOperation(global, 'clearImmediate', timers.clearImmediate); | ||
| 149 | - defineOperation(global, 'setImmediate', timers.setImmediate); | ||
| 150 | + defineOperation(globalThis, 'clearImmediate', timers.clearImmediate); | ||
| 151 | + defineOperation(globalThis, 'setImmediate', timers.setImmediate); | ||
| 150 | 152 | } | |
| 151 | 153 | ||
| 152 | 154 | // Set the per-Environment callback that will be called | |
@@ -280,7 +282,7 @@ function setupProcessObject() { | |||
| 280 | 282 | value: 'process' | |
| 281 | 283 | }); | |
| 282 | 284 | // Make process globally available to users by putting it on the global proxy | |
| 283 | - ObjectDefineProperty(global, 'process', { | ||
| 285 | + ObjectDefineProperty(globalThis, 'process', { | ||
| 284 | 286 | value: process, | |
| 285 | 287 | enumerable: false, | |
| 286 | 288 | writable: true, | |
@@ -289,7 +291,7 @@ function setupProcessObject() { | |||
| 289 | 291 | } | |
| 290 | 292 | ||
| 291 | 293 | function setupGlobalProxy() { | |
| 292 | - ObjectDefineProperty(global, SymbolToStringTag, { | ||
| 294 | + ObjectDefineProperty(globalThis, SymbolToStringTag, { | ||
| 293 | 295 | value: 'global', | |
| 294 | 296 | writable: false, | |
| 295 | 297 | enumerable: false, | |
@@ -306,7 +308,7 @@ function setupBuffer() { | |||
| 306 | 308 | delete bufferBinding.setBufferPrototype; | |
| 307 | 309 | delete bufferBinding.zeroFill; | |
| 308 | 310 | ||
| 309 | - ObjectDefineProperty(global, 'Buffer', { | ||
| 311 | + ObjectDefineProperty(globalThis, 'Buffer', { | ||
| 310 | 312 | value: Buffer, | |
| 311 | 313 | enumerable: false, | |
| 312 | 314 | writable: true, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,6 +7,7 @@ const { | |||
| 7 | 7 | SafeMap, | |
| 8 | 8 | SafeWeakMap, | |
| 9 | 9 | StringPrototypeStartsWith, | |
| 10 | + globalThis, | ||
| 10 | 11 | } = primordials; | |
| 11 | 12 | ||
| 12 | 13 | const { | |
@@ -290,7 +291,7 @@ function initializeDeprecations() { | |||
| 290 | 291 | // deprecation path for these in ES Modules. | |
| 291 | 292 | // See https://github.com/nodejs/node/pull/26334. | |
| 292 | 293 | let _process = process; | |
| 293 | - ObjectDefineProperty(global, 'process', { | ||
| 294 | + ObjectDefineProperty(globalThis, 'process', { | ||
| 294 | 295 | get() { | |
| 295 | 296 | return _process; | |
| 296 | 297 | }, | |
@@ -302,7 +303,7 @@ function initializeDeprecations() { | |||
| 302 | 303 | }); | |
| 303 | 304 | ||
| 304 | 305 | let _Buffer = Buffer; | |
| 305 | - ObjectDefineProperty(global, 'Buffer', { | ||
| 306 | + ObjectDefineProperty(globalThis, 'Buffer', { | ||
| 306 | 307 | get() { | |
| 307 | 308 | return _Buffer; | |
| 308 | 309 | }, | |
@@ -321,7 +322,7 @@ function initializeAbortController() { | |||
| 321 | 322 | AbortController, | |
| 322 | 323 | AbortSignal | |
| 323 | 324 | } = require('internal/abort_controller'); | |
| 324 | - ObjectDefineProperties(global, { | ||
| 325 | + ObjectDefineProperties(globalThis, { | ||
| 325 | 326 | AbortController: { | |
| 326 | 327 | writable: true, | |
| 327 | 328 | enumerable: false, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,10 @@ | |||
| 3 | 3 | // User passed `-e` or `--eval` arguments to Node without `-i` or | |
| 4 | 4 | // `--interactive`. | |
| 5 | 5 | ||
| 6 | + const { | ||
| 7 | + globalThis, | ||
| 8 | + } = primordials; | ||
| 9 | + | ||
| 6 | 10 | const { | |
| 7 | 11 | prepareMainThreadExecution | |
| 8 | 12 | } = require('internal/bootstrap/pre_execution'); | |
@@ -12,7 +16,7 @@ const { addBuiltinLibsToObject } = require('internal/modules/cjs/helpers'); | |||
| 12 | 16 | const { getOptionValue } = require('internal/options'); | |
| 13 | 17 | ||
| 14 | 18 | prepareMainThreadExecution(); | |
| 15 | - addBuiltinLibsToObject(global); | ||
| 19 | + addBuiltinLibsToObject(globalThis); | ||
| 16 | 20 | markBootstrapComplete(); | |
| 17 | 21 | ||
| 18 | 22 | const source = getOptionValue('--eval'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -195,6 +195,7 @@ primordials.SafeWeakSet = makeSafe( | |||
| 195 | 195 | 'Math', | |
| 196 | 196 | 'Reflect' | |
| 197 | 197 | ].forEach((name) => { | |
| 198 | + // eslint-disable-next-line no-restricted-globals | ||
| 198 | 199 | copyPropsRenamed(global[name], primordials, name); | |
| 199 | 200 | }); | |
| 200 | 201 | ||
@@ -235,6 +236,7 @@ primordials.SafeWeakSet = makeSafe( | |||
| 235 | 236 | 'WeakMap', | |
| 236 | 237 | 'WeakSet', | |
| 237 | 238 | ].forEach((name) => { | |
| 239 | + // eslint-disable-next-line no-restricted-globals | ||
| 238 | 240 | const original = global[name]; | |
| 239 | 241 | primordials[name] = original; | |
| 240 | 242 | copyPropsRenamed(original, primordials, name); | |
@@ -247,6 +249,7 @@ primordials.SafeWeakSet = makeSafe( | |||
| 247 | 249 | [ | |
| 248 | 250 | 'Promise', | |
| 249 | 251 | ].forEach((name) => { | |
| 252 | + // eslint-disable-next-line no-restricted-globals | ||
| 250 | 253 | const original = global[name]; | |
| 251 | 254 | primordials[name] = original; | |
| 252 | 255 | copyPropsRenamedBound(original, primordials, name); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,7 @@ | |||
| 3 | 3 | const { | |
| 4 | 4 | Array, | |
| 5 | 5 | ArrayIsArray, | |
| 6 | + ArrayPrototypeFilter, | ||
| 6 | 7 | BigIntPrototypeValueOf, | |
| 7 | 8 | BooleanPrototypeValueOf, | |
| 8 | 9 | DatePrototypeGetTime, | |
@@ -41,7 +42,9 @@ const { | |||
| 41 | 42 | ObjectSetPrototypeOf, | |
| 42 | 43 | ReflectApply, | |
| 43 | 44 | RegExp, | |
| 45 | + RegExpPrototypeExec, | ||
| 44 | 46 | RegExpPrototypeToString, | |
| 47 | + SafeSet, | ||
| 45 | 48 | SafeStringIterator, | |
| 46 | 49 | Set, | |
| 47 | 50 | SetPrototypeGetSize, | |
@@ -55,6 +58,7 @@ const { | |||
| 55 | 58 | TypedArrayPrototypeGetLength, | |
| 56 | 59 | TypedArrayPrototypeGetSymbolToStringTag, | |
| 57 | 60 | Uint8Array, | |
| 61 | + globalThis, | ||
| 58 | 62 | uncurryThis, | |
| 59 | 63 | } = primordials; | |
| 60 | 64 | ||
@@ -120,8 +124,11 @@ const { NativeModule } = require('internal/bootstrap/loaders'); | |||
| 120 | 124 | ||
| 121 | 125 | let hexSlice; | |
| 122 | 126 | ||
| 123 | - const builtInObjects = new Set( | ||
| 124 | - ObjectGetOwnPropertyNames(global).filter((e) => /^[A-Z][a-zA-Z0-9]+$/.test(e)) | ||
| 127 | + const builtInObjects = new SafeSet( | ||
| 128 | + ArrayPrototypeFilter( | ||
| 129 | + ObjectGetOwnPropertyNames(globalThis), | ||
| 130 | + (e) => RegExpPrototypeExec(/^[A-Z][a-zA-Z0-9]+$/, e) !== null | ||
| 131 | + ) | ||
| 125 | 132 | ); | |
| 126 | 133 | ||
| 127 | 134 | // https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -43,6 +43,7 @@ | |||
| 43 | 43 | 'use strict'; | |
| 44 | 44 | ||
| 45 | 45 | const { | |
| 46 | + ArrayPrototypeForEach, | ||
| 46 | 47 | Error, | |
| 47 | 48 | MathMax, | |
| 48 | 49 | NumberIsNaN, | |
@@ -67,6 +68,7 @@ const { | |||
| 67 | 68 | SyntaxError, | |
| 68 | 69 | SyntaxErrorPrototype, | |
| 69 | 70 | WeakSet, | |
| 71 | + globalThis, | ||
| 70 | 72 | } = primordials; | |
| 71 | 73 | ||
| 72 | 74 | const { | |
@@ -984,7 +986,7 @@ REPLServer.prototype.close = function close() { | |||
| 984 | 986 | REPLServer.prototype.createContext = function() { | |
| 985 | 987 | let context; | |
| 986 | 988 | if (this.useGlobal) { | |
| 987 | - context = global; | ||
| 989 | + context = globalThis; | ||
| 988 | 990 | } else { | |
| 989 | 991 | sendInspectorCommand((session) => { | |
| 990 | 992 | session.post('Runtime.enable'); | |
@@ -996,13 +998,13 @@ REPLServer.prototype.createContext = function() { | |||
| 996 | 998 | }, () => { | |
| 997 | 999 | context = vm.createContext(); | |
| 998 | 1000 | }); | |
| 999 | - for (const name of ObjectGetOwnPropertyNames(global)) { | ||
| 1001 | + ArrayPrototypeForEach(ObjectGetOwnPropertyNames(globalThis), (name) => { | ||
| 1000 | 1002 | // Only set properties that do not already exist as a global builtin. | |
| 1001 | 1003 | if (!globalBuiltins.has(name)) { | |
| 1002 | 1004 | ObjectDefineProperty(context, name, | |
| 1003 | - ObjectGetOwnPropertyDescriptor(global, name)); | ||
| 1005 | + ObjectGetOwnPropertyDescriptor(globalThis, name)); | ||
| 1004 | 1006 | } | |
| 1005 | - } | ||
| 1007 | + }); | ||
| 1006 | 1008 | context.global = context; | |
| 1007 | 1009 | const _console = new Console(this.output); | |
| 1008 | 1010 | ObjectDefineProperty(context, 'console', { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments