From a23c2308a768033dbbf5ed4b3e14359ba970cedc Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sun, 2 Jun 2019 16:44:21 +0200 Subject: [PATCH] util: support AsyncGeneratorFunction in .inspect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes sure async generator functions are properly detected while using `util.inspect`. PR-URL: https://github.com/nodejs/node/pull/28056 Reviewed-By: Anna Henningsen Reviewed-By: Michaƫl Zasso Reviewed-By: Yongsheng Zhang Reviewed-By: Benjamin Gruenbaum Reviewed-By: Tiancheng "Timothy" Gu Reviewed-By: Colin Ihrig Reviewed-By: Trivikram Kamat Reviewed-By: Rich Trott --- lib/internal/util/inspect.js | 7 ++++--- test/parallel/test-util-inspect.js | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index 8735c40ac013be..45839292602c44 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -870,10 +870,11 @@ function getBoxedBase(value, ctx, keys, constructor, tag) { function getFunctionBase(value, constructor, tag) { let type = 'Function'; + if (isGeneratorFunction(value)) { + type = `Generator${type}`; + } if (isAsyncFunction(value)) { - type = 'AsyncFunction'; - } else if (isGeneratorFunction(value)) { - type = 'GeneratorFunction'; + type = `Async${type}`; } let base = `[${type}`; if (constructor === null) { diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index f9566df48a1fde..7a7c5287fb2810 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -48,6 +48,10 @@ assert.strictEqual(util.inspect(async () => {}), '[AsyncFunction (anonymous)]'); util.inspect(fn), '[GeneratorFunction (anonymous)]' ); + assert.strictEqual( + util.inspect(async function* abc() {}), + '[AsyncGeneratorFunction: abc]' + ); Object.setPrototypeOf(fn, Object.getPrototypeOf(async () => {})); assert.strictEqual( util.inspect(fn),