From f8978604271bcb752ea65172d6645d44f00de822 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 b32529b8c071dd..59236853cc6c72 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -847,10 +847,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 7133cc59acba41..80a612ede53050 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]'); util.inspect(fn), '[GeneratorFunction]' ); + assert.strictEqual( + util.inspect(async function* abc() {}), + '[AsyncGeneratorFunction: abc]' + ); Object.setPrototypeOf(fn, Object.getPrototypeOf(async () => {})); assert.strictEqual( util.inspect(fn),