1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 15:49:44 -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 GitHub
parent fe0d9e078f
commit 0209f7b469
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 21 deletions

View file

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

View file

@ -17,17 +17,7 @@ import {
validateInteger,
validateObject,
} from "ext:deno_node/internal/validators.mjs";
const previewEntries = (iter, isKeyValue) => {
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 { previewEntries } from "ext:deno_node/internal_binding/util.ts";
import { Buffer } from "node:buffer";
const { isBuffer } = Buffer;
import {
@ -475,7 +465,6 @@ const consoleMethods = {
// https://console.spec.whatwg.org/#table
table(tabularData, properties) {
console.log("tabularData", tabularData);
if (properties !== undefined) {
validateArray(properties, "properties");
}

View file

@ -129,3 +129,18 @@ export function getOwnNonIndexProperties(
}
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];
}
}