@@ -169,7 +169,7 @@ function pendingDeprecate(fn, msg, code) {
169
169
// Mark that a method should not be used.
170
170
// Returns a modified function which warns once by default.
171
171
// If --no-deprecation is set, then it is a no-op.
172
- function deprecate ( fn , msg , code , useEmitSync ) {
172
+ function deprecate ( fn , msg , code , useEmitSync , modifyPrototype = true ) {
173
173
// Lazy-load to avoid a circular dependency.
174
174
if ( validateString === undefined )
175
175
( { validateString } = require ( 'internal/validators' ) ) ;
@@ -192,19 +192,23 @@ function deprecate(fn, msg, code, useEmitSync) {
192
192
return ReflectApply ( fn , this , args ) ;
193
193
}
194
194
195
- // The wrapper will keep the same prototype as fn to maintain prototype chain
196
- ObjectSetPrototypeOf ( deprecated , fn ) ;
197
- if ( fn . prototype ) {
198
- // Setting this (rather than using Object.setPrototype, as above) ensures
199
- // that calling the unwrapped constructor gives an instanceof the wrapped
200
- // constructor.
201
- deprecated . prototype = fn . prototype ;
202
- }
195
+ if ( modifyPrototype ) {
196
+ // The wrapper will keep the same prototype as fn to maintain prototype chain
197
+ // Modifying the prototype does alter the object chains, and as observed in
198
+ // most cases, it slows the code.
199
+ ObjectSetPrototypeOf ( deprecated , fn ) ;
200
+ if ( fn . prototype ) {
201
+ // Setting this (rather than using Object.setPrototype, as above) ensures
202
+ // that calling the unwrapped constructor gives an instanceof the wrapped
203
+ // constructor.
204
+ deprecated . prototype = fn . prototype ;
205
+ }
203
206
204
- ObjectDefineProperty ( deprecated , 'length' , {
205
- __proto__ : null ,
206
- ...ObjectGetOwnPropertyDescriptor ( fn , 'length' ) ,
207
- } ) ;
207
+ ObjectDefineProperty ( deprecated , 'length' , {
208
+ __proto__ : null ,
209
+ ...ObjectGetOwnPropertyDescriptor ( fn , 'length' ) ,
210
+ } ) ;
211
+ }
208
212
209
213
return deprecated ;
210
214
}
0 commit comments