Skip to content

Commit

Permalink
repl: remove usage of require('util') in repl.js
Browse files Browse the repository at this point in the history
Use `require('internal/util/inspect').inspect` and
`require('internal/util/debuglog').debuglog` instead of
`require('util').inspect` and `require('util').debuglog`.

Refs: #26546

PR-URL: #26820
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Masashi Hirano <shisama07@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
  • Loading branch information
dnlup authored and BethGriggs committed Apr 4, 2019
1 parent d44db12 commit c64ab28
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions lib/repl.js
Expand Up @@ -51,8 +51,12 @@ const {
isIdentifierStart,
isIdentifierChar
} = require('internal/deps/acorn/acorn/dist/acorn');
const internalUtil = require('internal/util');
const util = require('util');
const {
decorateErrorStack,
isError,
deprecate
} = require('internal/util');
const { inspect } = require('internal/util/inspect');
const Stream = require('stream');
const vm = require('vm');
const path = require('path');
Expand All @@ -61,7 +65,7 @@ const { Interface } = require('readline');
const { Console } = require('console');
const CJSModule = require('internal/modules/cjs/loader');
const domain = require('domain');
const debug = util.debuglog('repl');
const debug = require('internal/util/debuglog').debuglog('repl');
const {
ERR_CANNOT_WATCH_SIGINT,
ERR_INVALID_ARG_TYPE,
Expand Down Expand Up @@ -120,8 +124,8 @@ function hasOwnProperty(obj, prop) {
// This is the default "writer" value, if none is passed in the REPL options,
// and it can be overridden by custom print functions, such as `probe` or
// `eyes.js`.
const writer = exports.writer = (obj) => util.inspect(obj, writer.options);
writer.options = { ...util.inspect.defaultOptions, showProxy: true };
const writer = exports.writer = (obj) => inspect(obj, writer.options);
writer.options = { ...inspect.defaultOptions, showProxy: true };

exports._builtinLibs = builtinLibs;

Expand Down Expand Up @@ -204,10 +208,10 @@ function REPLServer(prompt,

let rli = this;
Object.defineProperty(this, 'rli', {
get: util.deprecate(() => rli,
'REPLServer.rli is deprecated', 'DEP0124'),
set: util.deprecate((val) => rli = val,
'REPLServer.rli is deprecated', 'DEP0124'),
get: deprecate(() => rli,
'REPLServer.rli is deprecated', 'DEP0124'),
set: deprecate((val) => rli = val,
'REPLServer.rli is deprecated', 'DEP0124'),
enumerable: true,
configurable: true
});
Expand Down Expand Up @@ -430,15 +434,15 @@ function REPLServer(prompt,
if (typeof e === 'object' && e !== null) {
const pstrace = Error.prepareStackTrace;
Error.prepareStackTrace = prepareStackTrace(pstrace);
internalUtil.decorateErrorStack(e);
decorateErrorStack(e);
Error.prepareStackTrace = pstrace;

if (e.domainThrown) {
delete e.domain;
delete e.domainThrown;
}

if (internalUtil.isError(e)) {
if (isError(e)) {
if (e.stack) {
if (e.name === 'SyntaxError') {
// Remove stack trace.
Expand Down Expand Up @@ -482,10 +486,12 @@ function REPLServer(prompt,

self.clearBufferedCommand();
Object.defineProperty(this, 'bufferedCommand', {
get: util.deprecate(() => self[kBufferedCommandSymbol],
'REPLServer.bufferedCommand is deprecated', 'DEP0074'),
set: util.deprecate((val) => self[kBufferedCommandSymbol] = val,
'REPLServer.bufferedCommand is deprecated', 'DEP0074'),
get: deprecate(() => self[kBufferedCommandSymbol],
'REPLServer.bufferedCommand is deprecated',
'DEP0074'),
set: deprecate((val) => self[kBufferedCommandSymbol] = val,
'REPLServer.bufferedCommand is deprecated',
'DEP0074'),
enumerable: true
});

Expand Down Expand Up @@ -518,7 +524,7 @@ function REPLServer(prompt,
writer.options.colors = self.useColors;

if (options[kStandaloneREPL]) {
Object.defineProperty(util.inspect, 'replDefaults', {
Object.defineProperty(inspect, 'replDefaults', {
get() {
return writer.options;
},
Expand Down Expand Up @@ -567,7 +573,7 @@ function REPLServer(prompt,
return false;
}

self.parseREPLKeyword = util.deprecate(
self.parseREPLKeyword = deprecate(
_parseREPLKeyword,
'REPLServer.parseREPLKeyword() is deprecated',
'DEP0075');
Expand Down Expand Up @@ -924,7 +930,7 @@ REPLServer.prototype.setPrompt = function setPrompt(prompt) {
Interface.prototype.setPrompt.call(this, prompt);
};

REPLServer.prototype.turnOffEditorMode = util.deprecate(
REPLServer.prototype.turnOffEditorMode = deprecate(
function() { _turnOffEditorMode(this); },
'REPLServer.turnOffEditorMode() is deprecated',
'DEP0078');
Expand Down Expand Up @@ -1315,7 +1321,7 @@ REPLServer.prototype.defineCommand = function(keyword, cmd) {
this.commands[keyword] = cmd;
};

REPLServer.prototype.memory = util.deprecate(
REPLServer.prototype.memory = deprecate(
_memory,
'REPLServer.memory() is deprecated',
'DEP0082');
Expand Down

0 comments on commit c64ab28

Please sign in to comment.