child_process: give names to promisified exec() and execFile()

PR-URL: https://github.com/nodejs/node/pull/57916
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
LiviaMedeiros 2025-04-18 03:05:42 +08:00 committed by Node.js GitHub Bot
parent 40a657b330
commit dd62456e22
2 changed files with 13 additions and 2 deletions

View File

@ -47,6 +47,7 @@ const {
} = primordials;
const {
assignFunctionName,
convertToValidSignal,
getSystemErrorName,
kEmptyObject,
@ -236,7 +237,7 @@ function exec(command, options, callback) {
}
const customPromiseExecFunction = (orig) => {
return (...args) => {
return assignFunctionName(orig.name, function(...args) {
const { promise, resolve, reject } = PromiseWithResolvers();
promise.child = orig(...args, (err, stdout, stderr) => {
@ -250,7 +251,7 @@ const customPromiseExecFunction = (orig) => {
});
return promise;
};
});
};
ObjectDefineProperty(exec, promisify.custom, {

View File

@ -9,6 +9,7 @@ import fs from 'node:fs';
import readline from 'node:readline';
import stream from 'node:stream';
import timers from 'node:timers';
import child_process from 'node:child_process';
assert.strictEqual(
@ -38,3 +39,12 @@ assert.strictEqual(
promisify(timers.setTimeout).name,
'setTimeout'
);
assert.strictEqual(
promisify(child_process.exec).name,
'exec'
);
assert.strictEqual(
promisify(child_process.execFile).name,
'execFile'
);