| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7d688d4 commit d756d2b
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 | |
|---|---|---|---|
@@ -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, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,6 +6,7 @@ const { | |||
| 6 | 6 | SafeMap, | |
| 7 | 7 | SafeWeakMap, | |
| 8 | 8 | StringPrototypeStartsWith, | |
| 9 | + globalThis, | ||
| 9 | 10 | } = primordials; | |
| 10 | 11 | ||
| 11 | 12 | const { | |
@@ -302,7 +303,7 @@ function initializeDeprecations() { | |||
| 302 | 303 | // deprecation path for these in ES Modules. | |
| 303 | 304 | // See https://github.com/nodejs/node/pull/26334. | |
| 304 | 305 | let _process = process; | |
| 305 | - ObjectDefineProperty(global, 'process', { | ||
| 306 | + ObjectDefineProperty(globalThis, 'process', { | ||
| 306 | 307 | get() { | |
| 307 | 308 | return _process; | |
| 308 | 309 | }, | |
@@ -314,7 +315,7 @@ function initializeDeprecations() { | |||
| 314 | 315 | }); | |
| 315 | 316 | ||
| 316 | 317 | let _Buffer = Buffer; | |
| 317 | - ObjectDefineProperty(global, 'Buffer', { | ||
| 318 | + ObjectDefineProperty(globalThis, 'Buffer', { | ||
| 318 | 319 | get() { | |
| 319 | 320 | return _Buffer; | |
| 320 | 321 | }, | |
| 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 | |
|---|---|---|---|
@@ -155,6 +155,7 @@ function copyPrototype(src, dest, prefix) { | |||
| 155 | 155 | 'Math', | |
| 156 | 156 | 'Reflect', | |
| 157 | 157 | ].forEach((name) => { | |
| 158 | + // eslint-disable-next-line no-restricted-globals | ||
| 158 | 159 | copyPropsRenamed(global[name], primordials, name); | |
| 159 | 160 | }); | |
| 160 | 161 | ||
@@ -198,6 +199,7 @@ function copyPrototype(src, dest, prefix) { | |||
| 198 | 199 | 'WeakRef', | |
| 199 | 200 | 'WeakSet', | |
| 200 | 201 | ].forEach((name) => { | |
| 202 | + // eslint-disable-next-line no-restricted-globals | ||
| 201 | 203 | const original = global[name]; | |
| 202 | 204 | primordials[name] = original; | |
| 203 | 205 | copyPropsRenamed(original, primordials, name); | |
@@ -210,6 +212,7 @@ function copyPrototype(src, dest, prefix) { | |||
| 210 | 212 | [ | |
| 211 | 213 | 'Promise', | |
| 212 | 214 | ].forEach((name) => { | |
| 215 | + // eslint-disable-next-line no-restricted-globals | ||
| 213 | 216 | const original = global[name]; | |
| 214 | 217 | primordials[name] = original; | |
| 215 | 218 | copyPropsRenamedBound(original, primordials, name); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -74,6 +74,7 @@ const { | |||
| 74 | 74 | TypedArrayPrototypeGetLength, | |
| 75 | 75 | TypedArrayPrototypeGetSymbolToStringTag, | |
| 76 | 76 | Uint8Array, | |
| 77 | + globalThis, | ||
| 77 | 78 | uncurryThis, | |
| 78 | 79 | } = primordials; | |
| 79 | 80 | ||
@@ -144,7 +145,7 @@ let hexSlice; | |||
| 144 | 145 | ||
| 145 | 146 | const builtInObjects = new SafeSet( | |
| 146 | 147 | ArrayPrototypeFilter( | |
| 147 | - ObjectGetOwnPropertyNames(global), | ||
| 148 | + ObjectGetOwnPropertyNames(globalThis), | ||
| 148 | 149 | (e) => RegExpPrototypeTest(/^[A-Z][a-zA-Z0-9]+$/, e) | |
| 149 | 150 | ) | |
| 150 | 151 | ); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -98,6 +98,7 @@ const { | |||
| 98 | 98 | Symbol, | |
| 99 | 99 | SyntaxError, | |
| 100 | 100 | SyntaxErrorPrototype, | |
| 101 | + globalThis, | ||
| 101 | 102 | } = primordials; | |
| 102 | 103 | ||
| 103 | 104 | const { | |
@@ -1009,7 +1010,7 @@ REPLServer.prototype.close = function close() { | |||
| 1009 | 1010 | REPLServer.prototype.createContext = function() { | |
| 1010 | 1011 | let context; | |
| 1011 | 1012 | if (this.useGlobal) { | |
| 1012 | - context = global; | ||
| 1013 | + context = globalThis; | ||
| 1013 | 1014 | } else { | |
| 1014 | 1015 | sendInspectorCommand((session) => { | |
| 1015 | 1016 | session.post('Runtime.enable'); | |
@@ -1021,11 +1022,11 @@ REPLServer.prototype.createContext = function() { | |||
| 1021 | 1022 | }, () => { | |
| 1022 | 1023 | context = vm.createContext(); | |
| 1023 | 1024 | }); | |
| 1024 | - ArrayPrototypeForEach(ObjectGetOwnPropertyNames(global), (name) => { | ||
| 1025 | + ArrayPrototypeForEach(ObjectGetOwnPropertyNames(globalThis), (name) => { | ||
| 1025 | 1026 | // Only set properties that do not already exist as a global builtin. | |
| 1026 | 1027 | if (!globalBuiltins.has(name)) { | |
| 1027 | 1028 | ObjectDefineProperty(context, name, | |
| 1028 | - ObjectGetOwnPropertyDescriptor(global, name)); | ||
| 1029 | + ObjectGetOwnPropertyDescriptor(globalThis, name)); | ||
| 1029 | 1030 | } | |
| 1030 | 1031 | }); | |
| 1031 | 1032 | context.global = context; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments