| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent db02f6f commit 26c973d
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -75,7 +75,9 @@ const { getValidatedPath } = require('internal/fs/utils'); | |||
| 75 | 75 | const { | |
| 76 | 76 | isInt32, | |
| 77 | 77 | validateAbortSignal, | |
| 78 | + validateArray, | ||
| 78 | 79 | validateBoolean, | |
| 80 | + validateFunction, | ||
| 79 | 81 | validateObject, | |
| 80 | 82 | validateString, | |
| 81 | 83 | } = require('internal/validators'); | |
@@ -119,20 +121,18 @@ function fork(modulePath, args = [], options) { | |||
| 119 | 121 | ||
| 120 | 122 | if (args == null) { | |
| 121 | 123 | args = []; | |
| 122 | - } else if (typeof args !== 'object') { | ||
| 123 | - throw new ERR_INVALID_ARG_VALUE('args', args); | ||
| 124 | - } else if (!ArrayIsArray(args)) { | ||
| 124 | + } else if (typeof args === 'object' && !ArrayIsArray(args)) { | ||
| 125 | 125 | options = args; | |
| 126 | 126 | args = []; | |
| 127 | + } else { | ||
| 128 | + validateArray(args, 'args'); | ||
| 127 | 129 | } | |
| 128 | 130 | ||
| 129 | - if (options == null) { | ||
| 130 | - options = {}; | ||
| 131 | - } else if (typeof options !== 'object') { | ||
| 132 | - throw new ERR_INVALID_ARG_VALUE('options', options); | ||
| 133 | - } else { | ||
| 134 | - options = { ...options }; | ||
| 131 | + if (options != null) { | ||
| 132 | + validateObject(options, 'options'); | ||
| 135 | 133 | } | |
| 134 | + options = { ...options, shell: false }; | ||
| 135 | + options.execPath = options.execPath || process.execPath; | ||
| 136 | 136 | ||
| 137 | 137 | // Prepare arguments for fork: | |
| 138 | 138 | execArgv = options.execArgv || process.execArgv; | |
@@ -160,9 +160,6 @@ function fork(modulePath, args = [], options) { | |||
| 160 | 160 | throw new ERR_CHILD_PROCESS_IPC_REQUIRED('options.stdio'); | |
| 161 | 161 | } | |
| 162 | 162 | ||
| 163 | - options.execPath = options.execPath || process.execPath; | ||
| 164 | - options.shell = false; | ||
| 165 | - | ||
| 166 | 163 | return spawn(options.execPath, args, options); | |
| 167 | 164 | } | |
| 168 | 165 | ||
@@ -276,33 +273,25 @@ ObjectDefineProperty(exec, promisify.custom, { | |||
| 276 | 273 | * @returns {ChildProcess} | |
| 277 | 274 | */ | |
| 278 | 275 | function execFile(file, args = [], options, callback) { | |
| 279 | - if (args == null) { | ||
| 280 | - args = []; | ||
| 281 | - } else if (typeof args === 'object') { | ||
| 282 | - if (!ArrayIsArray(args)) { | ||
| 283 | - callback = options; | ||
| 284 | - options = args; | ||
| 285 | - args = []; | ||
| 286 | - } | ||
| 276 | + if (args != null && typeof args === 'object' && !ArrayIsArray(args)) { | ||
| 277 | + callback = options; | ||
| 278 | + options = args; | ||
| 279 | + args = null; | ||
| 287 | 280 | } else if (typeof args === 'function') { | |
| 288 | 281 | callback = args; | |
| 289 | - options = {}; | ||
| 290 | - args = []; | ||
| 291 | - } else { | ||
| 292 | - throw new ERR_INVALID_ARG_VALUE('args', args); | ||
| 282 | + options = null; | ||
| 283 | + args = null; | ||
| 293 | 284 | } | |
| 294 | 285 | ||
| 295 | - if (options == null) { | ||
| 296 | - options = {}; | ||
| 297 | - } else if (typeof options === 'function') { | ||
| 286 | + if (typeof options === 'function') { | ||
| 298 | 287 | callback = options; | |
| 299 | - options = {}; | ||
| 300 | - } else if (typeof options !== 'object') { | ||
| 301 | - throw new ERR_INVALID_ARG_VALUE('options', options); | ||
| 288 | + options = null; | ||
| 289 | + } else if (options != null) { | ||
| 290 | + validateObject(options, 'options'); | ||
| 302 | 291 | } | |
| 303 | 292 | ||
| 304 | - if (callback && typeof callback !== 'function') { | ||
| 305 | - throw new ERR_INVALID_ARG_VALUE('callback', callback); | ||
| 293 | + if (callback != null) { | ||
| 294 | + validateFunction(callback, 'callback'); | ||
| 306 | 295 | } | |
| 307 | 296 | ||
| 308 | 297 | options = { | |
@@ -391,7 +380,7 @@ function execFile(file, args = [], options, callback) { | |||
| 391 | 380 | return; | |
| 392 | 381 | } | |
| 393 | 382 | ||
| 394 | - if (args.length !== 0) | ||
| 383 | + if (args?.length) | ||
| 395 | 384 | cmd += ` ${ArrayPrototypeJoin(args, ' ')}`; | |
| 396 | 385 | ||
| 397 | 386 | if (!ex) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -54,7 +54,7 @@ const expectedEnv = { foo: 'bar' }; | |||
| 54 | 54 | fork(fixtures.path('child-process-echo-options.js'), arg); | |
| 55 | 55 | }, | |
| 56 | 56 | { | |
| 57 | - code: 'ERR_INVALID_ARG_VALUE', | ||
| 57 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 58 | 58 | name: 'TypeError' | |
| 59 | 59 | } | |
| 60 | 60 | ); | |
@@ -97,7 +97,7 @@ const expectedEnv = { foo: 'bar' }; | |||
| 97 | 97 | fork(fixtures.path('child-process-echo-options.js'), [], arg); | |
| 98 | 98 | }, | |
| 99 | 99 | { | |
| 100 | - code: 'ERR_INVALID_ARG_VALUE', | ||
| 100 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 101 | 101 | name: 'TypeError' | |
| 102 | 102 | } | |
| 103 | 103 | ); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -106,10 +106,10 @@ spawn(cmd, u, o); | |||
| 106 | 106 | spawn(cmd, n, o); | |
| 107 | 107 | spawn(cmd, a, u); | |
| 108 | 108 | ||
| 109 | - assert.throws(function() { spawn(cmd, a, n); }, invalidArgTypeError); | ||
| 110 | - | ||
| 111 | - assert.throws(function() { spawn(cmd, s); }, invalidArgTypeError); | ||
| 112 | - assert.throws(function() { spawn(cmd, a, s); }, invalidArgTypeError); | ||
| 109 | + assert.throws(() => { spawn(cmd, a, n); }, invalidArgTypeError); | ||
| 110 | + assert.throws(() => { spawn(cmd, s); }, invalidArgTypeError); | ||
| 111 | + assert.throws(() => { spawn(cmd, a, s); }, invalidArgTypeError); | ||
| 112 | + assert.throws(() => { spawn(cmd, a, a); }, invalidArgTypeError); | ||
| 113 | 113 | ||
| 114 | 114 | ||
| 115 | 115 | // Verify that execFile has same argument parsing behavior as spawn. | |
@@ -158,17 +158,18 @@ execFile(cmd, c, n); | |||
| 158 | 158 | // String is invalid in arg position (this may seem strange, but is | |
| 159 | 159 | // consistent across node API, cf. `net.createServer('not options', 'not | |
| 160 | 160 | // callback')`. | |
| 161 | - assert.throws(function() { execFile(cmd, s, o, c); }, invalidArgValueError); | ||
| 162 | - assert.throws(function() { execFile(cmd, a, s, c); }, invalidArgValueError); | ||
| 163 | - assert.throws(function() { execFile(cmd, a, o, s); }, invalidArgValueError); | ||
| 164 | - assert.throws(function() { execFile(cmd, a, s); }, invalidArgValueError); | ||
| 165 | - assert.throws(function() { execFile(cmd, o, s); }, invalidArgValueError); | ||
| 166 | - assert.throws(function() { execFile(cmd, u, u, s); }, invalidArgValueError); | ||
| 167 | - assert.throws(function() { execFile(cmd, n, n, s); }, invalidArgValueError); | ||
| 168 | - assert.throws(function() { execFile(cmd, a, u, s); }, invalidArgValueError); | ||
| 169 | - assert.throws(function() { execFile(cmd, a, n, s); }, invalidArgValueError); | ||
| 170 | - assert.throws(function() { execFile(cmd, u, o, s); }, invalidArgValueError); | ||
| 171 | - assert.throws(function() { execFile(cmd, n, o, s); }, invalidArgValueError); | ||
| 161 | + assert.throws(() => { execFile(cmd, s, o, c); }, invalidArgTypeError); | ||
| 162 | + assert.throws(() => { execFile(cmd, a, s, c); }, invalidArgTypeError); | ||
| 163 | + assert.throws(() => { execFile(cmd, a, o, s); }, invalidArgTypeError); | ||
| 164 | + assert.throws(() => { execFile(cmd, a, s); }, invalidArgTypeError); | ||
| 165 | + assert.throws(() => { execFile(cmd, o, s); }, invalidArgTypeError); | ||
| 166 | + assert.throws(() => { execFile(cmd, u, u, s); }, invalidArgTypeError); | ||
| 167 | + assert.throws(() => { execFile(cmd, n, n, s); }, invalidArgTypeError); | ||
| 168 | + assert.throws(() => { execFile(cmd, a, u, s); }, invalidArgTypeError); | ||
| 169 | + assert.throws(() => { execFile(cmd, a, n, s); }, invalidArgTypeError); | ||
| 170 | + assert.throws(() => { execFile(cmd, u, o, s); }, invalidArgTypeError); | ||
| 171 | + assert.throws(() => { execFile(cmd, n, o, s); }, invalidArgTypeError); | ||
| 172 | + assert.throws(() => { execFile(cmd, a, a); }, invalidArgTypeError); | ||
| 172 | 173 | ||
| 173 | 174 | execFile(cmd, c, s); // Should not throw. | |
| 174 | 175 | ||
@@ -190,5 +191,6 @@ fork(empty, n, n); | |||
| 190 | 191 | fork(empty, n, o); | |
| 191 | 192 | fork(empty, a, n); | |
| 192 | 193 | ||
| 193 | - assert.throws(function() { fork(empty, s); }, invalidArgValueError); | ||
| 194 | - assert.throws(function() { fork(empty, a, s); }, invalidArgValueError); | ||
| 194 | + assert.throws(() => { fork(empty, s); }, invalidArgTypeError); | ||
| 195 | + assert.throws(() => { fork(empty, a, s); }, invalidArgTypeError); | ||
| 196 | + assert.throws(() => { fork(empty, a, a); }, invalidArgTypeError); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments