Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
lib: avoid event override by assignment
  • Loading branch information
erights committed May 13, 2025
commit a5dce87ea3cc8486feab2f3667e61c29e4bdaafd
41 changes: 32 additions & 9 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Comment thread
erights marked this conversation as resolved.
});
} else {
this[kShapeMode] = true;
ObjectDefineProperty(this, kShapeMode, {
__proto__: null,
value: true,
});
Comment thread
erights marked this conversation as resolved.
}

this._maxListeners ||= undefined;

ObjectDefineProperty(this, '_maxListeners', {
__proto__: null,
value: this._maxListeners || undefined,
Comment thread
erights marked this conversation as resolved.
});

if (opts?.captureRejections) {
validateBoolean(opts.captureRejections, 'options.captureRejections');
this[kCapture] = Boolean(opts.captureRejections);
ObjectDefineProperty(this, kCapture, {
__proto__: null,
value: Boolean(opts.captureRejections),
});
Comment thread
erights marked this conversation as resolved.
} 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),
});
Comment thread
erights marked this conversation as resolved.
}
};

Expand Down