Skip to content

Commit ad80566

Browse files
aduh95richardlau
authored andcommitted
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: #38550 Backport-PR-URL: #39446 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
1 parent b5724a1 commit ad80566

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

lib/internal/inspector/inspect_repl.js

+17-16
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
const FS = require('fs');
77
const Path = require('path');
88
const Repl = require('repl');
9-
const util = require('util');
109
const vm = require('vm');
11-
const fileURLToPath = require('url').fileURLToPath;
10+
const { fileURLToPath } = require('internal/url');
1211

13-
const debuglog = util.debuglog('inspect');
12+
const { customInspectSymbol } = require('internal/util');
13+
const { inspect: utilInspect } = require('internal/util/inspect');
14+
const debuglog = require('internal/util/debuglog').debuglog('inspect');
1415

1516
const SHORTCUTS = {
1617
cont: 'c',
@@ -148,12 +149,12 @@ class RemoteObject {
148149
}
149150
}
150151

151-
[util.inspect.custom](depth, opts) {
152+
[customInspectSymbol](depth, opts) {
152153
function formatProperty(prop) {
153154
switch (prop.type) {
154155
case 'string':
155156
case 'undefined':
156-
return util.inspect(prop.value, opts);
157+
return utilInspect(prop.value, opts);
157158

158159
case 'number':
159160
case 'boolean':
@@ -162,7 +163,7 @@ class RemoteObject {
162163
case 'object':
163164
case 'symbol':
164165
if (prop.subtype === 'date') {
165-
return util.inspect(new Date(prop.value), opts);
166+
return utilInspect(new Date(prop.value), opts);
166167
}
167168
if (prop.subtype === 'array') {
168169
return opts.stylize(prop.value, 'special');
@@ -178,7 +179,7 @@ class RemoteObject {
178179
case 'number':
179180
case 'string':
180181
case 'undefined':
181-
return util.inspect(this.value, opts);
182+
return utilInspect(this.value, opts);
182183

183184
case 'symbol':
184185
return opts.stylize(this.description, 'special');
@@ -192,10 +193,10 @@ class RemoteObject {
192193
case 'object':
193194
switch (this.subtype) {
194195
case 'date':
195-
return util.inspect(new Date(this.description), opts);
196+
return utilInspect(new Date(this.description), opts);
196197

197198
case 'null':
198-
return util.inspect(null, opts);
199+
return utilInspect(null, opts);
199200

200201
case 'regexp':
201202
return opts.stylize(this.description, 'regexp');
@@ -243,11 +244,11 @@ class ScopeSnapshot {
243244
this.completionGroup = properties.map((prop) => prop.name);
244245
}
245246

246-
[util.inspect.custom](depth, opts) {
247+
[customInspectSymbol](depth, opts) {
247248
const type = `${this.type[0].toUpperCase()}${this.type.slice(1)}`;
248249
const name = this.name ? `<${this.name}>` : '';
249250
const prefix = `${type}${name} `;
250-
return util.inspect(this.properties, opts)
251+
return utilInspect(this.properties, opts)
251252
.replace(/^Map /, prefix);
252253
}
253254
}
@@ -296,7 +297,7 @@ function createRepl(inspector) {
296297

297298
const INSPECT_OPTIONS = { colors: inspector.stdout.isTTY };
298299
function inspect(value) {
299-
return util.inspect(value, INSPECT_OPTIONS);
300+
return utilInspect(value, INSPECT_OPTIONS);
300301
}
301302

302303
function print(value, addNewline = true) {
@@ -336,7 +337,7 @@ function createRepl(inspector) {
336337
function listScripts(displayNatives = false) {
337338
print(formatScripts(displayNatives));
338339
}
339-
listScripts[util.inspect.custom] = function listWithoutInternal() {
340+
listScripts[customInspectSymbol] = function listWithoutInternal() {
340341
return formatScripts();
341342
};
342343

@@ -352,7 +353,7 @@ function createRepl(inspector) {
352353
return p;
353354
}
354355

355-
[util.inspect.custom](depth, { stylize }) {
356+
[customInspectSymbol](depth, { stylize }) {
356357
const { startTime, endTime } = this.data;
357358
const MU = String.fromChar(956);
358359
return stylize(`[Profile ${endTime - startTime}${MU}s]`, 'special');
@@ -373,7 +374,7 @@ function createRepl(inspector) {
373374
this.delta = delta;
374375
}
375376

376-
[util.inspect.custom](depth, options) {
377+
[customInspectSymbol](depth, options) {
377378
const { scriptId, lineNumber, columnNumber, delta, scriptSource } = this;
378379
const start = Math.max(1, lineNumber - delta + 1);
379380
const end = lineNumber + delta + 1;
@@ -439,7 +440,7 @@ function createRepl(inspector) {
439440
}
440441

441442
class Backtrace extends Array {
442-
[util.inspect.custom]() {
443+
[customInspectSymbol]() {
443444
return this.map((callFrame, idx) => {
444445
const {
445446
location: { scriptId, lineNumber, columnNumber },

0 commit comments

Comments
 (0)