diff --git a/lib/.eslintrc.yaml b/lib/.eslintrc.yaml index f66e15e6d963e8..1b75d7e742e66d 100644 --- a/lib/.eslintrc.yaml +++ b/lib/.eslintrc.yaml @@ -9,6 +9,8 @@ rules: - groups: [[ "&&", "||" ]] no-restricted-globals: - error + - name: Array + message: "Use `const { Array } = primordials;` instead of the global." - name: JSON message: "Use `const { JSON } = primordials;` instead of the global." - name: Math diff --git a/lib/_http_client.js b/lib/_http_client.js index f6f1cb1160d84e..5233fda49e0145 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -22,6 +22,7 @@ 'use strict'; const { + ArrayIsArray, ObjectAssign, ObjectKeys, ObjectSetPrototypeOf, @@ -217,7 +218,7 @@ function ClientRequest(input, options, cb) { } } - const headersArray = Array.isArray(options.headers); + const headersArray = ArrayIsArray(options.headers); if (!headersArray) { if (options.headers) { const keys = ObjectKeys(options.headers); diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 466d634acb4193..e331d073b57067 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -22,6 +22,7 @@ 'use strict'; const { + ArrayIsArray, ObjectCreate, ObjectDefineProperty, ObjectKeys, @@ -359,7 +360,7 @@ function _storeHeader(firstLine, headers) { const entry = headers[key]; processHeader(this, state, entry[0], entry[1], false); } - } else if (Array.isArray(headers)) { + } else if (ArrayIsArray(headers)) { for (const entry of headers) { processHeader(this, state, entry[0], entry[1], true); } @@ -453,7 +454,7 @@ function _storeHeader(firstLine, headers) { function processHeader(self, state, key, value, validate) { if (validate) validateHeaderName(key); - if (Array.isArray(value)) { + if (ArrayIsArray(value)) { if (value.length < 2 || !isCookieField(key)) { for (var i = 0; i < value.length; i++) storeHeader(self, state, key, value[i], validate); @@ -695,7 +696,7 @@ function connectionCorkNT(conn) { OutgoingMessage.prototype.addTrailers = function addTrailers(headers) { this._trailer = ''; const keys = ObjectKeys(headers); - const isArray = Array.isArray(headers); + const isArray = ArrayIsArray(headers); var field, value; for (var i = 0, l = keys.length; i < l; i++) { var key = keys[i]; diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index 69f46f80a07eca..7c9a14f4392c1e 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -22,6 +22,7 @@ 'use strict'; const { + ArrayIsArray, ObjectDefineProperty, ObjectSetPrototypeOf, } = primordials; @@ -70,7 +71,7 @@ function prependListener(emitter, event, fn) { // the prependListener() method. The goal is to eventually remove this hack. if (!emitter._events || !emitter._events[event]) emitter.on(event, fn); - else if (Array.isArray(emitter._events[event])) + else if (ArrayIsArray(emitter._events[event])) emitter._events[event].unshift(fn); else emitter._events[event] = [fn, emitter._events[event]]; diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js index fe43e72d305a94..08c2ebbab4ceef 100644 --- a/lib/_stream_writable.js +++ b/lib/_stream_writable.js @@ -26,6 +26,7 @@ 'use strict'; const { + Array, ObjectDefineProperty, ObjectSetPrototypeOf, } = primordials; diff --git a/lib/_tls_common.js b/lib/_tls_common.js index 13ff850c994146..e4180a2f4dc7a3 100644 --- a/lib/_tls_common.js +++ b/lib/_tls_common.js @@ -22,6 +22,7 @@ 'use strict'; const { + ArrayIsArray, ObjectCreate, } = primordials; @@ -105,7 +106,7 @@ exports.createSecureContext = function createSecureContext(options) { // Add CA before the cert to be able to load cert's issuer in C++ code. const { ca } = options; if (ca) { - if (Array.isArray(ca)) { + if (ArrayIsArray(ca)) { for (i = 0; i < ca.length; ++i) { val = ca[i]; validateKeyOrCertOption('ca', val); @@ -121,7 +122,7 @@ exports.createSecureContext = function createSecureContext(options) { const { cert } = options; if (cert) { - if (Array.isArray(cert)) { + if (ArrayIsArray(cert)) { for (i = 0; i < cert.length; ++i) { val = cert[i]; validateKeyOrCertOption('cert', val); @@ -140,7 +141,7 @@ exports.createSecureContext = function createSecureContext(options) { const key = options.key; const passphrase = options.passphrase; if (key) { - if (Array.isArray(key)) { + if (ArrayIsArray(key)) { for (i = 0; i < key.length; ++i) { val = key[i]; // eslint-disable-next-line eqeqeq @@ -240,7 +241,7 @@ exports.createSecureContext = function createSecureContext(options) { } if (options.crl) { - if (Array.isArray(options.crl)) { + if (ArrayIsArray(options.crl)) { for (i = 0; i < options.crl.length; i++) { c.context.addCRL(options.crl[i]); } @@ -257,7 +258,7 @@ exports.createSecureContext = function createSecureContext(options) { if (!toBuf) toBuf = require('internal/crypto/util').toBuf; - if (Array.isArray(options.pfx)) { + if (ArrayIsArray(options.pfx)) { for (i = 0; i < options.pfx.length; i++) { const pfx = options.pfx[i]; const raw = pfx.buf ? pfx.buf : pfx; diff --git a/lib/buffer.js b/lib/buffer.js index 6c70cd61c8a947..ac8c134739f985 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -22,6 +22,8 @@ 'use strict'; const { + Array, + ArrayIsArray, MathFloor, MathMin, MathTrunc, @@ -483,7 +485,7 @@ function fromObject(obj) { return fromArrayLike(obj); } - if (obj.type === 'Buffer' && Array.isArray(obj.data)) { + if (obj.type === 'Buffer' && ArrayIsArray(obj.data)) { return fromArrayLike(obj.data); } } @@ -518,7 +520,7 @@ Buffer[kIsEncodingSymbol] = Buffer.isEncoding; Buffer.concat = function concat(list, length) { let i; - if (!Array.isArray(list)) { + if (!ArrayIsArray(list)) { throw new ERR_INVALID_ARG_TYPE('list', 'Array', list); } diff --git a/lib/child_process.js b/lib/child_process.js index ec7128f756030c..866eb5fae12429 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -22,6 +22,7 @@ 'use strict'; const { + ArrayIsArray, ObjectAssign, ObjectDefineProperty, ObjectPrototypeHasOwnProperty, @@ -63,7 +64,7 @@ function fork(modulePath /* , args, options */) { let options = {}; let args = []; let pos = 1; - if (pos < arguments.length && Array.isArray(arguments[pos])) { + if (pos < arguments.length && ArrayIsArray(arguments[pos])) { args = arguments[pos++]; } @@ -96,7 +97,7 @@ function fork(modulePath /* , args, options */) { if (typeof options.stdio === 'string') { options.stdio = stdioStringToArray(options.stdio, 'ipc'); - } else if (!Array.isArray(options.stdio)) { + } else if (!ArrayIsArray(options.stdio)) { // Use a separate fd=3 for the IPC channel. Inherit stdin, stdout, // and stderr from the parent if silent isn't set. options.stdio = stdioStringToArray( @@ -186,7 +187,7 @@ function execFile(file /* , args, options, callback */) { // Parse the optional positional parameters. let pos = 1; - if (pos < arguments.length && Array.isArray(arguments[pos])) { + if (pos < arguments.length && ArrayIsArray(arguments[pos])) { args = arguments[pos++]; } else if (pos < arguments.length && arguments[pos] == null) { pos++; @@ -404,7 +405,7 @@ function normalizeSpawnArguments(file, args, options) { if (file.length === 0) throw new ERR_INVALID_ARG_VALUE('file', file, 'cannot be empty'); - if (Array.isArray(args)) { + if (ArrayIsArray(args)) { args = args.slice(0); } else if (args == null) { args = []; diff --git a/lib/dgram.js b/lib/dgram.js index 64d57805c3728d..5f7e8f032cf998 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -22,6 +22,8 @@ 'use strict'; const { + Array, + ArrayIsArray, ObjectDefineProperty, ObjectSetPrototypeOf, } = primordials; @@ -592,7 +594,7 @@ Socket.prototype.send = function(buffer, throw new ERR_SOCKET_DGRAM_IS_CONNECTED(); } - if (!Array.isArray(buffer)) { + if (!ArrayIsArray(buffer)) { if (typeof buffer === 'string') { list = [ Buffer.from(buffer) ]; } else if (!isUint8Array(buffer)) { diff --git a/lib/domain.js b/lib/domain.js index 7c35a7c81ad6f6..322e7eb9586c35 100644 --- a/lib/domain.js +++ b/lib/domain.js @@ -27,6 +27,7 @@ // unless they address existing, critical bugs. const { + Array, ObjectDefineProperty, ReflectApply, } = primordials; diff --git a/lib/events.js b/lib/events.js index 8e16904cc8cbf4..f8c268ee1cd843 100644 --- a/lib/events.js +++ b/lib/events.js @@ -22,6 +22,7 @@ 'use strict'; const { + Array, MathMin, ObjectCreate, ObjectDefineProperty, diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index 05966f9e40906a..3836ee8e3d5ef5 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -1,6 +1,7 @@ 'use strict'; const { + ArrayIsArray, ObjectDefineProperty, ObjectSetPrototypeOf, } = primordials; @@ -357,7 +358,7 @@ ChildProcess.prototype.spawn = function(options) { // Let child process know about opened IPC channel if (options.envPairs === undefined) options.envPairs = []; - else if (!Array.isArray(options.envPairs)) { + else if (!ArrayIsArray(options.envPairs)) { throw new ERR_INVALID_ARG_TYPE('options.envPairs', 'Array', options.envPairs); @@ -370,7 +371,7 @@ ChildProcess.prototype.spawn = function(options) { validateString(options.file, 'options.file'); this.spawnfile = options.file; - if (Array.isArray(options.args)) + if (ArrayIsArray(options.args)) this.spawnargs = options.args; else if (options.args === undefined) this.spawnargs = []; @@ -613,7 +614,7 @@ function setupChannel(target, channel, serializationMode) { } } - assert(Array.isArray(target._handleQueue)); + assert(ArrayIsArray(target._handleQueue)); const queue = target._handleQueue; target._handleQueue = null; @@ -912,7 +913,7 @@ function getValidStdio(stdio, sync) { // Replace shortcut with an array if (typeof stdio === 'string') { stdio = stdioStringToArray(stdio); - } else if (!Array.isArray(stdio)) { + } else if (!ArrayIsArray(stdio)) { throw new ERR_INVALID_OPT_VALUE('stdio', inspect(stdio)); } diff --git a/lib/internal/console/constructor.js b/lib/internal/console/constructor.js index 43ae0eee41047f..0e96f16dfd3eb5 100644 --- a/lib/internal/console/constructor.js +++ b/lib/internal/console/constructor.js @@ -4,6 +4,8 @@ // console. It's exported for backwards compatibility. const { + ArrayFrom, + ArrayIsArray, MathFloor, ObjectDefineProperties, ObjectDefineProperty, @@ -44,11 +46,6 @@ const kSecond = 1000; const kMinute = 60 * kSecond; const kHour = 60 * kMinute; -const { - isArray: ArrayIsArray, - from: ArrayFrom, -} = Array; - // Lazy loaded for startup performance. let cliTable; diff --git a/lib/internal/dns/utils.js b/lib/internal/dns/utils.js index 226d134680a661..18ad6bfad7a192 100644 --- a/lib/internal/dns/utils.js +++ b/lib/internal/dns/utils.js @@ -1,4 +1,9 @@ 'use strict'; + +const { + ArrayIsArray, +} = primordials; + const errors = require('internal/errors'); const { isIP } = require('internal/net'); const { @@ -38,7 +43,7 @@ class Resolver { } setServers(servers) { - if (!Array.isArray(servers)) { + if (!ArrayIsArray(servers)) { throw new ERR_INVALID_ARG_TYPE('servers', 'Array', servers); } diff --git a/lib/internal/errors.js b/lib/internal/errors.js index a5155d936bd977..7dd976e299c079 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -11,6 +11,7 @@ // message may change, the code should not. const { + ArrayIsArray, MathAbs, ObjectDefineProperty, ObjectKeys, @@ -608,7 +609,7 @@ function isStackOverflowError(err) { function oneOf(expected, thing) { assert(typeof thing === 'string', '`thing` has to be of type string'); - if (Array.isArray(expected)) { + if (ArrayIsArray(expected)) { const len = expected.length; assert(len > 0, 'At least one expected value needs to be specified'); diff --git a/lib/internal/fixed_queue.js b/lib/internal/fixed_queue.js index a073ab7fc327af..d3ffbc2a1e154e 100644 --- a/lib/internal/fixed_queue.js +++ b/lib/internal/fixed_queue.js @@ -1,5 +1,9 @@ 'use strict'; +const { + Array, +} = primordials; + // Currently optimal queue size, tested on V8 6.0 - 6.6. Must be power of two. const kSize = 2048; const kMask = kSize - 1; diff --git a/lib/internal/fs/streams.js b/lib/internal/fs/streams.js index c8447191b5542a..6f274d841967ee 100644 --- a/lib/internal/fs/streams.js +++ b/lib/internal/fs/streams.js @@ -1,6 +1,7 @@ 'use strict'; const { + Array, MathMin, ObjectDefineProperty, ObjectSetPrototypeOf, diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js index 8ce9301836af7c..4d7f0d6765e799 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -1,6 +1,7 @@ 'use strict'; const { + ArrayIsArray, ObjectSetPrototypeOf, ReflectOwnKeys, } = primordials; @@ -541,7 +542,7 @@ const getValidatedPath = hideStackFrames((fileURLOrPath, propName = 'path') => { }); const validateBufferArray = hideStackFrames((buffers, propName = 'buffers') => { - if (!Array.isArray(buffers)) + if (!ArrayIsArray(buffers)) throw new ERR_INVALID_ARG_TYPE(propName, 'ArrayBufferView[]', buffers); for (let i = 0; i < buffers.length; i++) { diff --git a/lib/internal/http2/compat.js b/lib/internal/http2/compat.js index edd3d64ccf0092..b8d7dadb94fa92 100644 --- a/lib/internal/http2/compat.js +++ b/lib/internal/http2/compat.js @@ -1,6 +1,7 @@ 'use strict'; const { + ArrayIsArray, ObjectAssign, ObjectCreate, ObjectKeys, @@ -617,7 +618,7 @@ class Http2ServerResponse extends Stream { headers = statusMessage; let i; - if (Array.isArray(headers)) { + if (ArrayIsArray(headers)) { for (i = 0; i < headers.length; i++) { const header = headers[i]; this[kSetHeader](header[0], header[1]); diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 2f55365641de0f..c4d12f9205151c 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -3,6 +3,8 @@ /* eslint-disable no-use-before-define */ const { + ArrayFrom, + ArrayIsArray, MathMin, ObjectAssign, ObjectCreate, @@ -966,7 +968,7 @@ function setupHandle(socket, type, options) { this.settings(settings); if (type === NGHTTP2_SESSION_SERVER && - Array.isArray(options.origins)) { + ArrayIsArray(options.origins)) { this.origin(...options.origins); } @@ -1123,7 +1125,7 @@ class Http2Session extends EventEmitter { get originSet() { if (!this.encrypted || this.destroyed) return undefined; - return Array.from(initOriginSet(this)); + return ArrayFrom(initOriginSet(this)); } // True if the Http2Session is still waiting for the socket to connect diff --git a/lib/internal/http2/util.js b/lib/internal/http2/util.js index 482ae8546ae084..b43d6d421a4be0 100644 --- a/lib/internal/http2/util.js +++ b/lib/internal/http2/util.js @@ -1,6 +1,7 @@ 'use strict'; const { + ArrayIsArray, MathMax, ObjectCreate, ObjectKeys, @@ -449,7 +450,7 @@ function mapToHeaders(map, continue; key = key.toLowerCase(); isSingleValueHeader = kSingleValueHeaders.has(key); - isArray = Array.isArray(value); + isArray = ArrayIsArray(value); if (isArray) { switch (value.length) { case 0: @@ -513,7 +514,7 @@ const assertIsObject = hideStackFrames((value, name, types) => { if (value !== undefined && (value === null || typeof value !== 'object' || - Array.isArray(value))) { + ArrayIsArray(value))) { throw new ERR_INVALID_ARG_TYPE(name, types || 'Object', value); } }); diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index c9a12c9a43bf85..d962bc2a4cec30 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -22,6 +22,7 @@ 'use strict'; const { + ArrayIsArray, JSONParse, ObjectCreate, ObjectDefineProperty, @@ -461,7 +462,7 @@ function trySelf(paths, exts, isMain, trailingSlash, request) { function isConditionalDotExportSugar(exports, basePath) { if (typeof exports === 'string') return true; - if (Array.isArray(exports)) + if (ArrayIsArray(exports)) return true; if (typeof exports !== 'object') return false; @@ -569,9 +570,9 @@ function resolveExportsTarget(pkgPath, target, subpath, basePath, mappingKey) { } } } - } else if (Array.isArray(target)) { + } else if (ArrayIsArray(target)) { for (const targetValue of target) { - if (Array.isArray(targetValue)) continue; + if (ArrayIsArray(targetValue)) continue; try { return resolveExportsTarget(pkgPath, targetValue, subpath, basePath, mappingKey); @@ -910,7 +911,7 @@ Module._resolveFilename = function(request, parent, isMain, options) { let paths; if (typeof options === 'object' && options !== null) { - if (Array.isArray(options.paths)) { + if (ArrayIsArray(options.paths)) { const isRelative = request.startsWith('./') || request.startsWith('../') || ((isWindows && request.startsWith('.\\')) || @@ -1273,7 +1274,7 @@ Module._initPaths = function() { }; Module._preloadModules = function(requests) { - if (!Array.isArray(requests)) + if (!ArrayIsArray(requests)) return; // Preloaded modules have a dummy parent module which is deemed to exist diff --git a/lib/internal/per_context/primordials.js b/lib/internal/per_context/primordials.js index 6957019490c6bf..9e17b3541c78af 100644 --- a/lib/internal/per_context/primordials.js +++ b/lib/internal/per_context/primordials.js @@ -13,7 +13,6 @@ // by the native module compiler. const ReflectApply = Reflect.apply; -const ReflectConstruct = Reflect.construct; // This function is borrowed from the function with the same name on V8 Extras' // `utils` object. V8 implements Reflect.apply very efficiently in conjunction @@ -120,13 +119,7 @@ primordials.SafePromise = makeSafe( 'WeakSet', ].forEach((name) => { const original = global[name]; - primordials[name] = Object.setPrototypeOf({ - [name]: function(...args) { - return new.target ? - ReflectConstruct(original, args, new.target) : - ReflectApply(original, this, args); - } - }[name], null); + primordials[name] = original; copyPropsRenamed(original, primordials, name); copyPrototype(original.prototype, primordials, `${name}Prototype`); }); diff --git a/lib/internal/policy/manifest.js b/lib/internal/policy/manifest.js index d078ed092e22a7..02cf0743d728cd 100644 --- a/lib/internal/policy/manifest.js +++ b/lib/internal/policy/manifest.js @@ -1,6 +1,7 @@ 'use strict'; const { + ArrayIsArray, Map, MapPrototypeSet, ObjectEntries, @@ -137,7 +138,7 @@ class Manifest { if (dependencyMap === null || dependencyMap === undefined) { dependencyMap = {}; } - if (typeof dependencyMap === 'object' && !Array.isArray(dependencyMap)) { + if (typeof dependencyMap === 'object' && !ArrayIsArray(dependencyMap)) { /** * @returns {true | URL} */ diff --git a/lib/internal/priority_queue.js b/lib/internal/priority_queue.js index ec8bbaea412761..afd2cef643b9e5 100644 --- a/lib/internal/priority_queue.js +++ b/lib/internal/priority_queue.js @@ -1,5 +1,9 @@ 'use strict'; +const { + Array, +} = primordials; + const kCompare = Symbol('compare'); const kHeap = Symbol('heap'); const kSetPosition = Symbol('setPosition'); diff --git a/lib/internal/process/main_thread_only.js b/lib/internal/process/main_thread_only.js index a610395be99cbf..ab56500744ba0d 100644 --- a/lib/internal/process/main_thread_only.js +++ b/lib/internal/process/main_thread_only.js @@ -3,6 +3,10 @@ // This file contains process bootstrappers that can only be // run in the main thread +const { + ArrayIsArray, +} = primordials; + const { errnoException, codes: { @@ -74,7 +78,7 @@ function wrapPosixCredentialSetters(credentials) { } function setgroups(groups) { - if (!Array.isArray(groups)) { + if (!ArrayIsArray(groups)) { throw new ERR_INVALID_ARG_TYPE('groups', 'Array', groups); } for (let i = 0; i < groups.length; i++) { diff --git a/lib/internal/process/per_thread.js b/lib/internal/process/per_thread.js index 624601303a4460..7b1cd9eabeb498 100644 --- a/lib/internal/process/per_thread.js +++ b/lib/internal/process/per_thread.js @@ -5,6 +5,7 @@ // thread and the worker threads. const { + ArrayIsArray, ObjectDefineProperties, ObjectDefineProperty, ObjectFreeze, @@ -114,7 +115,7 @@ function wrapProcessMethods(binding) { _hrtime(hrValues); if (time !== undefined) { - if (!Array.isArray(time)) { + if (!ArrayIsArray(time)) { throw new ERR_INVALID_ARG_TYPE('time', 'Array', time); } if (time.length !== 2) { diff --git a/lib/internal/process/task_queues.js b/lib/internal/process/task_queues.js index 8ad9086a41964c..1abbfa78f80b6e 100644 --- a/lib/internal/process/task_queues.js +++ b/lib/internal/process/task_queues.js @@ -1,6 +1,7 @@ 'use strict'; const { + Array, FunctionPrototypeBind, } = primordials; diff --git a/lib/internal/process/warning.js b/lib/internal/process/warning.js index 67a553e21afb16..cf744cf0d591b1 100644 --- a/lib/internal/process/warning.js +++ b/lib/internal/process/warning.js @@ -1,5 +1,9 @@ 'use strict'; +const { + ArrayIsArray, +} = primordials; + const { ERR_INVALID_ARG_TYPE } = require('internal/errors').codes; // Lazily loaded @@ -84,7 +88,7 @@ function onWarning(warning) { // process.emitWarning(str[, options]) function emitWarning(warning, type, code, ctor, now) { let detail; - if (type !== null && typeof type === 'object' && !Array.isArray(type)) { + if (type !== null && typeof type === 'object' && !ArrayIsArray(type)) { ctor = type.ctor; code = type.code; if (typeof type.detail === 'string') diff --git a/lib/internal/querystring.js b/lib/internal/querystring.js index ecb4e072d83873..7df1c495c6e5c5 100644 --- a/lib/internal/querystring.js +++ b/lib/internal/querystring.js @@ -1,5 +1,9 @@ 'use strict'; +const { + Array, +} = primordials; + const { ERR_INVALID_URI } = require('internal/errors').codes; const hexTable = new Array(256); diff --git a/lib/internal/stream_base_commons.js b/lib/internal/stream_base_commons.js index 95430ff738fdb5..504de5fc57f9ab 100644 --- a/lib/internal/stream_base_commons.js +++ b/lib/internal/stream_base_commons.js @@ -1,5 +1,9 @@ 'use strict'; +const { + Array, +} = primordials; + const { Buffer } = require('buffer'); const { FastBuffer } = require('internal/buffer'); const { diff --git a/lib/internal/streams/pipeline.js b/lib/internal/streams/pipeline.js index 798745a110d51b..0c464605106630 100644 --- a/lib/internal/streams/pipeline.js +++ b/lib/internal/streams/pipeline.js @@ -3,6 +3,10 @@ 'use strict'; +const { + ArrayIsArray, +} = primordials; + let eos; const { once } = require('internal/util'); @@ -65,7 +69,7 @@ function popCallback(streams) { function pipeline(...streams) { const callback = popCallback(streams); - if (Array.isArray(streams[0])) streams = streams[0]; + if (ArrayIsArray(streams[0])) streams = streams[0]; if (streams.length < 2) { throw new ERR_MISSING_ARGS('streams'); diff --git a/lib/internal/tls.js b/lib/internal/tls.js index ee438016380fbd..d7370ad52c0f8e 100644 --- a/lib/internal/tls.js +++ b/lib/internal/tls.js @@ -1,6 +1,7 @@ 'use strict'; const { + ArrayIsArray, ObjectCreate, } = primordials; @@ -15,7 +16,7 @@ function parseCertString(s) { const key = parts[i].slice(0, sepIndex); const value = parts[i].slice(sepIndex + 1); if (key in out) { - if (!Array.isArray(out[key])) { + if (!ArrayIsArray(out[key])) { out[key] = [out[key]]; } out[key].push(value); diff --git a/lib/internal/url.js b/lib/internal/url.js index b4c047be529515..a30bcf5b9855e6 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -1,6 +1,7 @@ 'use strict'; const { + Array, ObjectCreate, ObjectDefineProperties, ObjectDefineProperty, diff --git a/lib/internal/util.js b/lib/internal/util.js index 30302c79a899a0..1ff25dbc7d2a86 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -1,6 +1,8 @@ 'use strict'; const { + ArrayFrom, + ArrayIsArray, ObjectCreate, ObjectDefineProperties, ObjectDefineProperty, @@ -184,7 +186,7 @@ function filterDuplicateStrings(items, low) { map.set(key, item); } } - return Array.from(map.values()).sort(); + return ArrayFrom(map.values()).sort(); } function cachedResult(fn) { @@ -361,7 +363,7 @@ function isInsideNodeModules() { // Iterate over all stack frames and look for the first one not coming // from inside Node.js itself: - if (Array.isArray(stack)) { + if (ArrayIsArray(stack)) { for (const frame of stack) { const filename = frame.getFileName(); // If a filename does not start with / or contain \, diff --git a/lib/internal/util/comparisons.js b/lib/internal/util/comparisons.js index 3af44f9bf53a51..b2784217171410 100644 --- a/lib/internal/util/comparisons.js +++ b/lib/internal/util/comparisons.js @@ -1,6 +1,7 @@ 'use strict'; const { + ArrayIsArray, BigIntPrototypeValueOf, BooleanPrototypeValueOf, DatePrototypeGetTime, @@ -163,7 +164,7 @@ function innerDeepEqual(val1, val2, strict, memos) { if (val1Tag !== val2Tag) { return false; } - if (Array.isArray(val1)) { + if (ArrayIsArray(val1)) { // Check for sparse arrays and general fast path if (val1.length !== val2.length) { return false; diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index 6484a3529786ed..7f7eb5d9749d10 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -1,6 +1,7 @@ 'use strict'; const { + Array, ArrayIsArray, BigIntPrototypeValueOf, BooleanPrototypeValueOf, diff --git a/lib/internal/vm/module.js b/lib/internal/vm/module.js index c97556ceb843d7..88a276e217a7fd 100644 --- a/lib/internal/vm/module.js +++ b/lib/internal/vm/module.js @@ -1,6 +1,7 @@ 'use strict'; const { + ArrayIsArray, ObjectCreate, ObjectDefineProperty, Symbol, @@ -350,7 +351,7 @@ class SourceTextModule extends Module { class SyntheticModule extends Module { constructor(exportNames, evaluateCallback, options = {}) { - if (!Array.isArray(exportNames) || + if (!ArrayIsArray(exportNames) || exportNames.some((e) => typeof e !== 'string')) { throw new ERR_INVALID_ARG_TYPE('exportNames', 'Array of strings', exportNames); diff --git a/lib/internal/worker.js b/lib/internal/worker.js index 699bf24346db91..621dfa77693168 100644 --- a/lib/internal/worker.js +++ b/lib/internal/worker.js @@ -3,6 +3,7 @@ /* global SharedArrayBuffer */ const { + ArrayIsArray, MathMax, ObjectCreate, ObjectEntries, @@ -79,7 +80,7 @@ class Worker extends EventEmitter { super(); debug(`[${threadId}] create new worker`, filename, options); validateString(filename, 'filename'); - if (options.execArgv && !Array.isArray(options.execArgv)) { + if (options.execArgv && !ArrayIsArray(options.execArgv)) { throw new ERR_INVALID_ARG_TYPE('options.execArgv', 'array', options.execArgv); diff --git a/lib/net.js b/lib/net.js index 749895444b237a..8fb5d2cd138ebb 100644 --- a/lib/net.js +++ b/lib/net.js @@ -22,6 +22,7 @@ 'use strict'; const { + ArrayIsArray, ObjectDefineProperty, ObjectSetPrototypeOf, } = primordials; @@ -809,7 +810,7 @@ protoGetter('bytesWritten', function bytesWritten() { bytes += Buffer.byteLength(el.chunk, el.encoding); }); - if (Array.isArray(data)) { + if (ArrayIsArray(data)) { // Was a writev, iterate over chunks to get total length for (let i = 0; i < data.length; i++) { const chunk = data[i]; @@ -920,7 +921,7 @@ Socket.prototype.connect = function(...args) { // already been normalized (so we don't normalize more than once). This has // been solved before in https://github.com/nodejs/node/pull/12342, but was // reverted as it had unintended side effects. - if (Array.isArray(args[0]) && args[0][normalizedArgsSymbol]) { + if (ArrayIsArray(args[0]) && args[0][normalizedArgsSymbol]) { normalized = args[0]; } else { normalized = normalizeArgs(args); diff --git a/lib/perf_hooks.js b/lib/perf_hooks.js index ac4fc405c53bea..32db324e6bc985 100644 --- a/lib/perf_hooks.js +++ b/lib/perf_hooks.js @@ -1,6 +1,7 @@ 'use strict'; const { + ArrayIsArray, ObjectDefineProperties, ObjectDefineProperty, ObjectKeys, @@ -335,7 +336,7 @@ class PerformanceObserver extends AsyncResource { if (typeof options !== 'object' || options === null) { throw new ERR_INVALID_ARG_TYPE('options', 'Object', options); } - if (!Array.isArray(options.entryTypes)) { + if (!ArrayIsArray(options.entryTypes)) { throw new ERR_INVALID_OPT_VALUE('entryTypes', options); } const entryTypes = options.entryTypes.filter(filterTypes).map(mapTypes); diff --git a/lib/querystring.js b/lib/querystring.js index 1573114e08194d..954b35d69e3fbd 100644 --- a/lib/querystring.js +++ b/lib/querystring.js @@ -24,6 +24,8 @@ 'use strict'; const { + Array, + ArrayIsArray, ObjectCreate, ObjectKeys, } = primordials; @@ -180,7 +182,7 @@ function stringify(obj, sep, eq, options) { let ks = encode(stringifyPrimitive(k)); ks += eq; - if (Array.isArray(v)) { + if (ArrayIsArray(v)) { const vlen = v.length; if (vlen === 0) continue; const vlast = vlen - 1; diff --git a/lib/repl.js b/lib/repl.js index 8519eeffd6c520..6f84cf7e69f1c3 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -43,6 +43,7 @@ 'use strict'; const { + ArrayIsArray, MathMax, ObjectAssign, ObjectCreate, @@ -1250,9 +1251,9 @@ function complete(line, callback) { completionGroupsLoaded(); } else { this.eval('.scope', this.context, 'repl', function ev(err, globals) { - if (err || !Array.isArray(globals)) { + if (err || !ArrayIsArray(globals)) { if (filter !== '') addCommonWords(completionGroups); - } else if (Array.isArray(globals[0])) { + } else if (ArrayIsArray(globals[0])) { // Add grouped globals for (let n = 0; n < globals.length; n++) completionGroups.push(globals[n]); diff --git a/lib/tls.js b/lib/tls.js index d1ed771f33b358..281de073c49574 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -22,6 +22,8 @@ 'use strict'; const { + Array, + ArrayIsArray, ObjectDefineProperty, ObjectFreeze, } = primordials; @@ -124,7 +126,7 @@ function convertProtocols(protocols) { exports.convertALPNProtocols = function convertALPNProtocols(protocols, out) { // If protocols is Array - translate it into buffer - if (Array.isArray(protocols)) { + if (ArrayIsArray(protocols)) { out.ALPNProtocols = convertProtocols(protocols); } else if (isArrayBufferView(protocols)) { // Copy new buffer not to be modified by user. @@ -270,7 +272,7 @@ exports.checkServerIdentity = function checkServerIdentity(hostname, cert) { // Match against Common Name only if no supported identifiers exist. const cn = subject.CN; - if (Array.isArray(cn)) + if (ArrayIsArray(cn)) valid = cn.some(wildcard); else if (cn) valid = wildcard(cn); diff --git a/lib/trace_events.js b/lib/trace_events.js index f142afded15d56..5ec50d32c63424 100644 --- a/lib/trace_events.js +++ b/lib/trace_events.js @@ -1,5 +1,9 @@ 'use strict'; +const { + ArrayIsArray, +} = primordials; + const { hasTracing } = internalBinding('config'); const kHandle = Symbol('handle'); const kEnabled = Symbol('enabled'); @@ -76,7 +80,7 @@ function createTracing(options) { if (typeof options !== 'object' || options === null) throw new ERR_INVALID_ARG_TYPE('options', 'object', options); - if (!Array.isArray(options.categories)) { + if (!ArrayIsArray(options.categories)) { throw new ERR_INVALID_ARG_TYPE('options.categories', 'string[]', options.categories); } diff --git a/lib/tty.js b/lib/tty.js index 3b431a1d881c99..95f2624708bc17 100644 --- a/lib/tty.js +++ b/lib/tty.js @@ -22,6 +22,7 @@ 'use strict'; const { + Array, ObjectSetPrototypeOf, } = primordials; diff --git a/lib/util.js b/lib/util.js index 438fa5f1020937..7329b8d715674c 100644 --- a/lib/util.js +++ b/lib/util.js @@ -22,6 +22,7 @@ 'use strict'; const { + ArrayIsArray, ObjectDefineProperties, ObjectDefineProperty, ObjectGetOwnPropertyDescriptors, @@ -243,7 +244,7 @@ module.exports = { getSystemErrorName, inherits, inspect, - isArray: Array.isArray, + isArray: ArrayIsArray, isBoolean, isBuffer, isDeepStrictEqual(a, b) { diff --git a/lib/v8.js b/lib/v8.js index 2156998d66d05b..1e0ee43f224c8f 100644 --- a/lib/v8.js +++ b/lib/v8.js @@ -15,6 +15,7 @@ 'use strict'; const { + Array, ObjectPrototypeToString, } = primordials;