| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 476c3ec commit 4f9cd27
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -460,16 +460,14 @@ function normalizeSpawnArguments(file, args, options) { | |||
| 460 | 460 | } | |
| 461 | 461 | ||
| 462 | 462 | // Validate windowsVerbatimArguments, if present. | |
| 463 | - if (options.windowsVerbatimArguments != null && | ||
| 464 | - typeof options.windowsVerbatimArguments !== 'boolean') { | ||
| 463 | + let { windowsVerbatimArguments } = options; | ||
| 464 | + if (windowsVerbatimArguments != null && | ||
| 465 | + typeof windowsVerbatimArguments !== 'boolean') { | ||
| 465 | 466 | throw new ERR_INVALID_ARG_TYPE('options.windowsVerbatimArguments', | |
| 466 | 467 | 'boolean', | |
| 467 | - options.windowsVerbatimArguments); | ||
| 468 | + windowsVerbatimArguments); | ||
| 468 | 469 | } | |
| 469 | 470 | ||
| 470 | - // Make a shallow copy so we don't clobber the user's options object. | ||
| 471 | - options = { ...options }; | ||
| 472 | - | ||
| 473 | 471 | if (options.shell) { | |
| 474 | 472 | const command = [file].concat(args).join(' '); | |
| 475 | 473 | // Set the shell, switches, and commands. | |
@@ -481,7 +479,7 @@ function normalizeSpawnArguments(file, args, options) { | |||
| 481 | 479 | // '/d /s /c' is used only for cmd.exe. | |
| 482 | 480 | if (/^(?:.*\\)?cmd(?:\.exe)?$/i.test(file)) { | |
| 483 | 481 | args = ['/d', '/s', '/c', `"${command}"`]; | |
| 484 | - options.windowsVerbatimArguments = true; | ||
| 482 | + windowsVerbatimArguments = true; | ||
| 485 | 483 | } else { | |
| 486 | 484 | args = ['-c', command]; | |
| 487 | 485 | } | |
@@ -521,58 +519,42 @@ function normalizeSpawnArguments(file, args, options) { | |||
| 521 | 519 | } | |
| 522 | 520 | ||
| 523 | 521 | return { | |
| 524 | - file: file, | ||
| 525 | - args: args, | ||
| 526 | - options: options, | ||
| 527 | - envPairs: envPairs | ||
| 522 | + // Make a shallow copy so we don't clobber the user's options object. | ||
| 523 | + ...options, | ||
| 524 | + args, | ||
| 525 | + detached: !!options.detached, | ||
| 526 | + envPairs, | ||
| 527 | + file, | ||
| 528 | + windowsHide: !!options.windowsHide, | ||
| 529 | + windowsVerbatimArguments: !!windowsVerbatimArguments | ||
| 528 | 530 | }; | |
| 529 | 531 | } | |
| 530 | 532 | ||
| 531 | 533 | ||
| 532 | 534 | var spawn = exports.spawn = function spawn(file, args, options) { | |
| 533 | - const opts = normalizeSpawnArguments(file, args, options); | ||
| 534 | 535 | const child = new ChildProcess(); | |
| 535 | 536 | ||
| 536 | - options = opts.options; | ||
| 537 | - debug('spawn', opts.args, options); | ||
| 538 | - | ||
| 539 | - child.spawn({ | ||
| 540 | - file: opts.file, | ||
| 541 | - args: opts.args, | ||
| 542 | - cwd: options.cwd, | ||
| 543 | - windowsHide: !!options.windowsHide, | ||
| 544 | - windowsVerbatimArguments: !!options.windowsVerbatimArguments, | ||
| 545 | - detached: !!options.detached, | ||
| 546 | - envPairs: opts.envPairs, | ||
| 547 | - stdio: options.stdio, | ||
| 548 | - uid: options.uid, | ||
| 549 | - gid: options.gid | ||
| 550 | - }); | ||
| 537 | + options = normalizeSpawnArguments(file, args, options); | ||
| 538 | + debug('spawn', options); | ||
| 539 | + child.spawn(options); | ||
| 551 | 540 | ||
| 552 | 541 | return child; | |
| 553 | 542 | }; | |
| 554 | 543 | ||
| 555 | 544 | function spawnSync(file, args, options) { | |
| 556 | - const opts = normalizeSpawnArguments(file, args, options); | ||
| 557 | - | ||
| 558 | - const defaults = { | ||
| 545 | + options = { | ||
| 559 | 546 | maxBuffer: MAX_BUFFER, | |
| 560 | - ...opts.options | ||
| 547 | + ...normalizeSpawnArguments(file, args, options) | ||
| 561 | 548 | }; | |
| 562 | - options = opts.options = defaults; | ||
| 563 | 549 | ||
| 564 | - debug('spawnSync', opts.args, options); | ||
| 550 | + debug('spawnSync', options); | ||
| 565 | 551 | ||
| 566 | 552 | // Validate the timeout, if present. | |
| 567 | 553 | validateTimeout(options.timeout); | |
| 568 | 554 | ||
| 569 | 555 | // Validate maxBuffer, if present. | |
| 570 | 556 | validateMaxBuffer(options.maxBuffer); | |
| 571 | 557 | ||
| 572 | - options.file = opts.file; | ||
| 573 | - options.args = opts.args; | ||
| 574 | - options.envPairs = opts.envPairs; | ||
| 575 | - | ||
| 576 | 558 | // Validate and translate the kill signal, if present. | |
| 577 | 559 | options.killSignal = sanitizeKillSignal(options.killSignal); | |
| 578 | 560 | ||
@@ -603,7 +585,7 @@ function spawnSync(file, args, options) { | |||
| 603 | 585 | } | |
| 604 | 586 | } | |
| 605 | 587 | ||
| 606 | - return child_process.spawnSync(opts); | ||
| 588 | + return child_process.spawnSync(options); | ||
| 607 | 589 | } | |
| 608 | 590 | exports.spawnSync = spawnSync; | |
| 609 | 591 | ||
@@ -628,15 +610,15 @@ function checkExecSyncError(ret, args, cmd) { | |||
| 628 | 610 | ||
| 629 | 611 | ||
| 630 | 612 | function execFileSync(command, args, options) { | |
| 631 | - const opts = normalizeSpawnArguments(command, args, options); | ||
| 632 | - const inheritStderr = !opts.options.stdio; | ||
| 613 | + options = normalizeSpawnArguments(command, args, options); | ||
| 633 | 614 | ||
| 634 | - const ret = spawnSync(opts.file, opts.args.slice(1), opts.options); | ||
| 615 | + const inheritStderr = !options.stdio; | ||
| 616 | + const ret = spawnSync(options.file, options.args.slice(1), options); | ||
| 635 | 617 | ||
| 636 | 618 | if (inheritStderr && ret.stderr) | |
| 637 | 619 | process.stderr.write(ret.stderr); | |
| 638 | 620 | ||
| 639 | - const err = checkExecSyncError(ret, opts.args, undefined); | ||
| 621 | + const err = checkExecSyncError(ret, options.args, undefined); | ||
| 640 | 622 | ||
| 641 | 623 | if (err) | |
| 642 | 624 | throw err; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1022,8 +1022,7 @@ function maybeClose(subprocess) { | |||
| 1022 | 1022 | } | |
| 1023 | 1023 | } | |
| 1024 | 1024 | ||
| 1025 | - function spawnSync(opts) { | ||
| 1026 | - const options = opts.options; | ||
| 1025 | + function spawnSync(options) { | ||
| 1027 | 1026 | const result = spawn_sync.spawn(options); | |
| 1028 | 1027 | ||
| 1029 | 1028 | if (result.output && options.encoding && options.encoding !== 'buffer') { | |
@@ -1038,9 +1037,9 @@ function spawnSync(opts) { | |||
| 1038 | 1037 | result.stderr = result.output && result.output[2]; | |
| 1039 | 1038 | ||
| 1040 | 1039 | if (result.error) { | |
| 1041 | - result.error = errnoException(result.error, 'spawnSync ' + opts.file); | ||
| 1042 | - result.error.path = opts.file; | ||
| 1043 | - result.error.spawnargs = opts.args.slice(1); | ||
| 1040 | + result.error = errnoException(result.error, 'spawnSync ' + options.file); | ||
| 1041 | + result.error.path = options.file; | ||
| 1042 | + result.error.spawnargs = options.args.slice(1); | ||
| 1044 | 1043 | } | |
| 1045 | 1044 | ||
| 1046 | 1045 | return result; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,7 +36,7 @@ if (process.argv[2] === 'child') { | |||
| 36 | 36 | // Verify that the default kill signal is SIGTERM. | |
| 37 | 37 | { | |
| 38 | 38 | const child = spawn(undefined, (opts) => { | |
| 39 | - assert.strictEqual(opts.options.killSignal, undefined); | ||
| 39 | + assert.strictEqual(opts.killSignal, undefined); | ||
| 40 | 40 | }); | |
| 41 | 41 | ||
| 42 | 42 | assert.strictEqual(child.signal, 'SIGTERM'); | |
@@ -45,7 +45,7 @@ if (process.argv[2] === 'child') { | |||
| 45 | 45 | // Verify that a string signal name is handled properly. | |
| 46 | 46 | { | |
| 47 | 47 | const child = spawn('SIGKILL', (opts) => { | |
| 48 | - assert.strictEqual(opts.options.killSignal, SIGKILL); | ||
| 48 | + assert.strictEqual(opts.killSignal, SIGKILL); | ||
| 49 | 49 | }); | |
| 50 | 50 | ||
| 51 | 51 | assert.strictEqual(child.signal, 'SIGKILL'); | |
@@ -56,7 +56,7 @@ if (process.argv[2] === 'child') { | |||
| 56 | 56 | assert.strictEqual(typeof SIGKILL, 'number'); | |
| 57 | 57 | ||
| 58 | 58 | const child = spawn(SIGKILL, (opts) => { | |
| 59 | - assert.strictEqual(opts.options.killSignal, SIGKILL); | ||
| 59 | + assert.strictEqual(opts.killSignal, SIGKILL); | ||
| 60 | 60 | }); | |
| 61 | 61 | ||
| 62 | 62 | assert.strictEqual(child.signal, 'SIGKILL'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -64,12 +64,12 @@ assert.strictEqual(env.stdout.toString().trim(), 'buzz'); | |||
| 64 | 64 | assert.strictEqual(opts.file, shellOutput); | |
| 65 | 65 | assert.deepStrictEqual(opts.args, | |
| 66 | 66 | [shellOutput, ...shellFlags, outputCmd]); | |
| 67 | - assert.strictEqual(opts.options.shell, shell); | ||
| 68 | - assert.strictEqual(opts.options.file, opts.file); | ||
| 69 | - assert.deepStrictEqual(opts.options.args, opts.args); | ||
| 70 | - assert.strictEqual(opts.options.windowsHide, undefined); | ||
| 71 | - assert.strictEqual(opts.options.windowsVerbatimArguments, | ||
| 72 | - windowsVerbatim); | ||
| 67 | + assert.strictEqual(opts.shell, shell); | ||
| 68 | + assert.strictEqual(opts.file, opts.file); | ||
| 69 | + assert.deepStrictEqual(opts.args, opts.args); | ||
| 70 | + assert.strictEqual(opts.windowsHide, false); | ||
| 71 | + assert.strictEqual(opts.windowsVerbatimArguments, | ||
| 72 | + !!windowsVerbatim); | ||
| 73 | 73 | }); | |
| 74 | 74 | cp.spawnSync(cmd, { shell }); | |
| 75 | 75 | internalCp.spawnSync = oldSpawnSync; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,7 +19,7 @@ internalCp.ChildProcess.prototype.spawn = common.mustCall(function(options) { | |||
| 19 | 19 | }, 2); | |
| 20 | 20 | ||
| 21 | 21 | internalCp.spawnSync = common.mustCall(function(options) { | |
| 22 | - assert.strictEqual(options.options.windowsHide, true); | ||
| 22 | + assert.strictEqual(options.windowsHide, true); | ||
| 23 | 23 | return originalSpawnSync.apply(this, arguments); | |
| 24 | 24 | }); | |
| 25 | 25 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments