| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,13 +23,25 @@ | |||
| 23 | 23 | ||
| 24 | 24 | const { | |
| 25 | 25 | ArrayIsArray, | |
| 26 | + ArrayPrototypeFilter, | ||
| 27 | + ArrayPrototypeIncludes, | ||
| 28 | + ArrayPrototypeJoin, | ||
| 29 | + ArrayPrototypeLastIndexOf, | ||
| 30 | + ArrayPrototypePush, | ||
| 31 | + ArrayPrototypeSlice, | ||
| 32 | + ArrayPrototypeSort, | ||
| 33 | + ArrayPrototypeSplice, | ||
| 34 | + ArrayPrototypeUnshift, | ||
| 26 | 35 | Error, | |
| 27 | 36 | NumberIsInteger, | |
| 28 | 37 | ObjectAssign, | |
| 29 | 38 | ObjectDefineProperty, | |
| 30 | 39 | ObjectPrototypeHasOwnProperty, | |
| 31 | 40 | Promise, | |
| 32 | - Set, | ||
| 41 | + RegExpPrototypeTest, | ||
| 42 | + SafeSet, | ||
| 43 | + StringPrototypeSlice, | ||
| 44 | + StringPrototypeToUpperCase, | ||
| 33 | 45 | } = primordials; | |
| 34 | 46 | ||
| 35 | 47 | const { | |
@@ -94,15 +106,15 @@ function fork(modulePath /* , args, options */) { | |||
| 94 | 106 | execArgv = options.execArgv || process.execArgv; | |
| 95 | 107 | ||
| 96 | 108 | if (execArgv === process.execArgv && process._eval != null) { | |
| 97 | - const index = execArgv.lastIndexOf(process._eval); | ||
| 109 | + const index = ArrayPrototypeLastIndexOf(execArgv, process._eval); | ||
| 98 | 110 | if (index > 0) { | |
| 99 | 111 | // Remove the -e switch to avoid fork bombing ourselves. | |
| 100 | - execArgv = execArgv.slice(); | ||
| 101 | - execArgv.splice(index - 1, 2); | ||
| 112 | + execArgv = ArrayPrototypeSlice(execArgv); | ||
| 113 | + ArrayPrototypeSplice(execArgv, index - 1, 2); | ||
| 102 | 114 | } | |
| 103 | 115 | } | |
| 104 | 116 | ||
| 105 | - args = execArgv.concat([modulePath], args); | ||
| 117 | + args = [...execArgv, modulePath, ...args]; | ||
| 106 | 118 | ||
| 107 | 119 | if (typeof options.stdio === 'string') { | |
| 108 | 120 | options.stdio = stdioStringToArray(options.stdio, 'ipc'); | |
@@ -112,7 +124,7 @@ function fork(modulePath /* , args, options */) { | |||
| 112 | 124 | options.stdio = stdioStringToArray( | |
| 113 | 125 | options.silent ? 'pipe' : 'inherit', | |
| 114 | 126 | 'ipc'); | |
| 115 | - } else if (!options.stdio.includes('ipc')) { | ||
| 127 | + } else if (!ArrayPrototypeIncludes(options.stdio, 'ipc')) { | ||
| 116 | 128 | throw new ERR_CHILD_PROCESS_IPC_REQUIRED('options.stdio'); | |
| 117 | 129 | } | |
| 118 | 130 | ||
@@ -282,7 +294,7 @@ function execFile(file /* , args, options, callback */) { | |||
| 282 | 294 | child.stdout && | |
| 283 | 295 | child.stdout.readableEncoding | |
| 284 | 296 | )) { | |
| 285 | - stdout = _stdout.join(''); | ||
| 297 | + stdout = ArrayPrototypeJoin(_stdout, ''); | ||
| 286 | 298 | } else { | |
| 287 | 299 | stdout = Buffer.concat(_stdout); | |
| 288 | 300 | } | |
@@ -291,7 +303,7 @@ function execFile(file /* , args, options, callback */) { | |||
| 291 | 303 | child.stderr && | |
| 292 | 304 | child.stderr.readableEncoding | |
| 293 | 305 | )) { | |
| 294 | - stderr = _stderr.join(''); | ||
| 306 | + stderr = ArrayPrototypeJoin(_stderr, ''); | ||
| 295 | 307 | } else { | |
| 296 | 308 | stderr = Buffer.concat(_stderr); | |
| 297 | 309 | } | |
@@ -302,7 +314,7 @@ function execFile(file /* , args, options, callback */) { | |||
| 302 | 314 | } | |
| 303 | 315 | ||
| 304 | 316 | if (args.length !== 0) | |
| 305 | - cmd += ` ${args.join(' ')}`; | ||
| 317 | + cmd += ` ${ArrayPrototypeJoin(args, ' ')}`; | ||
| 306 | 318 | ||
| 307 | 319 | if (!ex) { | |
| 308 | 320 | // eslint-disable-next-line no-restricted-syntax | |
@@ -360,16 +372,18 @@ function execFile(file /* , args, options, callback */) { | |||
| 360 | 372 | const length = encoding ? | |
| 361 | 373 | Buffer.byteLength(chunk, encoding) : | |
| 362 | 374 | chunk.length; | |
| 375 | + const slice = encoding ? StringPrototypeSlice : | ||
| 376 | + (buf, ...args) => buf.slice(...args); | ||
| 363 | 377 | stdoutLen += length; | |
| 364 | 378 | ||
| 365 | 379 | if (stdoutLen > options.maxBuffer) { | |
| 366 | 380 | const truncatedLen = options.maxBuffer - (stdoutLen - length); | |
| 367 | - _stdout.push(chunk.slice(0, truncatedLen)); | ||
| 381 | + ArrayPrototypePush(_stdout, slice(chunk, 0, truncatedLen)); | ||
| 368 | 382 | ||
| 369 | 383 | ex = new ERR_CHILD_PROCESS_STDIO_MAXBUFFER('stdout'); | |
| 370 | 384 | kill(); | |
| 371 | 385 | } else { | |
| 372 | - _stdout.push(chunk); | ||
| 386 | + ArrayPrototypePush(_stdout, chunk); | ||
| 373 | 387 | } | |
| 374 | 388 | }); | |
| 375 | 389 | } | |
@@ -387,7 +401,8 @@ function execFile(file /* , args, options, callback */) { | |||
| 387 | 401 | ||
| 388 | 402 | if (stderrLen > options.maxBuffer) { | |
| 389 | 403 | const truncatedLen = options.maxBuffer - (stderrLen - length); | |
| 390 | - _stderr.push(chunk.slice(0, truncatedLen)); | ||
| 404 | + ArrayPrototypePush(_stderr, | ||
| 405 | + chunk.slice(0, truncatedLen)); | ||
| 391 | 406 | ||
| 392 | 407 | ex = new ERR_CHILD_PROCESS_STDIO_MAXBUFFER('stderr'); | |
| 393 | 408 | kill(); | |
@@ -415,7 +430,7 @@ function normalizeSpawnArguments(file, args, options) { | |||
| 415 | 430 | throw new ERR_INVALID_ARG_VALUE('file', file, 'cannot be empty'); | |
| 416 | 431 | ||
| 417 | 432 | if (ArrayIsArray(args)) { | |
| 418 | - args = args.slice(0); | ||
| 433 | + args = ArrayPrototypeSlice(args); | ||
| 419 | 434 | } else if (args == null) { | |
| 420 | 435 | args = []; | |
| 421 | 436 | } else if (typeof args !== 'object') { | |
@@ -484,15 +499,15 @@ function normalizeSpawnArguments(file, args, options) { | |||
| 484 | 499 | } | |
| 485 | 500 | ||
| 486 | 501 | if (options.shell) { | |
| 487 | - const command = [file].concat(args).join(' '); | ||
| 502 | + const command = ArrayPrototypeJoin([file, ...args], ' '); | ||
| 488 | 503 | // Set the shell, switches, and commands. | |
| 489 | 504 | if (process.platform === 'win32') { | |
| 490 | 505 | if (typeof options.shell === 'string') | |
| 491 | 506 | file = options.shell; | |
| 492 | 507 | else | |
| 493 | 508 | file = process.env.comspec || 'cmd.exe'; | |
| 494 | 509 | // '/d /s /c' is used only for cmd.exe. | |
| 495 | - if (/^(?:.*\\)?cmd(?:\.exe)?$/i.test(file)) { | ||
| 510 | + if (RegExpPrototypeTest(/^(?:.*\\)?cmd(?:\.exe)?$/i, file)) { | ||
| 496 | 511 | args = ['/d', '/s', '/c', `"${command}"`]; | |
| 497 | 512 | windowsVerbatimArguments = true; | |
| 498 | 513 | } else { | |
@@ -510,9 +525,9 @@ function normalizeSpawnArguments(file, args, options) { | |||
| 510 | 525 | } | |
| 511 | 526 | ||
| 512 | 527 | if (typeof options.argv0 === 'string') { | |
| 513 | - args.unshift(options.argv0); | ||
| 528 | + ArrayPrototypeUnshift(args, options.argv0); | ||
| 514 | 529 | } else { | |
| 515 | - args.unshift(file); | ||
| 530 | + ArrayPrototypeUnshift(args, file); | ||
| 516 | 531 | } | |
| 517 | 532 | ||
| 518 | 533 | const env = options.env || process.env; | |
@@ -528,27 +543,30 @@ function normalizeSpawnArguments(file, args, options) { | |||
| 528 | 543 | let envKeys = []; | |
| 529 | 544 | // Prototype values are intentionally included. | |
| 530 | 545 | for (const key in env) { | |
| 531 | - envKeys.push(key); | ||
| 546 | + ArrayPrototypePush(envKeys, key); | ||
| 532 | 547 | } | |
| 533 | 548 | ||
| 534 | 549 | if (process.platform === 'win32') { | |
| 535 | 550 | // On Windows env keys are case insensitive. Filter out duplicates, | |
| 536 | 551 | // keeping only the first one (in lexicographic order) | |
| 537 | - const sawKey = new Set(); | ||
| 538 | - envKeys = envKeys.sort().filter((key) => { | ||
| 539 | - const uppercaseKey = key.toUpperCase(); | ||
| 540 | - if (sawKey.has(uppercaseKey)) { | ||
| 541 | - return false; | ||
| 552 | + const sawKey = new SafeSet(); | ||
| 553 | + envKeys = ArrayPrototypeFilter( | ||
| 554 | + ArrayPrototypeSort(envKeys), | ||
| 555 | + (key) => { | ||
| 556 | + const uppercaseKey = StringPrototypeToUpperCase(key); | ||
| 557 | + if (sawKey.has(uppercaseKey)) { | ||
| 558 | + return false; | ||
| 559 | + } | ||
| 560 | + sawKey.add(uppercaseKey); | ||
| 561 | + return true; | ||
| 542 | 562 | } | |
| 543 | - sawKey.add(uppercaseKey); | ||
| 544 | - return true; | ||
| 545 | - }); | ||
| 563 | + ); | ||
| 546 | 564 | } | |
| 547 | 565 | ||
| 548 | 566 | for (const key of envKeys) { | |
| 549 | 567 | const value = env[key]; | |
| 550 | 568 | if (value !== undefined) { | |
| 551 | - envPairs.push(`${key}=${value}`); | ||
| 569 | + ArrayPrototypePush(envPairs, `${key}=${value}`); | ||
| 552 | 570 | } | |
| 553 | 571 | } | |
| 554 | 572 | ||
@@ -629,7 +647,7 @@ function checkExecSyncError(ret, args, cmd) { | |||
| 629 | 647 | err = ret.error; | |
| 630 | 648 | } else if (ret.status !== 0) { | |
| 631 | 649 | let msg = 'Command failed: '; | |
| 632 | - msg += cmd || args.join(' '); | ||
| 650 | + msg += cmd || ArrayPrototypeJoin(args, ' '); | ||
| 633 | 651 | if (ret.stderr && ret.stderr.length > 0) | |
| 634 | 652 | msg += `\n${ret.stderr.toString()}`; | |
| 635 | 653 | // eslint-disable-next-line no-restricted-syntax | |
@@ -646,7 +664,8 @@ function execFileSync(command, args, options) { | |||
| 646 | 664 | options = normalizeSpawnArguments(command, args, options); | |
| 647 | 665 | ||
| 648 | 666 | const inheritStderr = !options.stdio; | |
| 649 | - const ret = spawnSync(options.file, options.args.slice(1), options); | ||
| 667 | + const ret = spawnSync(options.file, | ||
| 668 | + ArrayPrototypeSlice(options.args, 1), options); | ||
| 650 | 669 | ||
| 651 | 670 | if (inheritStderr && ret.stderr) | |
| 652 | 671 | process.stderr.write(ret.stderr); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments