diff options
-rw-r--r-- | cli/tests/unit/console_test.ts | 3 | ||||
-rw-r--r-- | ext/console/02_console.js | 27 |
2 files changed, 29 insertions, 1 deletions
diff --git a/cli/tests/unit/console_test.ts b/cli/tests/unit/console_test.ts index 8472e5c94..b5dcf2f05 100644 --- a/cli/tests/unit/console_test.ts +++ b/cli/tests/unit/console_test.ts @@ -259,6 +259,8 @@ unitTest(function consoleTestStringifyCircular() { assertEquals(stringify("s"), "s"); assertEquals(stringify(false), "false"); assertEquals(stringify(new Number(1)), "[Number: 1]"); + assertEquals(stringify(new Number(-0)), "[Number: -0]"); + assertEquals(stringify(Object(1n)), "[BigInt: 1n]"); assertEquals(stringify(new Boolean(true)), "[Boolean: true]"); assertEquals(stringify(new String("deno")), `[String: "deno"]`); assertEquals(stringify(/[0-9]*/), "/[0-9]*/"); @@ -279,6 +281,7 @@ unitTest(function consoleTestStringifyCircular() { assertEquals(stringify(new WeakSet()), "WeakSet { [items unknown] }"); assertEquals(stringify(new WeakMap()), "WeakMap { [items unknown] }"); assertEquals(stringify(Symbol(1)), `Symbol("1")`); + assertEquals(stringify(Object(Symbol(1))), `[Symbol: Symbol("1")]`); assertEquals(stringify(null), "null"); assertEquals(stringify(undefined), "undefined"); assertEquals(stringify(new Extended()), "Extended { a: 1, b: 2 }"); diff --git a/ext/console/02_console.js b/ext/console/02_console.js index e88b67ed2..09d96fc09 100644 --- a/ext/console/02_console.js +++ b/ext/console/02_console.js @@ -53,6 +53,7 @@ SetPrototypeEntries, Symbol, SymbolPrototypeToString, + SymbolPrototypeValueOf, SymbolToStringTag, SymbolHasInstance, SymbolFor, @@ -88,6 +89,9 @@ MathFloor, Number, NumberPrototypeToString, + NumberPrototypeValueOf, + BigInt, + BigIntPrototypeToString, Proxy, ReflectGet, ReflectGetOwnPropertyDescriptor, @@ -891,7 +895,24 @@ function inspectNumberObject(value, inspectOptions) { const cyan = maybeColor(colors.cyan, inspectOptions); - return cyan(`[Number: ${NumberPrototypeToString(value)}]`); // wrappers are in cyan + // Special handling of -0 + return cyan( + `[Number: ${ + ObjectIs(NumberPrototypeValueOf(value), -0) + ? "-0" + : NumberPrototypeToString(value) + }]`, + ); // wrappers are in cyan + } + + function inspectBigIntObject(value, inspectOptions) { + const cyan = maybeColor(colors.cyan, inspectOptions); + return cyan(`[BigInt: ${BigIntPrototypeToString(value)}n]`); // wrappers are in cyan + } + + function inspectSymbolObject(value, inspectOptions) { + const cyan = maybeColor(colors.cyan, inspectOptions); + return cyan(`[Symbol: ${maybeQuoteSymbol(SymbolPrototypeValueOf(value))}]`); // wrappers are in cyan } const PromiseState = { @@ -1125,10 +1146,14 @@ return inspectArray(value, level, inspectOptions); } else if (value instanceof Number) { return inspectNumberObject(value, inspectOptions); + } else if (value instanceof BigInt) { + return inspectBigIntObject(value, inspectOptions); } else if (value instanceof Boolean) { return inspectBooleanObject(value, inspectOptions); } else if (value instanceof String) { return inspectStringObject(value, inspectOptions); + } else if (value instanceof Symbol) { + return inspectSymbolObject(value, inspectOptions); } else if (value instanceof Promise) { return inspectPromise(value, level, inspectOptions); } else if (value instanceof RegExp) { |