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 <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>
1 parent b690e19 commit f897860

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

‎lib/internal/util/inspect.js‎

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

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

‎test/parallel/test-util-inspect.js‎

Lines changed: 4 additions & 0 deletions
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(asyncfunction*abc(){}),
53+
'[AsyncGeneratorFunction: abc]'
54+
);
5155
Object.setPrototypeOf(fn,Object.getPrototypeOf(async()=>{}));
5256
assert.strictEqual(
5357
util.inspect(fn),

0 commit comments

Comments
 (0)