@@ -158,7 +158,7 @@ function pendingDeprecate(fn, msg, code) {
158158// Mark that a method should not be used.
159159// Returns a modified function which warns once by default.
160160// If --no-deprecation is set, then it is a no-op.
161- function deprecate ( fn , msg , code , useEmitSync ) {
161+ function deprecate ( fn , msg , code , useEmitSync , modifyPrototype = true ) {
162162 // Lazy-load to avoid a circular dependency.
163163 if ( validateString === undefined )
164164 ( { validateString } = require ( 'internal/validators' ) ) ;
@@ -181,19 +181,23 @@ function deprecate(fn, msg, code, useEmitSync) {
181181 return ReflectApply ( fn , this , args ) ;
182182 }
183183
184- // The wrapper will keep the same prototype as fn to maintain prototype chain
185- ObjectSetPrototypeOf ( deprecated , fn ) ;
186- if ( fn . prototype ) {
187- // Setting this (rather than using Object.setPrototype, as above) ensures
188- // that calling the unwrapped constructor gives an instanceof the wrapped
189- // constructor.
190- deprecated . prototype = fn . prototype ;
191- }
184+ if ( modifyPrototype ) {
185+ // The wrapper will keep the same prototype as fn to maintain prototype chain
186+ // Modifying the prototype does alter the object chains, and as observed in
187+ // most cases, it slows the code.
188+ ObjectSetPrototypeOf ( deprecated , fn ) ;
189+ if ( fn . prototype ) {
190+ // Setting this (rather than using Object.setPrototype, as above) ensures
191+ // that calling the unwrapped constructor gives an instanceof the wrapped
192+ // constructor.
193+ deprecated . prototype = fn . prototype ;
194+ }
192195
193- ObjectDefineProperty ( deprecated , 'length' , {
194- __proto__ : null ,
195- ...ObjectGetOwnPropertyDescriptor ( fn , 'length' ) ,
196- } ) ;
196+ ObjectDefineProperty ( deprecated , 'length' , {
197+ __proto__ : null ,
198+ ...ObjectGetOwnPropertyDescriptor ( fn , 'length' ) ,
199+ } ) ;
200+ }
197201
198202 return deprecated ;
199203}
0 commit comments