Skip to content

Commit

Permalink
events: improve addAbortListener perf by saving the same options ob…
Browse files Browse the repository at this point in the history
…ject
  • Loading branch information
rluvaton committed Apr 4, 2024
1 parent 74343a7 commit 4453ccb
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/internal/events/abort_listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const {

let queueMicrotask;
let kResistStopPropagation;
let abortListenerOptions;

/**
* @param {AbortSignal} signal
Expand All @@ -34,8 +35,9 @@ function addAbortListener(signal, listener) {
queueMicrotask(() => listener());
} else {
kResistStopPropagation ??= require('internal/event_target').kResistStopPropagation;
abortListenerOptions ??= Object.freeze({ __proto__: null, once: true, [kResistStopPropagation]: true });
// TODO(atlowChemi) add { subscription: true } and return directly
signal.addEventListener('abort', listener, { __proto__: null, once: true, [kResistStopPropagation]: true });
signal.addEventListener('abort', listener, abortListenerOptions);
removeEventListener = () => {
signal.removeEventListener('abort', listener);
};
Expand Down

0 comments on commit 4453ccb

Please sign in to comment.