1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-29 16:30:56 -05:00

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); ctx.add(value);
const entries: string[] = []; const entries: string[] = [];
// In cases e.g. Uint8Array.prototype
try {
for (const el of value) { for (const el of value) {
entries.push(config.entryHandler(el, ctx, level + 1, maxLevel)); entries.push(config.entryHandler(el, ctx, level + 1, maxLevel));
} }
} catch (e) {}
ctx.delete(value); ctx.delete(value);
const iPrefix = `${config.displayName ? config.displayName + " " : ""}`; const iPrefix = `${config.displayName ? config.displayName + " " : ""}`;
const iContent = entries.length === 0 ? "" : ` ${entries.join(", ")} `; const iContent = entries.length === 0 ? "" : ` ${entries.join(", ")} `;

View file

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