Skip to content

Commit

Permalink
events: propagate weak option for kNewListener
Browse files Browse the repository at this point in the history
Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: #40899
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
jasnell authored and danielleadams committed Feb 1, 2022
1 parent c52ce19 commit 78a8c1b
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ class EventTarget {
initEventTarget(this);
}

[kNewListener](size, type, listener, once, capture, passive) {
[kNewListener](size, type, listener, once, capture, passive, weak) {
if (this[kMaxEventTargetListeners] > 0 &&
size > this[kMaxEventTargetListeners] &&
!this[kMaxEventTargetListenersWarned]) {
Expand Down Expand Up @@ -440,7 +440,14 @@ class EventTarget {
// This is the first handler in our linked list.
new Listener(root, listener, once, capture, passive,
isNodeStyleListener, weak);
this[kNewListener](root.size, type, listener, once, capture, passive);
this[kNewListener](
root.size,
type,
listener,
once,
capture,
passive,
weak);
this[kEvents].set(type, root);
return;
}
Expand All @@ -461,7 +468,7 @@ class EventTarget {
new Listener(previous, listener, once, capture, passive,
isNodeStyleListener, weak);
root.size++;
this[kNewListener](root.size, type, listener, once, capture, passive);
this[kNewListener](root.size, type, listener, once, capture, passive, weak);
}

removeEventListener(type, listener, options = {}) {
Expand Down Expand Up @@ -811,7 +818,7 @@ function defineEventHandler(emitter, name) {
if (typeof wrappedHandler.handler === 'function') {
this[kEvents].get(name).size++;
const size = this[kEvents].get(name).size;
this[kNewListener](size, name, value, false, false, false);
this[kNewListener](size, name, value, false, false, false, false);
}
} else {
wrappedHandler = makeEventHandler(value);
Expand Down

0 comments on commit 78a8c1b

Please sign in to comment.