Avoid Uint8Array.prototype throwing type error in console.log (#1327)

This commit is contained in:
Kevin (Kun) "Kassimo" Qian 2018-12-12 02:32:24 -05:00 committed by Ryan Dahl
parent 585de35b1d
commit 8502cb0ccb
2 changed files with 7 additions and 3 deletions

View file

@ -63,9 +63,12 @@ function createIterableString(
ctx.add(value);
const entries: string[] = [];
// In cases e.g. Uint8Array.prototype
try {
for (const el of value) {
entries.push(config.entryHandler(el, ctx, level + 1, maxLevel));
}
} catch (e) {}
ctx.delete(value);
const iPrefix = `${config.displayName ? config.displayName + " " : ""}`;
const iContent = entries.length === 0 ? "" : ` ${entries.join(", ")} `;

View file

@ -103,6 +103,7 @@ test(function consoleTestStringifyCircular() {
"[AsyncGeneratorFunction: agf]"
);
assertEqual(stringify(new Uint8Array([1, 2, 3])), "Uint8Array [ 1, 2, 3 ]");
assertEqual(stringify(Uint8Array.prototype), "TypedArray []");
assertEqual(
stringify({ a: { b: { c: { d: new Set([1]) } } } }),
"{ a: { b: { c: { d: [Set] } } } }"