Skip to content

Commit dab489e

Browse files
committed
lib: modify the prototype based on cond on deprecate
1 parent 6d55e9e commit dab489e

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

lib/async_hooks.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,10 @@ class AsyncResource {
262262
enumerable: true,
263263
get: deprecate(function() {
264264
return self;
265-
}, 'The asyncResource property on bound functions is deprecated', 'DEP0172'),
265+
}, 'The asyncResource property on bound functions is deprecated', 'DEP0172', false),
266266
set: deprecate(function(val) {
267267
self = val;
268-
}, 'The asyncResource property on bound functions is deprecated', 'DEP0172'),
268+
}, 'The asyncResource property on bound functions is deprecated', 'DEP0172', false),
269269
},
270270
});
271271
return bound;

lib/internal/util.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ function pendingDeprecate(fn, msg, code) {
169169
// Mark that a method should not be used.
170170
// Returns a modified function which warns once by default.
171171
// 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) {
173173
// Lazy-load to avoid a circular dependency.
174174
if (validateString === undefined)
175175
({ validateString } = require('internal/validators'));
@@ -192,19 +192,22 @@ function deprecate(fn, msg, code, useEmitSync) {
192192
return ReflectApply(fn, this, args);
193193
}
194194

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;
195+
if (modifyPrototype) {
196+
// The wrapper will keep the same prototype as fn to maintain prototype chain
197+
ObjectSetPrototypeOf(deprecated, fn);
198+
if (fn.prototype) {
199+
// Setting this (rather than using Object.setPrototype, as above) ensures
200+
// that calling the unwrapped constructor gives an instanceof the wrapped
201+
// constructor.
202+
deprecated.prototype = fn.prototype;
203+
}
204+
205+
ObjectDefineProperty(deprecated, 'length', {
206+
__proto__: null,
207+
...ObjectGetOwnPropertyDescriptor(fn, 'length'),
208+
});
202209
}
203210

204-
ObjectDefineProperty(deprecated, 'length', {
205-
__proto__: null,
206-
...ObjectGetOwnPropertyDescriptor(fn, 'length'),
207-
});
208211

209212
return deprecated;
210213
}

0 commit comments

Comments
 (0)