GeezerVison is showing github.com — lib: enforce use of Array from primordials · nodejs/node@79dd591
File treeExpand file treeCollapse file tree Open diff view settings Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/.eslintrc.yaml +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 9 | 9 | - groups: [[ "&&", "||" ]] | 10 | 10 | no-restricted-globals: | 11 | 11 | - error | | 12 | + - name: Array | | 13 | + message: "Use `const { Array } = primordials;` instead of the global." | 12 | 14 | - name: JSON | 13 | 15 | message: "Use `const { JSON } = primordials;` instead of the global." | 14 | 16 | - name: Math | |
Collapse file Copy file name to clipboardExpand all lines: lib/_http_client.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 22 | 22 | 'use strict'; | 23 | 23 |
| 24 | 24 | const { | | 25 | + ArrayIsArray, | 25 | 26 | ObjectAssign, | 26 | 27 | ObjectKeys, | 27 | 28 | ObjectSetPrototypeOf, | @@ -218,7 +219,7 @@ function ClientRequest(input, options, cb) { | 218 | 219 | } | 219 | 220 | } | 220 | 221 |
| 221 | | - const headersArray = Array.isArray(options.headers); | | 222 | + const headersArray = ArrayIsArray(options.headers); | 222 | 223 | if (!headersArray) { | 223 | 224 | if (options.headers) { | 224 | 225 | const keys = ObjectKeys(options.headers); | |
Collapse file Copy file name to clipboardExpand all lines: lib/_http_outgoing.js +4-3Lines changed: 4 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 22 | 22 | 'use strict'; | 23 | 23 |
| 24 | 24 | const { | | 25 | + ArrayIsArray, | 25 | 26 | ObjectCreate, | 26 | 27 | ObjectDefineProperty, | 27 | 28 | ObjectKeys, | @@ -350,7 +351,7 @@ function _storeHeader(firstLine, headers) { | 350 | 351 | const entry = headers[key]; | 351 | 352 | processHeader(this, state, entry[0], entry[1], false); | 352 | 353 | } | 353 | | - } else if (Array.isArray(headers)) { | | 354 | + } else if (ArrayIsArray(headers)) { | 354 | 355 | for (const entry of headers) { | 355 | 356 | processHeader(this, state, entry[0], entry[1], true); | 356 | 357 | } | @@ -444,7 +445,7 @@ function _storeHeader(firstLine, headers) { | 444 | 445 | function processHeader(self, state, key, value, validate) { | 445 | 446 | if (validate) | 446 | 447 | validateHeaderName(key); | 447 | | - if (Array.isArray(value)) { | | 448 | + if (ArrayIsArray(value)) { | 448 | 449 | if (value.length < 2 || !isCookieField(key)) { | 449 | 450 | for (var i = 0; i < value.length; i++) | 450 | 451 | storeHeader(self, state, key, value[i], validate); | @@ -686,7 +687,7 @@ function connectionCorkNT(conn) { | 686 | 687 | OutgoingMessage.prototype.addTrailers = function addTrailers(headers) { | 687 | 688 | this._trailer = ''; | 688 | 689 | const keys = ObjectKeys(headers); | 689 | | - const isArray = Array.isArray(headers); | | 690 | + const isArray = ArrayIsArray(headers); | 690 | 691 | var field, value; | 691 | 692 | for (var i = 0, l = keys.length; i < l; i++) { | 692 | 693 | var key = keys[i]; | |
Collapse file Copy file name to clipboardExpand all lines: lib/_stream_readable.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 22 | 22 | 'use strict'; | 23 | 23 |
| 24 | 24 | const { | | 25 | + ArrayIsArray, | 25 | 26 | ObjectDefineProperty, | 26 | 27 | ObjectSetPrototypeOf, | 27 | 28 | } = primordials; | @@ -70,7 +71,7 @@ function prependListener(emitter, event, fn) { | 70 | 71 | // the prependListener() method. The goal is to eventually remove this hack. | 71 | 72 | if (!emitter._events || !emitter._events[event]) | 72 | 73 | emitter.on(event, fn); | 73 | | - else if (Array.isArray(emitter._events[event])) | | 74 | + else if (ArrayIsArray(emitter._events[event])) | 74 | 75 | emitter._events[event].unshift(fn); | 75 | 76 | else | 76 | 77 | emitter._events[event] = [fn, emitter._events[event]]; | |
Collapse file Copy file name to clipboardExpand all lines: lib/_stream_writable.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 26 | 26 | 'use strict'; | 27 | 27 |
| 28 | 28 | const { | | 29 | + Array, | 29 | 30 | ObjectDefineProperty, | 30 | 31 | ObjectSetPrototypeOf, | 31 | 32 | } = primordials; | |
Collapse file Copy file name to clipboardExpand all lines: lib/_tls_common.js +6-5Lines changed: 6 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 22 | 22 | 'use strict'; | 23 | 23 |
| 24 | 24 | const { | | 25 | + ArrayIsArray, | 25 | 26 | ObjectCreate, | 26 | 27 | } = primordials; | 27 | 28 |
| @@ -105,7 +106,7 @@ exports.createSecureContext = function createSecureContext(options) { | 105 | 106 | // Add CA before the cert to be able to load cert's issuer in C++ code. | 106 | 107 | const { ca } = options; | 107 | 108 | if (ca) { | 108 | | - if (Array.isArray(ca)) { | | 109 | + if (ArrayIsArray(ca)) { | 109 | 110 | for (i = 0; i < ca.length; ++i) { | 110 | 111 | val = ca[i]; | 111 | 112 | validateKeyOrCertOption('ca', val); | @@ -121,7 +122,7 @@ exports.createSecureContext = function createSecureContext(options) { | 121 | 122 |
| 122 | 123 | const { cert } = options; | 123 | 124 | if (cert) { | 124 | | - if (Array.isArray(cert)) { | | 125 | + if (ArrayIsArray(cert)) { | 125 | 126 | for (i = 0; i < cert.length; ++i) { | 126 | 127 | val = cert[i]; | 127 | 128 | validateKeyOrCertOption('cert', val); | @@ -140,7 +141,7 @@ exports.createSecureContext = function createSecureContext(options) { | 140 | 141 | const key = options.key; | 141 | 142 | const passphrase = options.passphrase; | 142 | 143 | if (key) { | 143 | | - if (Array.isArray(key)) { | | 144 | + if (ArrayIsArray(key)) { | 144 | 145 | for (i = 0; i < key.length; ++i) { | 145 | 146 | val = key[i]; | 146 | 147 | // eslint-disable-next-line eqeqeq | @@ -240,7 +241,7 @@ exports.createSecureContext = function createSecureContext(options) { | 240 | 241 | } | 241 | 242 |
| 242 | 243 | if (options.crl) { | 243 | | - if (Array.isArray(options.crl)) { | | 244 | + if (ArrayIsArray(options.crl)) { | 244 | 245 | for (i = 0; i < options.crl.length; i++) { | 245 | 246 | c.context.addCRL(options.crl[i]); | 246 | 247 | } | @@ -257,7 +258,7 @@ exports.createSecureContext = function createSecureContext(options) { | 257 | 258 | if (!toBuf) | 258 | 259 | toBuf = require('internal/crypto/util').toBuf; | 259 | 260 |
| 260 | | - if (Array.isArray(options.pfx)) { | | 261 | + if (ArrayIsArray(options.pfx)) { | 261 | 262 | for (i = 0; i < options.pfx.length; i++) { | 262 | 263 | const pfx = options.pfx[i]; | 263 | 264 | const raw = pfx.buf ? pfx.buf : pfx; | |
Collapse file Copy file name to clipboardExpand all lines: lib/buffer.js +4-2Lines changed: 4 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 22 | 22 | 'use strict'; | 23 | 23 |
| 24 | 24 | const { | | 25 | + Array, | | 26 | + ArrayIsArray, | 25 | 27 | MathFloor, | 26 | 28 | MathMin, | 27 | 29 | MathTrunc, | @@ -483,7 +485,7 @@ function fromObject(obj) { | 483 | 485 | return fromArrayLike(obj); | 484 | 486 | } | 485 | 487 |
| 486 | | - if (obj.type === 'Buffer' && Array.isArray(obj.data)) { | | 488 | + if (obj.type === 'Buffer' && ArrayIsArray(obj.data)) { | 487 | 489 | return fromArrayLike(obj.data); | 488 | 490 | } | 489 | 491 | } | @@ -518,7 +520,7 @@ Buffer[kIsEncodingSymbol] = Buffer.isEncoding; | 518 | 520 |
| 519 | 521 | Buffer.concat = function concat(list, length) { | 520 | 522 | let i; | 521 | | - if (!Array.isArray(list)) { | | 523 | + if (!ArrayIsArray(list)) { | 522 | 524 | throw new ERR_INVALID_ARG_TYPE('list', 'Array', list); | 523 | 525 | } | 524 | 526 |
| |
Collapse file Copy file name to clipboardExpand all lines: lib/child_process.js +5-4Lines changed: 5 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 22 | 22 | 'use strict'; | 23 | 23 |
| 24 | 24 | const { | | 25 | + ArrayIsArray, | 25 | 26 | ObjectAssign, | 26 | 27 | ObjectDefineProperty, | 27 | 28 | ObjectPrototypeHasOwnProperty, | @@ -63,7 +64,7 @@ function fork(modulePath /* , args, options */) { | 63 | 64 | let options = {}; | 64 | 65 | let args = []; | 65 | 66 | let pos = 1; | 66 | | - if (pos < arguments.length && Array.isArray(arguments[pos])) { | | 67 | + if (pos < arguments.length && ArrayIsArray(arguments[pos])) { | 67 | 68 | args = arguments[pos++]; | 68 | 69 | } | 69 | 70 |
| @@ -96,7 +97,7 @@ function fork(modulePath /* , args, options */) { | 96 | 97 |
| 97 | 98 | if (typeof options.stdio === 'string') { | 98 | 99 | options.stdio = stdioStringToArray(options.stdio, 'ipc'); | 99 | | - } else if (!Array.isArray(options.stdio)) { | | 100 | + } else if (!ArrayIsArray(options.stdio)) { | 100 | 101 | // Use a separate fd=3 for the IPC channel. Inherit stdin, stdout, | 101 | 102 | // and stderr from the parent if silent isn't set. | 102 | 103 | options.stdio = stdioStringToArray( | @@ -186,7 +187,7 @@ function execFile(file /* , args, options, callback */) { | 186 | 187 |
| 187 | 188 | // Parse the optional positional parameters. | 188 | 189 | let pos = 1; | 189 | | - if (pos < arguments.length && Array.isArray(arguments[pos])) { | | 190 | + if (pos < arguments.length && ArrayIsArray(arguments[pos])) { | 190 | 191 | args = arguments[pos++]; | 191 | 192 | } else if (pos < arguments.length && arguments[pos] == null) { | 192 | 193 | pos++; | @@ -404,7 +405,7 @@ function normalizeSpawnArguments(file, args, options) { | 404 | 405 | if (file.length === 0) | 405 | 406 | throw new ERR_INVALID_ARG_VALUE('file', file, 'cannot be empty'); | 406 | 407 |
| 407 | | - if (Array.isArray(args)) { | | 408 | + if (ArrayIsArray(args)) { | 408 | 409 | args = args.slice(0); | 409 | 410 | } else if (args == null) { | 410 | 411 | args = []; | |
Collapse file Copy file name to clipboardExpand all lines: lib/dgram.js +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 22 | 22 | 'use strict'; | 23 | 23 |
| 24 | 24 | const { | | 25 | + Array, | | 26 | + ArrayIsArray, | 25 | 27 | ObjectDefineProperty, | 26 | 28 | ObjectSetPrototypeOf, | 27 | 29 | } = primordials; | @@ -592,7 +594,7 @@ Socket.prototype.send = function(buffer, | 592 | 594 | throw new ERR_SOCKET_DGRAM_IS_CONNECTED(); | 593 | 595 | } | 594 | 596 |
| 595 | | - if (!Array.isArray(buffer)) { | | 597 | + if (!ArrayIsArray(buffer)) { | 596 | 598 | if (typeof buffer === 'string') { | 597 | 599 | list = [ Buffer.from(buffer) ]; | 598 | 600 | } else if (!isUint8Array(buffer)) { | |
Collapse file Copy file name to clipboardExpand all lines: lib/domain.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 27 | 27 | // unless they address existing, critical bugs. | 28 | 28 |
| 29 | 29 | const { | | 30 | + Array, | 30 | 31 | ObjectDefineProperty, | 31 | 32 | ReflectApply, | 32 | 33 | } = primordials; | |
|