diff --git a/lib/events.js b/lib/events.js index 5bfe95c84ab198..5970aafd59e030 100644 --- a/lib/events.js +++ b/lib/events.js @@ -330,24 +330,47 @@ EventEmitter.setMaxListeners = EventEmitter.init = function(opts) { if (this._events === undefined || - this._events === ObjectGetPrototypeOf(this)._events) { - this._events = { __proto__: null }; - this._eventsCount = 0; - this[kShapeMode] = false; + this._events === ObjectGetPrototypeOf(this)._events) { + ObjectDefineProperties(this, { + __proto__: null, + _events: { + __proto__: null, + value: { __proto__: null }, + }, + _eventCount: { + __proto__: null, + value: 0, + }, + [kShapeMode]: { + __proto__: null, + value: false, + }, + }); } else { - this[kShapeMode] = true; + ObjectDefineProperty(this, kShapeMode, { + __proto__: null, + value: true, + }); } - this._maxListeners ||= undefined; - + ObjectDefineProperty(this, '_maxListeners', { + __proto__: null, + value: this._maxListeners || undefined, + }); if (opts?.captureRejections) { validateBoolean(opts.captureRejections, 'options.captureRejections'); - this[kCapture] = Boolean(opts.captureRejections); + ObjectDefineProperty(this, kCapture, { + __proto__: null, + value: Boolean(opts.captureRejections), + }); } else { // Assigning the kCapture property directly saves an expensive // prototype lookup in a very sensitive hot path. - this[kCapture] = EventEmitter.prototype[kCapture]; + ObjectDefineProperty(this, kCapture, { + __proto__: null, + value: Boolean(opts.captureRejections), + }); } };