mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
lib: remove startsWith/endsWith primordials for char checks
PR-URL: https://github.com/nodejs/node/pull/55407 Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Mattias Buelens <mattias@buelens.com> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
This commit is contained in:
parent
6e3e99c81e
commit
753cbede2a
11 changed files with 17 additions and 22 deletions
|
@ -341,7 +341,7 @@ function calculateServerName(options, req) {
|
|||
// abc:123 => abc
|
||||
// [::1] => ::1
|
||||
// [::1]:123 => ::1
|
||||
if (hostHeader.startsWith('[')) {
|
||||
if (hostHeader[0] === '[') {
|
||||
const index = hostHeader.indexOf(']');
|
||||
if (index === -1) {
|
||||
// Leading '[', but no ']'. Need to do something...
|
||||
|
|
|
@ -46,7 +46,7 @@ for (let i = 0; i < process.execArgv.length; i++) {
|
|||
if (StringPrototypeStartsWith(arg, '--watch')) {
|
||||
i++;
|
||||
const nextArg = process.execArgv[i];
|
||||
if (nextArg && StringPrototypeStartsWith(nextArg, '-')) {
|
||||
if (nextArg && nextArg[0] === '-') {
|
||||
ArrayPrototypePush(argsWithoutWatchOptions, nextArg);
|
||||
}
|
||||
continue;
|
||||
|
|
|
@ -3,9 +3,7 @@ const {
|
|||
ObjectPrototypeHasOwnProperty,
|
||||
PromisePrototypeThen,
|
||||
SafeMap,
|
||||
StringPrototypeEndsWith,
|
||||
StringPrototypeSlice,
|
||||
StringPrototypeStartsWith,
|
||||
} = primordials;
|
||||
const {
|
||||
Buffer: { concat: BufferConcat },
|
||||
|
@ -248,8 +246,9 @@ allowList.addRange('127.0.0.1', '127.255.255.255');
|
|||
async function isLocalAddress(hostname) {
|
||||
try {
|
||||
if (
|
||||
StringPrototypeStartsWith(hostname, '[') &&
|
||||
StringPrototypeEndsWith(hostname, ']')
|
||||
hostname.length &&
|
||||
hostname[0] === '[' &&
|
||||
hostname[hostname.length - 1] === ']'
|
||||
) {
|
||||
hostname = StringPrototypeSlice(hostname, 1, -1);
|
||||
}
|
||||
|
|
|
@ -391,8 +391,9 @@ function resolvePackageTargetString(
|
|||
}
|
||||
|
||||
if (!StringPrototypeStartsWith(target, './')) {
|
||||
if (internal && !StringPrototypeStartsWith(target, '../') &&
|
||||
!StringPrototypeStartsWith(target, '/')) {
|
||||
if (internal &&
|
||||
target[0] !== '/' &&
|
||||
!StringPrototypeStartsWith(target, '../')) {
|
||||
// No need to convert target to string, since it's already presumed to be
|
||||
if (!URLCanParse(target)) {
|
||||
const exportTarget = pattern ?
|
||||
|
|
|
@ -202,7 +202,7 @@ function addBuiltinLibsToObject(object, dummyModuleName) {
|
|||
ArrayPrototypeForEach(builtinModules, (name) => {
|
||||
// Neither add underscored modules, nor ones that contain slashes (e.g.,
|
||||
// 'fs/promises') or ones that are already defined.
|
||||
if (StringPrototypeStartsWith(name, '_') ||
|
||||
if (name[0] === '_' ||
|
||||
StringPrototypeIncludes(name, '/') ||
|
||||
ObjectPrototypeHasOwnProperty(object, name)) {
|
||||
return;
|
||||
|
|
|
@ -25,7 +25,6 @@ const {
|
|||
StringPrototypeEndsWith,
|
||||
StringPrototypeReplace,
|
||||
StringPrototypeSlice,
|
||||
StringPrototypeStartsWith,
|
||||
Symbol,
|
||||
SymbolIterator,
|
||||
} = primordials;
|
||||
|
@ -300,7 +299,7 @@ function buildAllowedFlags() {
|
|||
}
|
||||
|
||||
function isAccepted(to) {
|
||||
if (!StringPrototypeStartsWith(to, '-') || to === '--') return true;
|
||||
if (!to.length || to[0] !== '-' || to === '--') return true;
|
||||
const recursiveExpansion = aliases.get(to);
|
||||
if (recursiveExpansion) {
|
||||
if (recursiveExpansion[0] === to)
|
||||
|
|
|
@ -14,7 +14,6 @@ const {
|
|||
ObjectFreeze,
|
||||
ObjectGetOwnPropertyDescriptor,
|
||||
String,
|
||||
StringPrototypeStartsWith,
|
||||
Symbol,
|
||||
globalThis,
|
||||
} = primordials;
|
||||
|
@ -242,8 +241,7 @@ function patchProcessObject(expandArgv1) {
|
|||
let mainEntry;
|
||||
// If requested, update process.argv[1] to replace whatever the user provided with the resolved absolute file path of
|
||||
// the entry point.
|
||||
if (expandArgv1 && process.argv[1] &&
|
||||
!StringPrototypeStartsWith(process.argv[1], '-')) {
|
||||
if (expandArgv1 && process.argv[1] && process.argv[1][0] !== '-') {
|
||||
// Expand process.argv[1] into a full path.
|
||||
const path = require('path');
|
||||
try {
|
||||
|
|
|
@ -10,12 +10,10 @@ const {
|
|||
RegExpPrototypeExec,
|
||||
SafeSet,
|
||||
SafeStringIterator,
|
||||
StringPrototypeEndsWith,
|
||||
StringPrototypeIndexOf,
|
||||
StringPrototypeLastIndexOf,
|
||||
StringPrototypeReplaceAll,
|
||||
StringPrototypeSlice,
|
||||
StringPrototypeStartsWith,
|
||||
StringPrototypeToLowerCase,
|
||||
StringPrototypeTrim,
|
||||
Symbol,
|
||||
|
@ -298,8 +296,7 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) {
|
|||
function getInputPreview(input, callback) {
|
||||
// For similar reasons as `defaultEval`, wrap expressions starting with a
|
||||
// curly brace with parenthesis.
|
||||
if (StringPrototypeStartsWith(input, '{') &&
|
||||
!StringPrototypeEndsWith(input, ';') && !wrapped) {
|
||||
if (!wrapped && input[0] === '{' && input[input.length - 1] !== ';') {
|
||||
input = `(${input})`;
|
||||
wrapped = true;
|
||||
}
|
||||
|
|
|
@ -1428,7 +1428,7 @@ function urlToHttpOptions(url) {
|
|||
__proto__: null,
|
||||
...url, // In case the url object was extended by the user.
|
||||
protocol: url.protocol,
|
||||
hostname: hostname && StringPrototypeStartsWith(hostname, '[') ?
|
||||
hostname: hostname && hostname[0] === '[' ?
|
||||
StringPrototypeSlice(hostname, 1, -1) :
|
||||
hostname,
|
||||
hash: url.hash,
|
||||
|
|
|
@ -1191,7 +1191,7 @@ function getClassBase(value, constructor, tag) {
|
|||
|
||||
function getFunctionBase(value, constructor, tag) {
|
||||
const stringified = FunctionPrototypeToString(value);
|
||||
if (StringPrototypeStartsWith(stringified, 'class') && StringPrototypeEndsWith(stringified, '}')) {
|
||||
if (StringPrototypeStartsWith(stringified, 'class') && stringified[stringified.length - 1] === '}') {
|
||||
const slice = StringPrototypeSlice(stringified, 5, -1);
|
||||
const bracketIndex = StringPrototypeIndexOf(slice, '{');
|
||||
if (bracketIndex !== -1 &&
|
||||
|
@ -1570,7 +1570,8 @@ function handleMaxCallStackSize(ctx, err, constructorName, indentationLvl) {
|
|||
function addNumericSeparator(integerString) {
|
||||
let result = '';
|
||||
let i = integerString.length;
|
||||
const start = StringPrototypeStartsWith(integerString, '-') ? 1 : 0;
|
||||
assert(i !== 0);
|
||||
const start = integerString[0] === '-' ? 1 : 0;
|
||||
for (; i >= start + 4; i -= 3) {
|
||||
result = `_${StringPrototypeSlice(integerString, i - 3, i)}${result}`;
|
||||
}
|
||||
|
|
|
@ -130,7 +130,7 @@ const { shouldColorize } = require('internal/util/colors');
|
|||
const CJSModule = require('internal/modules/cjs/loader').Module;
|
||||
let _builtinLibs = ArrayPrototypeFilter(
|
||||
CJSModule.builtinModules,
|
||||
(e) => !StringPrototypeStartsWith(e, '_'),
|
||||
(e) => e[0] !== '_',
|
||||
);
|
||||
const nodeSchemeBuiltinLibs = ArrayPrototypeMap(
|
||||
_builtinLibs, (lib) => `node:${lib}`);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue