diff --git a/lib/.eslintrc.yaml b/lib/.eslintrc.yaml index 0f34afff0814a6..20e01898695507 100644 --- a/lib/.eslintrc.yaml +++ b/lib/.eslintrc.yaml @@ -11,6 +11,8 @@ rules: - error - name: Array message: "Use `const { Array } = primordials;` instead of the global." + - name: ArrayBuffer + message: "Use `const { ArrayBuffer } = primordials;` instead of the global." - name: BigInt message: "Use `const { BigInt } = primordials;` instead of the global." - name: BigInt64Array @@ -21,6 +23,8 @@ rules: message: "Use `const { Boolean } = primordials;` instead of the global." - name: Error message: "Use `const { Error } = primordials;` instead of the global." + - name: EvalError + message: "Use `const { EvalError } = primordials;` instead of the global." - name: Float32Array message: "Use `const { Float32Array } = primordials;` instead of the global." - name: Float64Array @@ -43,6 +47,10 @@ rules: message: "Use `const { Object } = primordials;` instead of the global." - name: Promise message: "Use `const { Promise } = primordials;` instead of the global." + - name: RangeError + message: "Use `const { RangeError } = primordials;` instead of the global." + - name: ReferenceError + message: "Use `const { ReferenceError } = primordials;` instead of the global." - name: Reflect message: "Use `const { Reflect } = primordials;` instead of the global." - name: RegExp @@ -53,12 +61,28 @@ rules: message: "Use `const { String } = primordials;` instead of the global." - name: Symbol message: "Use `const { Symbol } = primordials;` instead of the global." + - name: SyntaxError + message: "Use `const { SyntaxError } = primordials;` instead of the global." + - name: TypeError + message: "Use `const { TypeError } = primordials;` instead of the global." + - name: URIError + message: "Use `const { URIError } = primordials;` instead of the global." - name: Uint16Array message: "Use `const { Uint16Array } = primordials;` instead of the global." + - name: Uint32Array + message: "Use `const { Uint32Array } = primordials;` instead of the global." + - name: Uint8Array + message: "Use `const { Uint8Array } = primordials;` instead of the global." + - name: Uint8ClampedArray + message: "Use `const { Uint8ClampedArray } = primordials;` instead of the global." - name: WeakMap message: "Use `const { WeakMap } = primordials;` instead of the global." - name: WeakSet message: "Use `const { WeakSet } = primordials;` instead of the global." + - name: parseFloat + message: "Use `const { NumberParseFloat } = primordials;` instead of the global." + - name: parseInt + message: "Use `const { NumberParseInt } = primordials;` instead of the global." no-restricted-syntax: # Config copied from .eslintrc.js - error diff --git a/lib/buffer.js b/lib/buffer.js index a921d491647258..0daf5636edad46 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -39,6 +39,7 @@ const { ObjectSetPrototypeOf, SymbolSpecies, SymbolToPrimitive, + Uint8Array, Uint8ArrayPrototype, } = primordials; @@ -387,7 +388,7 @@ function SlowBuffer(length) { return createUnsafeBuffer(length); } -ObjectSetPrototypeOf(SlowBuffer.prototype, Uint8Array.prototype); +ObjectSetPrototypeOf(SlowBuffer.prototype, Uint8ArrayPrototype); ObjectSetPrototypeOf(SlowBuffer, Uint8Array); function allocate(size) { diff --git a/lib/internal/bootstrap/loaders.js b/lib/internal/bootstrap/loaders.js index 127ef67c36eb64..d5715aa9f8c666 100644 --- a/lib/internal/bootstrap/loaders.js +++ b/lib/internal/bootstrap/loaders.js @@ -53,6 +53,7 @@ const { ReflectGet, SafeSet, String, + TypeError, } = primordials; // Set up process.moduleLoadList. diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js index dd806022cada39..005b1b46c28227 100644 --- a/lib/internal/bootstrap/pre_execution.js +++ b/lib/internal/bootstrap/pre_execution.js @@ -2,6 +2,7 @@ const { Map, + NumberParseInt, ObjectDefineProperty, SafeWeakMap, } = primordials; @@ -327,7 +328,7 @@ function setupChildProcessIpcChannel() { if (process.env.NODE_CHANNEL_FD) { const assert = require('internal/assert'); - const fd = parseInt(process.env.NODE_CHANNEL_FD, 10); + const fd = NumberParseInt(process.env.NODE_CHANNEL_FD, 10); assert(fd >= 0); // Make sure it's not accidentally inherited by child processes. diff --git a/lib/internal/buffer.js b/lib/internal/buffer.js index 5b2a4a508d14e5..e23896eac93fba 100644 --- a/lib/internal/buffer.js +++ b/lib/internal/buffer.js @@ -6,6 +6,7 @@ const { Float64Array, MathFloor, Number, + Uint8Array, } = primordials; const { diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index 31d9f02df36fce..092922f956a17c 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -5,6 +5,7 @@ const { ObjectDefineProperty, ObjectSetPrototypeOf, Symbol, + Uint8Array, } = primordials; const { diff --git a/lib/internal/dns/utils.js b/lib/internal/dns/utils.js index 9948330adcda82..cee582e7fa57e9 100644 --- a/lib/internal/dns/utils.js +++ b/lib/internal/dns/utils.js @@ -2,6 +2,9 @@ const { ArrayIsArray, + ArrayPrototypePush, + NumberParseInt, + StringPrototypeReplace, } = primordials; const errors = require('internal/errors'); @@ -78,9 +81,9 @@ class Resolver { ipVersion = isIP(match[1]); if (ipVersion !== 0) { - const port = - parseInt(serv.replace(addrSplitRE, '$2')) || IANA_DNS_PORT; - return newSet.push([ipVersion, match[1], port]); + const port = NumberParseInt( + StringPrototypeReplace(serv, addrSplitRE, '$2')) || IANA_DNS_PORT; + return ArrayPrototypePush(newSet, [ipVersion, match[1], port]); } } @@ -94,7 +97,8 @@ class Resolver { ipVersion = isIP(hostIP); if (ipVersion !== 0) { - return newSet.push([ipVersion, hostIP, parseInt(port)]); + return ArrayPrototypePush( + newSet, [ipVersion, hostIP, NumberParseInt(port)]); } } diff --git a/lib/internal/encoding.js b/lib/internal/encoding.js index de0a1b7cc799bb..5226bf518dac38 100644 --- a/lib/internal/encoding.js +++ b/lib/internal/encoding.js @@ -10,6 +10,8 @@ const { ObjectGetOwnPropertyDescriptors, Symbol, SymbolToStringTag, + Uint32Array, + Uint8Array, } = primordials; const { diff --git a/lib/internal/error_serdes.js b/lib/internal/error_serdes.js index 5e18448da7046c..47392752df6318 100644 --- a/lib/internal/error_serdes.js +++ b/lib/internal/error_serdes.js @@ -4,6 +4,7 @@ const Buffer = require('buffer').Buffer; const { ArrayPrototypeForEach, Error, + EvalError, FunctionPrototypeCall, ObjectAssign, ObjectCreate, @@ -13,8 +14,13 @@ const { ObjectGetPrototypeOf, ObjectKeys, ObjectPrototypeToString, + RangeError, + ReferenceError, SafeSet, SymbolToStringTag, + SyntaxError, + TypeError, + URIError, } = primordials; const kSerializedError = 0; diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 314c06c7b78f03..373bf11858ae07 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -21,10 +21,14 @@ const { NumberIsInteger, ObjectDefineProperty, ObjectKeys, + RangeError, String, StringPrototypeStartsWith, Symbol, SymbolFor, + SyntaxError, + TypeError, + URIError, WeakMap, } = primordials; @@ -81,7 +85,7 @@ const maybeOverridePrepareStackTrace = (globalThis, error, trace) => { // https://crbug.com/v8/7848 // `globalThis` is the global that contains the constructor which // created `error`. - if (typeof globalThis.Error.prepareStackTrace === 'function') { + if (typeof globalThis.Error?.prepareStackTrace === 'function') { return globalThis.Error.prepareStackTrace(error, trace); } // We still have legacy usage that depends on the main context's `Error` diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index b913b3b5bdefbe..ab961c059187af 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -16,6 +16,8 @@ const { ReflectGetPrototypeOf, Set, Symbol, + Uint32Array, + Uint8Array, } = primordials; const { diff --git a/lib/internal/per_context/domexception.js b/lib/internal/per_context/domexception.js index c6d6370c5547cd..06bb3fa3053cd5 100644 --- a/lib/internal/per_context/domexception.js +++ b/lib/internal/per_context/domexception.js @@ -7,6 +7,7 @@ const { SafeWeakMap, SafeMap, SymbolToStringTag, + TypeError, } = primordials; class ERR_INVALID_THIS extends TypeError { diff --git a/lib/internal/per_context/primordials.js b/lib/internal/per_context/primordials.js index 09bea0fc7fc523..8b1b8841c25379 100644 --- a/lib/internal/per_context/primordials.js +++ b/lib/internal/per_context/primordials.js @@ -125,6 +125,7 @@ primordials.SafePromise = makeSafe( 'Boolean', 'Date', 'Error', + 'EvalError', 'Float32Array', 'Float64Array', 'Function', @@ -134,10 +135,15 @@ primordials.SafePromise = makeSafe( 'Map', 'Number', 'Object', + 'RangeError', + 'ReferenceError', 'RegExp', 'Set', 'String', 'Symbol', + 'SyntaxError', + 'TypeError', + 'URIError', 'Uint16Array', 'Uint32Array', 'Uint8Array', diff --git a/lib/internal/process/per_thread.js b/lib/internal/process/per_thread.js index 1005d841a283f4..80bda3df9ace37 100644 --- a/lib/internal/process/per_thread.js +++ b/lib/internal/process/per_thread.js @@ -18,6 +18,7 @@ const { SetPrototype, SetPrototypeHas, StringPrototypeReplace, + Uint32Array, } = primordials; const { diff --git a/lib/internal/repl.js b/lib/internal/repl.js index 565ab049c71487..5eeb2e349031b2 100644 --- a/lib/internal/repl.js +++ b/lib/internal/repl.js @@ -3,6 +3,7 @@ const { Number, NumberIsNaN, + NumberParseInt, ObjectCreate, } = primordials; @@ -25,7 +26,7 @@ function createRepl(env, opts, cb) { ...opts }; - if (parseInt(env.NODE_NO_READLINE)) { + if (NumberParseInt(env.NODE_NO_READLINE)) { opts.terminal = false; } diff --git a/lib/internal/streams/buffer_list.js b/lib/internal/streams/buffer_list.js index fc8dd1b1f0fded..2551bee4473de4 100644 --- a/lib/internal/streams/buffer_list.js +++ b/lib/internal/streams/buffer_list.js @@ -2,6 +2,7 @@ const { SymbolIterator, + Uint8Array, } = primordials; const { Buffer } = require('buffer'); diff --git a/lib/internal/streams/readable.js b/lib/internal/streams/readable.js index b2a6ddfb29e9e6..275fef2c676361 100644 --- a/lib/internal/streams/readable.js +++ b/lib/internal/streams/readable.js @@ -24,6 +24,7 @@ const { NumberIsInteger, NumberIsNaN, + NumberParseInt, ObjectDefineProperties, ObjectKeys, ObjectSetPrototypeOf, @@ -388,7 +389,7 @@ Readable.prototype.read = function(n) { if (n === undefined) { n = NaN; } else if (!NumberIsInteger(n)) { - n = parseInt(n, 10); + n = NumberParseInt(n, 10); } const state = this._readableState; const nOrig = n; diff --git a/lib/internal/util/comparisons.js b/lib/internal/util/comparisons.js index 9d4cdf9f183f16..2c10f0c8929752 100644 --- a/lib/internal/util/comparisons.js +++ b/lib/internal/util/comparisons.js @@ -20,6 +20,7 @@ const { StringPrototypeValueOf, SymbolPrototypeValueOf, SymbolToStringTag, + Uint8Array, } = primordials; const { compare } = internalBinding('buffer'); diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index 2a9bb18fdf6009..c73ab5a037fd78 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -29,6 +29,8 @@ const { MathSqrt, Number, NumberIsNaN, + NumberParseFloat, + NumberParseInt, NumberPrototypeValueOf, Object, ObjectAssign, @@ -56,6 +58,10 @@ const { SymbolIterator, SymbolToStringTag, Uint16Array, + Uint32Array, + Uint8Array, + Uint8ArrayPrototype, + Uint8ClampedArray, uncurryThis, } = primordials; @@ -136,7 +142,7 @@ const mapSizeGetter = uncurryThis( ObjectGetOwnPropertyDescriptor(MapPrototype, 'size').get); const typedArraySizeGetter = uncurryThis( ObjectGetOwnPropertyDescriptor( - ObjectGetPrototypeOf(Uint8Array.prototype), 'length').get); + ObjectGetPrototypeOf(Uint8ArrayPrototype), 'length').get); let hexSlice; @@ -1950,7 +1956,8 @@ function formatWithOptionsInternal(inspectOptions, ...args) { } else if (typeof tempInteger === 'symbol') { tempStr = 'NaN'; } else { - tempStr = formatNumber(stylizeNoColor, parseInt(tempInteger)); + tempStr = formatNumber(stylizeNoColor, + NumberParseInt(tempInteger)); } break; case 102: // 'f' @@ -1958,7 +1965,8 @@ function formatWithOptionsInternal(inspectOptions, ...args) { if (typeof tempFloat === 'symbol') { tempStr = 'NaN'; } else { - tempStr = formatNumber(stylizeNoColor, parseFloat(tempFloat)); + tempStr = formatNumber(stylizeNoColor, + NumberParseFloat(tempFloat)); } break; case 99: // 'c' diff --git a/lib/internal/util/types.js b/lib/internal/util/types.js index 676f386a2458d4..4b9eeb469b2d19 100644 --- a/lib/internal/util/types.js +++ b/lib/internal/util/types.js @@ -5,10 +5,11 @@ const { ObjectGetOwnPropertyDescriptor, ObjectGetPrototypeOf, SymbolToStringTag, + Uint8ArrayPrototype, uncurryThis, } = primordials; -const TypedArrayPrototype = ObjectGetPrototypeOf(Uint8Array.prototype); +const TypedArrayPrototype = ObjectGetPrototypeOf(Uint8ArrayPrototype); const TypedArrayProto_toStringTag = uncurryThis( diff --git a/lib/internal/validators.js b/lib/internal/validators.js index 2ef7d653d98fba..2439342ae8a78b 100644 --- a/lib/internal/validators.js +++ b/lib/internal/validators.js @@ -5,6 +5,7 @@ const { NumberIsInteger, NumberMAX_SAFE_INTEGER, NumberMIN_SAFE_INTEGER, + NumberParseInt, String, } = primordials; @@ -65,7 +66,7 @@ function parseFileMode(value, name, def) { if (!octalReg.test(value)) { throw new ERR_INVALID_ARG_VALUE(name, value, modeDesc); } - return parseInt(value, 8); + return NumberParseInt(value, 8); } throw new ERR_INVALID_ARG_VALUE(name, value, modeDesc); diff --git a/lib/internal/vm/module.js b/lib/internal/vm/module.js index d9892d520e78fe..c10433a36f6dcb 100644 --- a/lib/internal/vm/module.js +++ b/lib/internal/vm/module.js @@ -9,6 +9,7 @@ const { ObjectSetPrototypeOf, SafePromise, Symbol, + TypeError, WeakMap, } = primordials; diff --git a/lib/internal/worker.js b/lib/internal/worker.js index c89c8cd4e27b08..e97cd7efea22df 100644 --- a/lib/internal/worker.js +++ b/lib/internal/worker.js @@ -14,6 +14,7 @@ const { String, Symbol, SymbolFor, + Uint32Array, } = primordials; const EventEmitter = require('events'); diff --git a/lib/net.js b/lib/net.js index a699df2c849a43..b149878f6574dc 100644 --- a/lib/net.js +++ b/lib/net.js @@ -27,6 +27,7 @@ const { Error, Number, NumberIsNaN, + NumberParseInt, ObjectDefineProperty, ObjectSetPrototypeOf, Symbol, @@ -1204,7 +1205,7 @@ function createServerHandle(address, port, addressType, fd, flags) { } else if (port === -1 && addressType === -1) { handle = new Pipe(PipeConstants.SERVER); if (isWindows) { - const instances = parseInt(process.env.NODE_PENDING_PIPE_INSTANCES); + const instances = NumberParseInt(process.env.NODE_PENDING_PIPE_INSTANCES); if (!NumberIsNaN(instances)) { handle.setPendingInstances(instances); } diff --git a/lib/os.js b/lib/os.js index dc0d08376f2da0..d03be051d09144 100644 --- a/lib/os.js +++ b/lib/os.js @@ -23,6 +23,7 @@ const { Float64Array, + NumberParseInt, ObjectDefineProperties, SymbolToPrimitive, } = primordials; @@ -179,7 +180,7 @@ function getCIDR(address, netmask, family) { const parts = netmask.split(split); for (var i = 0; i < parts.length; i++) { if (parts[i] !== '') { - const binary = parseInt(parts[i], range); + const binary = NumberParseInt(parts[i], range); const tmp = countBinaryOnes(binary); ones += tmp; if (hasZeros) { diff --git a/lib/repl.js b/lib/repl.js index f60a49b3f49d43..78c256d60b5559 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -46,6 +46,7 @@ const { Error, MathMax, NumberIsNaN, + NumberParseFloat, ObjectAssign, ObjectCreate, ObjectDefineProperty, @@ -58,8 +59,12 @@ const { PromiseRace, RegExp, Set, + StringPrototypeCharAt, StringPrototypeIncludes, + StringPrototypeMatch, Symbol, + SyntaxError, + SyntaxErrorPrototype, WeakSet, } = primordials; @@ -765,9 +770,10 @@ function REPLServer(prompt, // Check to see if a REPL keyword was used. If it returns true, // display next prompt and return. if (trimmedCmd) { - if (trimmedCmd.charAt(0) === '.' && trimmedCmd.charAt(1) !== '.' && - NumberIsNaN(parseFloat(trimmedCmd))) { - const matches = trimmedCmd.match(/^\.([^\s]+)\s*(.*)$/); + if (StringPrototypeCharAt(trimmedCmd, 0) === '.' && + StringPrototypeCharAt(trimmedCmd, 1) !== '.' && + NumberIsNaN(NumberParseFloat(trimmedCmd))) { + const matches = StringPrototypeMatch(trimmedCmd, /^\.([^\s]+)\s*(.*)$/); const keyword = matches && matches[1]; const rest = matches && matches[2]; if (_parseREPLKeyword.call(self, keyword, rest) === true) { @@ -1566,7 +1572,7 @@ function defineDefaultCommands(repl) { function Recoverable(err) { this.err = err; } -ObjectSetPrototypeOf(Recoverable.prototype, SyntaxError.prototype); +ObjectSetPrototypeOf(Recoverable.prototype, SyntaxErrorPrototype); ObjectSetPrototypeOf(Recoverable, SyntaxError); module.exports = { diff --git a/lib/zlib.js b/lib/zlib.js index 1b4d3773c7f00b..faa84401e9a04b 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -22,6 +22,7 @@ 'use strict'; const { + ArrayBuffer, Error, MathMax, NumberIsFinite, @@ -33,6 +34,7 @@ const { ObjectKeys, ObjectSetPrototypeOf, Symbol, + Uint32Array, } = primordials; const {