Skip to content

Commit

Permalink
fixup!
Browse files Browse the repository at this point in the history
  • Loading branch information
RedYetiDev committed Oct 26, 2024
1 parent 23a70c0 commit e9a2c30
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
18 changes: 11 additions & 7 deletions lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const {
} = internalBinding('util');
const { isNativeError, isPromise } = internalBinding('types');
const { getOptionValue } = require('internal/options');
const assert = require('internal/assert');
const { encodings } = internalBinding('string_decoder');

const noCrypto = !process.versions.openssl;
Expand Down Expand Up @@ -97,7 +98,7 @@ function isError(e) {
// each one once.
const codesWarned = new SafeSet();

const lazyValidateString = getLazy(() => require('internal/validators').validateString);
let validateString;

function getDeprecationWarningEmitter(
code, msg, deprecated, useEmitSync,
Expand Down Expand Up @@ -145,8 +146,12 @@ function pendingDeprecate(fn, msg, code) {
// Returns a modified function which warns once by default.
// If --no-deprecation is set, then it is a no-op.
function deprecate(fn, msg, code, useEmitSync) {
// Lazy-load to avoid a circular dependency.
if (validateString === undefined)
({ validateString } = require('internal/validators'));

if (code !== undefined)
lazyValidateString()(code, 'code');
validateString(code, 'code');

const emitDeprecationWarning = getDeprecationWarningEmitter(
code, msg, deprecated, useEmitSync,
Expand Down Expand Up @@ -175,9 +180,8 @@ function deprecate(fn, msg, code, useEmitSync) {
return deprecated;
}

function deprecateInstantation(target, code, ...args) {
if (code !== undefined)
lazyValidateString()(code, 'code');
function deprecateInstantiation(target, code, ...args) {
assert(typeof code === 'string');

getDeprecationWarningEmitter(code, `Instantiating ${target.name} without the 'new' keyword has been deprecated.`, target)();

Expand Down Expand Up @@ -878,7 +882,7 @@ module.exports = {
defineLazyProperties,
defineReplaceableLazyAttribute,
deprecate,
deprecateInstantation,
deprecateInstantiation,
emitExperimentalWarning,
encodingsMap,
exposeInterface,
Expand Down Expand Up @@ -930,4 +934,4 @@ module.exports = {
setOwnProperty,
pendingDeprecate,
WeakReference,
};
};
6 changes: 3 additions & 3 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const {
decorateErrorStack,
isError,
deprecate,
deprecateInstantation,
deprecateInstantiation,
SideEffectFreeRegExpPrototypeSymbolReplace,
SideEffectFreeRegExpPrototypeSymbolSplit,
} = require('internal/util');
Expand Down Expand Up @@ -263,7 +263,7 @@ function REPLServer(prompt,
ignoreUndefined,
replMode) {
if (!(this instanceof REPLServer)) {
return deprecateInstantation(REPLServer, 'DEP0185', prompt, stream, eval_, useGlobal, ignoreUndefined, replMode);
return deprecateInstantiation(REPLServer, 'DEP0185', prompt, stream, eval_, useGlobal, ignoreUndefined, replMode);
}

let options;
Expand Down Expand Up @@ -1845,7 +1845,7 @@ function defineDefaultCommands(repl) {

function Recoverable(err) {
if (!(this instanceof Recoverable))
return deprecateInstantation(Recoverable, 'DEP0185', err);
return deprecateInstantiation(Recoverable, 'DEP0185', err);
this.err = err;
}
ObjectSetPrototypeOf(Recoverable.prototype, SyntaxErrorPrototype);
Expand Down

0 comments on commit e9a2c30

Please sign in to comment.