Skip to content
Closed
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
10 changes: 5 additions & 5 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ EventEmitter.init = function(opts) {
this._maxListeners = this._maxListeners || undefined;


if (opts && opts.captureRejections) {
if (opts?.captureRejections) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to benchmark these changes. The entire events.js file is one of the most performance sensitive in core and changes here can have massive impact throughout. Last I benchmarked, optional chaining still had some performance lag that hadn't been fully optimized out. That's not a block on this on it's own but let's be sure to run benchmarks before this lands.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also not a fan of the optional chaining operator. I think it hinders readability.

if (typeof opts.captureRejections !== 'boolean') {
throw new ERR_INVALID_ARG_TYPE('options.captureRejections',
'boolean', opts.captureRejections);
Expand Down Expand Up @@ -706,9 +706,9 @@ function getEventListeners(emitterOrTarget, type) {
}

async function once(emitter, name, options = {}) {
const signal = options ? options.signal : undefined;
const signal = options?.signal;
validateAbortSignal(signal, 'options.signal');
if (signal && signal.aborted)
if (signal?.aborted)
throw lazyDOMException('The operation was aborted', 'AbortError');
return new Promise((resolve, reject) => {
const errorListener = (err) => {
Expand Down Expand Up @@ -762,7 +762,7 @@ function eventTargetAgnosticRemoveListener(emitter, name, listener, flags) {

function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
if (typeof emitter.on === 'function') {
if (flags && flags.once) {
if (flags?.once) {
emitter.once(name, listener);
} else {
emitter.on(name, listener);
Expand All @@ -779,7 +779,7 @@ function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
function on(emitter, event, options) {
const { signal } = { ...options };
validateAbortSignal(signal, 'options.signal');
if (signal && signal.aborted) {
if (signal?.aborted) {
throw lazyDOMException('The operation was aborted', 'AbortError');
}

Expand Down