From e9a2c30526c9159f6c6eaa7d9b51eb000d3c6bc6 Mon Sep 17 00:00:00 2001 From: Aviv Keller Date: Sat, 26 Oct 2024 16:06:40 -0400 Subject: [PATCH] fixup! --- lib/internal/util.js | 18 +++++++++++------- lib/repl.js | 6 +++--- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/internal/util.js b/lib/internal/util.js index 6ca3239e6f9ffc..2df4695c9f1abc 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -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; @@ -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, @@ -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, @@ -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)(); @@ -878,7 +882,7 @@ module.exports = { defineLazyProperties, defineReplaceableLazyAttribute, deprecate, - deprecateInstantation, + deprecateInstantiation, emitExperimentalWarning, encodingsMap, exposeInterface, @@ -930,4 +934,4 @@ module.exports = { setOwnProperty, pendingDeprecate, WeakReference, -}; +}; \ No newline at end of file diff --git a/lib/repl.js b/lib/repl.js index 871ea680b221df..724a01bfc430af 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -111,7 +111,7 @@ const { decorateErrorStack, isError, deprecate, - deprecateInstantation, + deprecateInstantiation, SideEffectFreeRegExpPrototypeSymbolReplace, SideEffectFreeRegExpPrototypeSymbolSplit, } = require('internal/util'); @@ -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; @@ -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);