Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debugger: refactor to use internal modules #38550

Merged
merged 1 commit into from
May 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions lib/internal/inspector/inspect_repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,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',
Expand Down Expand Up @@ -170,12 +171,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':
Expand All @@ -184,7 +185,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');
Expand All @@ -200,7 +201,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');
Expand All @@ -214,10 +215,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');
Expand Down Expand Up @@ -265,11 +266,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);
}
}
Expand Down Expand Up @@ -318,7 +319,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) {
Expand Down Expand Up @@ -358,7 +359,7 @@ function createRepl(inspector) {
function listScripts(displayNatives = false) {
print(formatScripts(displayNatives));
}
listScripts[util.inspect.custom] = function listWithoutInternal() {
listScripts[customInspectSymbol] = function listWithoutInternal() {
return formatScripts();
};

Expand All @@ -374,7 +375,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');
Expand All @@ -395,7 +396,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;
Expand Down Expand Up @@ -461,7 +462,7 @@ function createRepl(inspector) {
}

class Backtrace extends Array {
[util.inspect.custom]() {
[customInspectSymbol]() {
return this.map((callFrame, idx) => {
const {
location: { scriptId, lineNumber, columnNumber },
Expand Down