From 7fa1f73a2c002ba9c15e55ffa1d39d237e7713c3 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Wed, 5 May 2021 11:21:27 +0200 Subject: [PATCH] debugger: refactor to use internal modules This avoids loading the entirety of `node:util` and `node:url` and their dependencies while only a subset is actually used by this module. PR-URL: https://github.com/nodejs/node/pull/38550 Backport-PR-URL: https://github.com/nodejs/node/pull/39446 Reviewed-By: James M Snell Reviewed-By: Darshan Sen --- lib/internal/inspector/inspect_repl.js | 33 +++++++++++++------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/internal/inspector/inspect_repl.js b/lib/internal/inspector/inspect_repl.js index 1b829c99061f45..4bb7cd05bd1a30 100644 --- a/lib/internal/inspector/inspect_repl.js +++ b/lib/internal/inspector/inspect_repl.js @@ -6,11 +6,12 @@ const FS = require('fs'); const Path = require('path'); const Repl = require('repl'); -const util = require('util'); const vm = require('vm'); -const fileURLToPath = require('url').fileURLToPath; +const { fileURLToPath } = require('internal/url'); -const debuglog = util.debuglog('inspect'); +const { customInspectSymbol } = require('internal/util'); +const { inspect: utilInspect } = require('internal/util/inspect'); +const debuglog = require('internal/util/debuglog').debuglog('inspect'); const SHORTCUTS = { cont: 'c', @@ -148,12 +149,12 @@ class RemoteObject { } } - [util.inspect.custom](depth, opts) { + [customInspectSymbol](depth, opts) { function formatProperty(prop) { switch (prop.type) { case 'string': case 'undefined': - return util.inspect(prop.value, opts); + return utilInspect(prop.value, opts); case 'number': case 'boolean': @@ -162,7 +163,7 @@ class RemoteObject { case 'object': case 'symbol': if (prop.subtype === 'date') { - return util.inspect(new Date(prop.value), opts); + return utilInspect(new Date(prop.value), opts); } if (prop.subtype === 'array') { return opts.stylize(prop.value, 'special'); @@ -178,7 +179,7 @@ class RemoteObject { case 'number': case 'string': case 'undefined': - return util.inspect(this.value, opts); + return utilInspect(this.value, opts); case 'symbol': return opts.stylize(this.description, 'special'); @@ -192,10 +193,10 @@ class RemoteObject { case 'object': switch (this.subtype) { case 'date': - return util.inspect(new Date(this.description), opts); + return utilInspect(new Date(this.description), opts); case 'null': - return util.inspect(null, opts); + return utilInspect(null, opts); case 'regexp': return opts.stylize(this.description, 'regexp'); @@ -243,11 +244,11 @@ class ScopeSnapshot { this.completionGroup = properties.map((prop) => prop.name); } - [util.inspect.custom](depth, opts) { + [customInspectSymbol](depth, opts) { const type = `${this.type[0].toUpperCase()}${this.type.slice(1)}`; const name = this.name ? `<${this.name}>` : ''; const prefix = `${type}${name} `; - return util.inspect(this.properties, opts) + return utilInspect(this.properties, opts) .replace(/^Map /, prefix); } } @@ -296,7 +297,7 @@ function createRepl(inspector) { const INSPECT_OPTIONS = { colors: inspector.stdout.isTTY }; function inspect(value) { - return util.inspect(value, INSPECT_OPTIONS); + return utilInspect(value, INSPECT_OPTIONS); } function print(value, addNewline = true) { @@ -336,7 +337,7 @@ function createRepl(inspector) { function listScripts(displayNatives = false) { print(formatScripts(displayNatives)); } - listScripts[util.inspect.custom] = function listWithoutInternal() { + listScripts[customInspectSymbol] = function listWithoutInternal() { return formatScripts(); }; @@ -352,7 +353,7 @@ function createRepl(inspector) { return p; } - [util.inspect.custom](depth, { stylize }) { + [customInspectSymbol](depth, { stylize }) { const { startTime, endTime } = this.data; const MU = String.fromChar(956); return stylize(`[Profile ${endTime - startTime}${MU}s]`, 'special'); @@ -373,7 +374,7 @@ function createRepl(inspector) { this.delta = delta; } - [util.inspect.custom](depth, options) { + [customInspectSymbol](depth, options) { const { scriptId, lineNumber, columnNumber, delta, scriptSource } = this; const start = Math.max(1, lineNumber - delta + 1); const end = lineNumber + delta + 1; @@ -439,7 +440,7 @@ function createRepl(inspector) { } class Backtrace extends Array { - [util.inspect.custom]() { + [customInspectSymbol]() { return this.map((callFrame, idx) => { const { location: { scriptId, lineNumber, columnNumber },