Skip to content

Commit

Permalink
util: support AsyncGeneratorFunction in .inspect
Browse files Browse the repository at this point in the history
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 committed Jun 17, 2019
1 parent b690e19 commit f897860
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit f897860

Please sign in to comment.