From dd62456e22c55c85cfdf3a7d32b132bd3e66ea74 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Fri, 18 Apr 2025 03:05:42 +0800 Subject: [PATCH] child_process: give names to promisified `exec()` and `execFile()` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/57916 Reviewed-By: Antoine du Hamel Reviewed-By: Vinícius Lourenço Claro Cardoso Reviewed-By: James M Snell --- lib/child_process.js | 5 +++-- test/parallel/test-util-promisify-custom-names.mjs | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/child_process.js b/lib/child_process.js index 5c853716a26..21616c69f87 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -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, { diff --git a/test/parallel/test-util-promisify-custom-names.mjs b/test/parallel/test-util-promisify-custom-names.mjs index 3ff05d907b5..79da972ae20 100644 --- a/test/parallel/test-util-promisify-custom-names.mjs +++ b/test/parallel/test-util-promisify-custom-names.mjs @@ -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' +);