Skip to content
Permalink
Browse files

util: support AsyncGeneratorFunction in .inspect

This makes sure async generator functions are properly detected while
using `util.inspect`.

PR-URL: #28056
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information...
BridgeAR authored and Trott committed Jun 2, 2019
1 parent be721e8 commit a23c2308a768033dbbf5ed4b3e14359ba970cedc
Showing with 8 additions and 3 deletions.
  1. +4 −3 lib/internal/util/inspect.js
  2. +4 −0 test/parallel/test-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) {
@@ -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),

0 comments on commit a23c230

Please sign in to comment.
You can’t perform that action at this time.