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 <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Yongsheng Zhang <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • 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.