summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Kettmeir <crowlkats@toaxl.com>2023-11-28 16:07:48 +0100
committerGitHub <noreply@github.com>2023-11-28 16:07:48 +0100
commit32c041c8d7c5d72d4c1850f1fd6f3f38b530a16c (patch)
treea3c25d4bd887935b8f67732acc4cc081695c19ee
parentbe4cd5eebf20d4495f7e3bff8e14ca22dd015659 (diff)
Reland "fix(ext/console): fix inspecting iterators error. (#20720)" (#21370)
-rw-r--r--ext/console/01_console.js33
-rw-r--r--ext/node/polyfills/internal/console/constructor.mjs13
-rw-r--r--ext/node/polyfills/internal_binding/util.ts2
3 files changed, 25 insertions, 23 deletions
diff --git a/ext/console/01_console.js b/ext/console/01_console.js
index 67c75f74d..9c199aa59 100644
--- a/ext/console/01_console.js
+++ b/ext/console/01_console.js
@@ -12,6 +12,7 @@ const {
ArrayBufferPrototypeGetByteLength,
ArrayIsArray,
ArrayPrototypeFill,
+ ArrayPrototypeConcat,
ArrayPrototypeFilter,
ArrayPrototypeFind,
ArrayPrototypeForEach,
@@ -41,6 +42,7 @@ const {
FunctionPrototypeBind,
FunctionPrototypeCall,
FunctionPrototypeToString,
+ NumberIsNaN,
MapPrototype,
MapPrototypeDelete,
MapPrototypeEntries,
@@ -134,9 +136,24 @@ const {
Uint8Array,
WeakMapPrototypeHas,
WeakSetPrototypeHas,
- isNaN,
} = primordials;
+// supposed to be in node/internal_binding/util.ts
+export function previewEntries(iter, isKeyValue) {
+ if (isKeyValue) {
+ // deno-lint-ignore prefer-primordials
+ const arr = [...iter];
+ if (ArrayIsArray(arr[0]) && arr[0].length === 2) {
+ // deno-lint-ignore prefer-primordials
+ return [ArrayPrototypeConcat([], ...arr), true];
+ }
+ return [arr, false];
+ } else {
+ // deno-lint-ignore prefer-primordials
+ return [...iter];
+ }
+}
+
let noColor = () => false;
function setNoColorFn(fn) {
@@ -950,7 +967,7 @@ function formatRaw(ctx, value, recurseTimes, typedArray, proxyDetails) {
}
} else if (ObjectPrototypeIsPrototypeOf(DatePrototype, value)) {
const date = proxyDetails ? proxyDetails[0] : value;
- if (isNaN(DatePrototypeGetTime(date))) {
+ if (NumberIsNaN(DatePrototypeGetTime(date))) {
return ctx.stylize("Invalid Date", "date");
} else {
base = DatePrototypeToISOString(date);
@@ -1493,9 +1510,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 +1719,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);
}
diff --git a/ext/node/polyfills/internal/console/constructor.mjs b/ext/node/polyfills/internal/console/constructor.mjs
index 5ea9eeb3a..afa18bb97 100644
--- a/ext/node/polyfills/internal/console/constructor.mjs
+++ b/ext/node/polyfills/internal/console/constructor.mjs
@@ -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");
}
diff --git a/ext/node/polyfills/internal_binding/util.ts b/ext/node/polyfills/internal_binding/util.ts
index 38eeebee0..59f1246fc 100644
--- a/ext/node/polyfills/internal_binding/util.ts
+++ b/ext/node/polyfills/internal_binding/util.ts
@@ -129,3 +129,5 @@ export function getOwnNonIndexProperties(
}
return result;
}
+
+export { previewEntries } from "ext:deno_console/01_console.js";