Skip to content

Commit

Permalink
fix(ext/console): fix inspecting iterators error. (denoland#20720)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghosind authored Nov 13, 2023
1 parent fe0d9e0 commit 0209f7b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
13 changes: 4 additions & 9 deletions ext/console/01_console.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ const {
WeakSetPrototypeHas,
isNaN,
} = primordials;
import { previewEntries } from "ext:deno_node/internal_binding/util.ts";

let noColor = () => false;

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
}

Expand Down
13 changes: 1 addition & 12 deletions ext/node/polyfills/internal/console/constructor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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");
}
Expand Down
15 changes: 15 additions & 0 deletions ext/node/polyfills/internal_binding/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}

0 comments on commit 0209f7b

Please sign in to comment.