summaryrefslogtreecommitdiff
path: root/ext/console/02_console.js
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2023-03-23 10:01:07 -0400
committerGitHub <noreply@github.com>2023-03-23 10:01:07 -0400
commita3529d02329e0d2127ad2a5bb78b4c476ddd6984 (patch)
treee49cbc9ba875c963daa8333bda4bc44b2c1b5300 /ext/console/02_console.js
parent64602e70271750c5420d53f2189bf1286ce13fba (diff)
refactor(ext/node): Use Deno.inspect (#17960)
No need for two almost identical implementations of the same thing --------- Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com> Co-authored-by: Aapo Alasuutari <aapo.alasuutari@gmail.com>
Diffstat (limited to 'ext/console/02_console.js')
-rw-r--r--ext/console/02_console.js13
1 files changed, 12 insertions, 1 deletions
diff --git a/ext/console/02_console.js b/ext/console/02_console.js
index 8c33ac3bc..295fef4c3 100644
--- a/ext/console/02_console.js
+++ b/ext/console/02_console.js
@@ -204,7 +204,7 @@ function isFullWidthCodePoint(code) {
);
}
-function getStringWidth(str) {
+export function getStringWidth(str) {
str = StringPrototypeNormalize(colors.stripColor(str), "NFC");
let width = 0;
@@ -1334,6 +1334,16 @@ function inspectObject(value, inspectOptions, proxyDetails) {
) {
return String(value[customInspect](inspect, inspectOptions));
}
+ if (
+ ReflectHas(value, nodeCustomInspect) &&
+ typeof value[nodeCustomInspect] === "function"
+ ) {
+ // TODO(kt3k): The last inspect needs to be util.inspect of Node.js.
+ // We need to move the implementation of util.inspect to this file.
+ return String(
+ value[nodeCustomInspect](inspectOptions.depth, inspectOptions, inspect),
+ );
+ }
// This non-unique symbol is used to support op_crates, ie.
// in extensions/web we don't want to depend on public
// Symbol.for("Deno.customInspect") symbol defined in the public API.
@@ -2310,6 +2320,7 @@ class Console {
}
const customInspect = SymbolFor("Deno.customInspect");
+const nodeCustomInspect = SymbolFor("nodejs.util.inspect.custom");
function inspect(
value,