From 867f79c5ab6322e76c8ed03238c2cdba69b451c8 Mon Sep 17 00:00:00 2001 From: catloversg <152669316+catloversg@users.noreply.github.com> Date: Tue, 22 Oct 2024 10:37:40 +0700 Subject: [PATCH] API: Improve built-in print APIs when printing Promise objects (#1710) --- src/Netscript/NetscriptHelpers.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Netscript/NetscriptHelpers.tsx b/src/Netscript/NetscriptHelpers.tsx index cd2ff6014..341319da5 100644 --- a/src/Netscript/NetscriptHelpers.tsx +++ b/src/Netscript/NetscriptHelpers.tsx @@ -256,7 +256,16 @@ function argsToString(args: unknown[]): string { return (out += `< Set: ${[...nativeArg].join("; ")} >`); } 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}`);