Skip to content

Commit f897860

Browse files
committed
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 <[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]>
1 parent b690e19 commit f897860

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

lib/internal/util/inspect.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -847,10 +847,11 @@ function getBoxedBase(value, ctx, keys, constructor, tag) {
847847

848848
function getFunctionBase(value, constructor, tag) {
849849
let type = 'Function';
850+
if (isGeneratorFunction(value)) {
851+
type = `Generator${type}`;
852+
}
850853
if (isAsyncFunction(value)) {
851-
type = 'AsyncFunction';
852-
} else if (isGeneratorFunction(value)) {
853-
type = 'GeneratorFunction';
854+
type = `Async${type}`;
854855
}
855856
let base = `[${type}`;
856857
if (constructor === null) {

test/parallel/test-util-inspect.js

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ assert.strictEqual(util.inspect(async () => {}), '[AsyncFunction]');
4848
util.inspect(fn),
4949
'[GeneratorFunction]'
5050
);
51+
assert.strictEqual(
52+
util.inspect(async function* abc() {}),
53+
'[AsyncGeneratorFunction: abc]'
54+
);
5155
Object.setPrototypeOf(fn, Object.getPrototypeOf(async () => {}));
5256
assert.strictEqual(
5357
util.inspect(fn),

0 commit comments

Comments
 (0)