|
22 | 22 | 'use strict';
|
23 | 23 |
|
24 | 24 | const util = require('util');
|
25 |
| -const { |
26 |
| - deprecate, convertToValidSignal, customPromisifyArgs |
27 |
| -} = require('internal/util'); |
| 25 | +const { deprecate, convertToValidSignal } = require('internal/util'); |
| 26 | +const { createPromise, |
| 27 | + promiseResolve, promiseReject } = process.binding('util'); |
28 | 28 | const debug = util.debuglog('child_process');
|
29 | 29 |
|
30 | 30 | const uv = process.binding('uv');
|
@@ -140,9 +140,27 @@ exports.exec = function(command /*, options, callback*/) {
|
140 | 140 | opts.callback);
|
141 | 141 | };
|
142 | 142 |
|
143 |
| -Object.defineProperty(exports.exec, customPromisifyArgs, |
144 |
| - { value: ['stdout', 'stderr'], enumerable: false }); |
| 143 | +const customPromiseExecFunction = (orig) => { |
| 144 | + return (...args) => { |
| 145 | + const promise = createPromise(); |
145 | 146 |
|
| 147 | + orig(...args, (err, stdout, stderr) => { |
| 148 | + if (err !== null) { |
| 149 | + err.stdout = stdout; |
| 150 | + err.stderr = stderr; |
| 151 | + promiseReject(promise, err); |
| 152 | + } else { |
| 153 | + promiseResolve(promise, { stdout, stderr }); |
| 154 | + } |
| 155 | + }); |
| 156 | + return promise; |
| 157 | + }; |
| 158 | +}; |
| 159 | + |
| 160 | +Object.defineProperty(exports.exec, util.promisify.custom, { |
| 161 | + enumerable: false, |
| 162 | + value: customPromiseExecFunction(exports.exec) |
| 163 | +}); |
146 | 164 |
|
147 | 165 | exports.execFile = function(file /*, args, options, callback*/) {
|
148 | 166 | var args = [];
|
@@ -338,8 +356,10 @@ exports.execFile = function(file /*, args, options, callback*/) {
|
338 | 356 | return child;
|
339 | 357 | };
|
340 | 358 |
|
341 |
| -Object.defineProperty(exports.execFile, customPromisifyArgs, |
342 |
| - { value: ['stdout', 'stderr'], enumerable: false }); |
| 359 | +Object.defineProperty(exports.execFile, util.promisify.custom, { |
| 360 | + enumerable: false, |
| 361 | + value: customPromiseExecFunction(exports.execFile) |
| 362 | +}); |
343 | 363 |
|
344 | 364 | const _deprecatedCustomFds = deprecate(
|
345 | 365 | function deprecateCustomFds(options) {
|
|
0 commit comments