(fn, msg, code, useEmitSync, modifyPrototype = true)
| 175 | // Returns a modified function which warns once by default. |
| 176 | // If --no-deprecation is set, then it is a no-op. |
| 177 | function 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 | |
| 220 | function deprecateInstantiation(target, code, ...args) { |
| 221 | assert(typeof code === 'string'); |
no test coverage detected
searching dependent graphs…