summaryrefslogtreecommitdiff
path: root/cli/js
diff options
context:
space:
mode:
Diffstat (limited to 'cli/js')
-rw-r--r--cli/js/tests/console_test.ts13
-rw-r--r--cli/js/web/console.ts57
2 files changed, 49 insertions, 21 deletions
diff --git a/cli/js/tests/console_test.ts b/cli/js/tests/console_test.ts
index 256c7da80..b64016078 100644
--- a/cli/js/tests/console_test.ts
+++ b/cli/js/tests/console_test.ts
@@ -163,10 +163,14 @@ unitTest(function consoleTestStringifyCircular(): void {
"{ a: { b: { c: { d: [Set] } } } }"
);
assertEquals(stringify(nestedObj), nestedObjExpected);
- assertEquals(stringify(JSON), "{}");
+ assertEquals(stringify(JSON), 'JSON { Symbol(Symbol.toStringTag): "JSON" }');
assertEquals(
stringify(console),
- "{ printFunc, log, debug, info, dir, dirxml, warn, error, assert, count, countReset, table, time, timeLog, timeEnd, group, groupCollapsed, groupEnd, clear, trace, indentLevel }"
+ "{ printFunc, log, debug, info, dir, dirxml, warn, error, assert, count, countReset, table, time, timeLog, timeEnd, group, groupCollapsed, groupEnd, clear, trace, indentLevel, Symbol(isConsoleInstance) }"
+ );
+ assertEquals(
+ stringify({ str: 1, [Symbol.for("sym")]: 2, [Symbol.toStringTag]: "TAG" }),
+ 'TAG { str: 1, Symbol(sym): 2, Symbol(Symbol.toStringTag): "TAG" }'
);
// test inspect is working the same
assertEquals(inspect(nestedObj), nestedObjExpected);
@@ -224,7 +228,10 @@ unitTest(function consoleTestWithCustomInspectorError(): void {
}
assertEquals(stringify(new B({ a: "a" })), "a");
- assertEquals(stringify(B.prototype), "{}");
+ assertEquals(
+ stringify(B.prototype),
+ "{ Symbol(Deno.customInspect): [Function: [Deno.customInspect]] }"
+ );
});
unitTest(function consoleTestWithIntegerFormatSpecifier(): void {
diff --git a/cli/js/web/console.ts b/cli/js/web/console.ts
index 7f79dd255..0812a4e21 100644
--- a/cli/js/web/console.ts
+++ b/cli/js/web/console.ts
@@ -286,24 +286,45 @@ function createRawObjectString(
let baseString = "";
- const className = getClassInstanceName(value);
- let shouldShowClassName = false;
- if (className && className !== "Object" && className !== "anonymous") {
- shouldShowClassName = true;
+ let shouldShowDisplayName = false;
+ // @ts-ignore
+ let displayName = value[Symbol.toStringTag];
+ if (!displayName) {
+ displayName = getClassInstanceName(value);
}
- const keys = Object.keys(value);
- const entries: string[] = keys.map((key): string => {
- if (keys.length > OBJ_ABBREVIATE_SIZE) {
- return key;
- } else {
- return `${key}: ${stringifyWithQuotes(
- value[key],
- ctx,
- level + 1,
- maxLevel
- )}`;
+ if (displayName && displayName !== "Object" && displayName !== "anonymous") {
+ shouldShowDisplayName = true;
+ }
+
+ const entries: string[] = [];
+ const stringKeys = Object.keys(value);
+ const symbolKeys = Object.getOwnPropertySymbols(value);
+ const numKeys = stringKeys.length + symbolKeys.length;
+ if (numKeys > OBJ_ABBREVIATE_SIZE) {
+ for (const key of stringKeys) {
+ entries.push(key);
}
- });
+ for (const key of symbolKeys) {
+ entries.push(key.toString());
+ }
+ } else {
+ for (const key of stringKeys) {
+ entries.push(
+ `${key}: ${stringifyWithQuotes(value[key], ctx, level + 1, maxLevel)}`
+ );
+ }
+ for (const key of symbolKeys) {
+ entries.push(
+ `${key.toString()}: ${stringifyWithQuotes(
+ // @ts-ignore
+ value[key],
+ ctx,
+ level + 1,
+ maxLevel
+ )}`
+ );
+ }
+ }
ctx.delete(value);
@@ -313,8 +334,8 @@ function createRawObjectString(
baseString = `{ ${entries.join(", ")} }`;
}
- if (shouldShowClassName) {
- baseString = `${className} ${baseString}`;
+ if (shouldShowDisplayName) {
+ baseString = `${displayName} ${baseString}`;
}
return baseString;