mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
fix(console): fix display of primitive wrapper objects (#12425)
This commit is contained in:
parent
7a22df9b76
commit
1d55fcb74c
2 changed files with 29 additions and 1 deletions
|
@ -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 }");
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue