1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-08 07:08:27 -05:00

fix(ext/console): fix inspecting iterators error. (#20720)

Fixes #19776 and #20676.
This commit is contained in:
Chen Su 2023-11-14 03:13:20 +08:00 committed by Yoshiya Hinosawa
parent 9b07557bfb
commit 7e19fee4c4
No known key found for this signature in database
GPG key ID: 9017DB4559488785
3 changed files with 20 additions and 21 deletions

View file

@ -136,6 +136,7 @@ const {
WeakSetPrototypeHas, WeakSetPrototypeHas,
isNaN, isNaN,
} = primordials; } = primordials;
import { previewEntries } from "ext:deno_node/internal_binding/util.ts";
let noColor = () => false; let noColor = () => false;
@ -1493,9 +1494,7 @@ function getIteratorBraces(type, tag) {
const iteratorRegExp = new SafeRegExp(" Iterator] {$"); const iteratorRegExp = new SafeRegExp(" Iterator] {$");
function formatIterator(braces, ctx, value, recurseTimes) { function formatIterator(braces, ctx, value, recurseTimes) {
// TODO(wafuwafu13): Implement const { 0: entries, 1: isKeyValue } = previewEntries(value, true);
// const { 0: entries, 1: isKeyValue } = previewEntries(value, true);
const { 0: entries, 1: isKeyValue } = value;
if (isKeyValue) { if (isKeyValue) {
// Mark entry iterators as such. // Mark entry iterators as such.
braces[0] = StringPrototypeReplace( braces[0] = StringPrototypeReplace(
@ -1704,16 +1703,12 @@ function formatWeakCollection(ctx) {
} }
function formatWeakSet(ctx, value, recurseTimes) { function formatWeakSet(ctx, value, recurseTimes) {
// TODO(wafuwafu13): Implement const entries = previewEntries(value);
// const entries = previewEntries(value);
const entries = value;
return formatSetIterInner(ctx, recurseTimes, entries, kWeak); return formatSetIterInner(ctx, recurseTimes, entries, kWeak);
} }
function formatWeakMap(ctx, value, recurseTimes) { function formatWeakMap(ctx, value, recurseTimes) {
// TODO(wafuwafu13): Implement const entries = previewEntries(value);
// const entries = previewEntries(value);
const entries = value;
return formatMapIterInner(ctx, recurseTimes, entries, kWeak); return formatMapIterInner(ctx, recurseTimes, entries, kWeak);
} }

View file

@ -17,17 +17,7 @@ import {
validateInteger, validateInteger,
validateObject, validateObject,
} from "ext:deno_node/internal/validators.mjs"; } from "ext:deno_node/internal/validators.mjs";
const previewEntries = (iter, isKeyValue) => { import { previewEntries } from "ext:deno_node/internal_binding/util.ts";
if (isKeyValue) {
const arr = [...iter];
if (Array.isArray(arr[0]) && arr[0].length === 2) {
return [[].concat(...arr), true];
}
return [arr, false];
} else {
return [...iter];
}
};
import { Buffer } from "node:buffer"; import { Buffer } from "node:buffer";
const { isBuffer } = Buffer; const { isBuffer } = Buffer;
import { import {
@ -475,7 +465,6 @@ const consoleMethods = {
// https://console.spec.whatwg.org/#table // https://console.spec.whatwg.org/#table
table(tabularData, properties) { table(tabularData, properties) {
console.log("tabularData", tabularData);
if (properties !== undefined) { if (properties !== undefined) {
validateArray(properties, "properties"); validateArray(properties, "properties");
} }

View file

@ -129,3 +129,18 @@ export function getOwnNonIndexProperties(
} }
return result; return result;
} }
export function previewEntries(
iter: Iterable<unknown>,
isKeyValue?: boolean,
): Array<unknown | boolean> {
if (isKeyValue) {
const arr = [...iter];
if (Array.isArray(arr[0]) && arr[0].length === 2) {
return [([] as unknown[]).concat(...arr), true];
}
return [arr, false];
} else {
return [...iter];
}
}