API: Improve built-in print APIs when printing Promise objects (#1710)

This commit is contained in:
catloversg 2024-10-22 10:37:40 +07:00 committed by GitHub
parent bc51733fbe
commit 867f79c5ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -256,7 +256,16 @@ function argsToString(args: unknown[]): string {
return (out += `< Set: ${[...nativeArg].join("; ")} >`); return (out += `< Set: ${[...nativeArg].join("; ")} >`);
} }
if (typeof nativeArg === "object") { if (typeof nativeArg === "object") {
return (out += JSON.stringify(nativeArg)); return (out += JSON.stringify(nativeArg, (_, value) => {
/**
* If the property is a promise, we will return a string that clearly states that it's a promise object, not a
* normal object. If we don't do that, all promises will be serialized into "{}".
*/
if (value instanceof Promise) {
return value.toString();
}
return value;
}));
} }
return (out += `${nativeArg}`); return (out += `${nativeArg}`);