MCPcopy Index your code
hub / github.com/nodejs/node / deprecate

Function deprecate

lib/internal/util.js:177–218  ·  view source on GitHub ↗
(fn, msg, code, useEmitSync, modifyPrototype = true)

Source from the content-addressed store, hash-verified

175// Returns a modified function which warns once by default.
176// If --no-deprecation is set, then it is a no-op.
177function deprecate(fn, msg, code, useEmitSync, modifyPrototype = true) {
178 // Lazy-load to avoid a circular dependency.
179 if (validateString === undefined)
180 ({ validateString } = require('internal/validators'));
181
182 if (code !== undefined)
183 validateString(code, 'code');
184
185 const emitDeprecationWarning = getDeprecationWarningEmitter(
186 code, msg, deprecated, useEmitSync,
187 );
188
189 function deprecated(...args) {
190 if (!process.noDeprecation) {
191 emitDeprecationWarning();
192 }
193 if (new.target) {
194 return ReflectConstruct(fn, args, new.target);
195 }
196 return ReflectApply(fn, this, args);
197 }
198
199 if (modifyPrototype) {
200 // The wrapper will keep the same prototype as fn to maintain prototype chain
201 // Modifying the prototype does alter the object chains, and as observed in
202 // most cases, it slows the code.
203 ObjectSetPrototypeOf(deprecated, fn);
204 if (fn.prototype) {
205 // Setting this (rather than using Object.setPrototype, as above) ensures
206 // that calling the unwrapped constructor gives an instanceof the wrapped
207 // constructor.
208 deprecated.prototype = fn.prototype;
209 }
210
211 ObjectDefineProperty(deprecated, 'length', {
212 __proto__: null,
213 ...ObjectGetOwnPropertyDescriptor(fn, 'length'),
214 });
215 }
216
217 return deprecated;
218}
219
220function deprecateInstantiation(target, code, ...args) {
221 assert(typeof code === 'string');

Callers 4

diffiehellman.jsFile · 0.50
core.jsFile · 0.50
initializeDeprecationsFunction · 0.50
utils.jsFile · 0.50

Calls 2

requireFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…