From 353bece95c3ec72a57fe0d5b906706cf4733b444 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Wed, 31 Aug 2022 00:48:04 +0200 Subject: [PATCH] fixup! tools: add `ArrayPrototypeConcat` to the list of primordials to avoid --- lib/internal/bootstrap/node.js | 12 ++++++------ lib/internal/debugger/inspect.js | 7 +++---- lib/internal/main/print_help.js | 1 + lib/internal/modules/cjs/loader.js | 7 +++++-- lib/internal/modules/esm/resolve.js | 12 ++++++------ lib/internal/perf/observe.js | 5 ++++- lib/internal/test_runner/runner.js | 7 +++---- lib/internal/util/inspector.js | 9 ++++----- lib/repl.js | 6 ++++-- 9 files changed, 36 insertions(+), 30 deletions(-) diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index d2b82e7b699cd7..77a43fe0dc27ee 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -40,8 +40,8 @@ setupPrepareStackTrace(); const { Array, - ArrayPrototypeConcat, ArrayPrototypeFill, + ArrayPrototypePushApply, FunctionPrototypeCall, JSONParse, ObjectDefineProperty, @@ -179,11 +179,11 @@ const rawMethods = internalBinding('process_methods'); process.getActiveResourcesInfo = function() { const timerCounts = internalTimers.getTimerCounts(); - return ArrayPrototypeConcat( - rawMethods._getActiveRequestsInfo(), - rawMethods._getActiveHandlesInfo(), - ArrayPrototypeFill(new Array(timerCounts.timeoutCount), 'Timeout'), - ArrayPrototypeFill(new Array(timerCounts.immediateCount), 'Immediate')); + const info = rawMethods._getActiveRequestsInfo(); + ArrayPrototypePushApply(info, rawMethods._getActiveHandlesInfo()); + ArrayPrototypePushApply(info, ArrayPrototypeFill(new Array(timerCounts.timeoutCount), 'Timeout')); + ArrayPrototypePushApply(info, ArrayPrototypeFill(new Array(timerCounts.immediateCount), 'Immediate')); + return info; }; // TODO(joyeecheung): remove these diff --git a/lib/internal/debugger/inspect.js b/lib/internal/debugger/inspect.js index e006f513f9b93f..2ab824741ddcea 100644 --- a/lib/internal/debugger/inspect.js +++ b/lib/internal/debugger/inspect.js @@ -1,11 +1,11 @@ 'use strict'; const { - ArrayPrototypeConcat, ArrayPrototypeForEach, ArrayPrototypeJoin, ArrayPrototypeMap, ArrayPrototypePop, + ArrayPrototypePushApply, ArrayPrototypeShift, ArrayPrototypeSlice, FunctionPrototypeBind, @@ -79,9 +79,8 @@ const debugRegex = /Debugger listening on ws:\/\/\[?(.+?)\]?:(\d+)\//; async function runScript(script, scriptArgs, inspectHost, inspectPort, childPrint) { await portIsFree(inspectHost, inspectPort); - const args = ArrayPrototypeConcat( - [`--inspect-brk=${inspectPort}`, script], - scriptArgs); + const args = [`--inspect-brk=${inspectPort}`, script]; + ArrayPrototypePushApply(args, scriptArgs); const child = spawn(process.execPath, args); child.stdout.setEncoding('utf8'); child.stderr.setEncoding('utf8'); diff --git a/lib/internal/main/print_help.js b/lib/internal/main/print_help.js index bfef215ace8db5..ad35d3db353b9a 100644 --- a/lib/internal/main/print_help.js +++ b/lib/internal/main/print_help.js @@ -31,6 +31,7 @@ for (const key of ObjectKeys(types)) // Environment variables are parsed ad-hoc throughout the code base, // so we gather the documentation here. const { hasIntl, hasSmallICU, hasNodeOptions } = internalBinding('config'); +// eslint-disable-next-line node-code/avoid-prototype-pollution const envVars = new SafeMap(ArrayPrototypeConcat([ ['FORCE_COLOR', { helpText: "when set to 'true', 1, 2, 3, or an empty " + 'string causes NO_COLOR and NODE_DISABLE_COLORS to be ignored.' }], diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index 796c527b011139..71ed904133ee81 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -688,9 +688,12 @@ Module._resolveLookupPaths = function(request, parent) { StringPrototypeCharAt(request, 1) !== '/' && (!isWindows || StringPrototypeCharAt(request, 1) !== '\\'))) { - let paths = modulePaths; + let paths; if (parent?.paths?.length) { - paths = ArrayPrototypeConcat(parent.paths, paths); + paths = ArrayPrototypeSlice(modulePaths); + ArrayPrototypeUnshiftApply(paths, parent.paths); + } else { + paths = modulePaths; } debug('looking for %j in %j', request, paths); diff --git a/lib/internal/modules/esm/resolve.js b/lib/internal/modules/esm/resolve.js index a923508f2fd866..61fb1fb4814fc0 100644 --- a/lib/internal/modules/esm/resolve.js +++ b/lib/internal/modules/esm/resolve.js @@ -2,8 +2,8 @@ const { ArrayIsArray, - ArrayPrototypeConcat, ArrayPrototypeJoin, + ArrayPrototypePush, ArrayPrototypeShift, JSONParse, JSONStringify, @@ -973,11 +973,11 @@ function throwIfUnsupportedURLScheme(parsed, experimentalNetworkImports) { ) ) ) { - throw new ERR_UNSUPPORTED_ESM_URL_SCHEME(parsed, ArrayPrototypeConcat( - 'file', - 'data', - experimentalNetworkImports ? ['https', 'http'] : [], - )); + const schemes = ['file', 'data']; + if (experimentalNetworkImports) { + ArrayPrototypePush(schemes, 'https', 'http'); + } + throw new ERR_UNSUPPORTED_ESM_URL_SCHEME(parsed, schemes); } } diff --git a/lib/internal/perf/observe.js b/lib/internal/perf/observe.js index f84bb69bbddae2..9634f3ea641bf0 100644 --- a/lib/internal/perf/observe.js +++ b/lib/internal/perf/observe.js @@ -470,7 +470,10 @@ function filterBufferMapByNameAndType(name, type) { // Unrecognized type; return []; } else { - bufferList = ArrayPrototypeConcat(markEntryBuffer, measureEntryBuffer, resourceTimingBuffer); + bufferList = []; + ArrayPrototypePushApply(bufferList, markEntryBuffer); + ArrayPrototypePushApply(bufferList, measureEntryBuffer); + ArrayPrototypePushApply(bufferList, resourceTimingBuffer); } if (name !== undefined) { bufferList = ArrayPrototypeFilter(bufferList, (buffer) => buffer.name === name); diff --git a/lib/internal/test_runner/runner.js b/lib/internal/test_runner/runner.js index a4afbcb0a7710f..e864508879945a 100644 --- a/lib/internal/test_runner/runner.js +++ b/lib/internal/test_runner/runner.js @@ -1,10 +1,10 @@ 'use strict'; const { ArrayFrom, - ArrayPrototypeConcat, ArrayPrototypeFilter, ArrayPrototypeIncludes, ArrayPrototypeJoin, + ArrayPrototypePush, ArrayPrototypeSlice, ArrayPrototypeSort, ObjectAssign, @@ -102,9 +102,8 @@ function filterExecArgv(arg) { function runTestFile(path, root) { const subtest = root.createSubtest(Test, path, async (t) => { - const args = ArrayPrototypeConcat( - ArrayPrototypeFilter(process.execArgv, filterExecArgv), - path); + const args = ArrayPrototypeFilter(process.execArgv, filterExecArgv); + ArrayPrototypePush(args, path); const child = spawn(process.execPath, args, { signal: t.signal, encoding: 'utf8' }); // TODO(cjihrig): Implement a TAP parser to read the child's stdout diff --git a/lib/internal/util/inspector.js b/lib/internal/util/inspector.js index d78467136c4918..9eecad48e219db 100644 --- a/lib/internal/util/inspector.js +++ b/lib/internal/util/inspector.js @@ -1,7 +1,7 @@ 'use strict'; const { - ArrayPrototypeConcat, + ArrayPrototypePushApply, FunctionPrototypeBind, ObjectDefineProperty, ObjectKeys, @@ -30,10 +30,9 @@ function installConsoleExtensions(commandLineApi) { const { makeRequireFunction } = require('internal/modules/cjs/helpers'); const consoleAPIModule = new CJSModule(''); const cwd = tryGetCwd(); - consoleAPIModule.paths = ArrayPrototypeConcat( - CJSModule._nodeModulePaths(cwd), - CJSModule.globalPaths - ); + consoleAPIModule.paths = []; + ArrayPrototypePushApply(consoleAPIModule.paths, CJSModule._nodeModulePaths(cwd)); + ArrayPrototypePushApply(consoleAPIModule.paths, CJSModule.globalPaths); commandLineApi.require = makeRequireFunction(consoleAPIModule); } diff --git a/lib/repl.js b/lib/repl.js index f2996d660d8d6f..4bf71eeaceb200 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -43,7 +43,6 @@ 'use strict'; const { - ArrayPrototypeConcat, ArrayPrototypeFilter, ArrayPrototypeFindIndex, ArrayPrototypeForEach, @@ -52,6 +51,7 @@ const { ArrayPrototypeMap, ArrayPrototypePop, ArrayPrototypePush, + ArrayPrototypePushApply, ArrayPrototypeReverse, ArrayPrototypeShift, ArrayPrototypeSlice, @@ -1333,7 +1333,9 @@ function complete(line, callback) { } else if (RegExpPrototypeExec(/^\.\.?\//, completeOn) !== null) { paths = [process.cwd()]; } else { - paths = ArrayPrototypeConcat(module.paths, CJSModule.globalPaths); + paths = []; + ArrayPrototypePushApply(paths, module.paths); + ArrayPrototypePushApply(paths, CJSModule.globalPaths); } ArrayPrototypeForEach(paths, (dir) => {