Skip to content

Commit

Permalink
[fix] Prevent on<event> setters from removing all listeners (#955)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobbogers authored and lpinca committed Jan 9, 2017
1 parent c843e6a commit 20585ee
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/WebSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,10 @@ WebSocket.CLOSED = 3;
* @public
*/
get () {
const listener = this.listeners(method)[0];
return listener ? listener._listener ? listener._listener : listener : undefined;
const listeners = this.listeners(method);
for (var i = 0; i < listeners.length; i++) {
if (listeners[i]._listener) return listeners[i]._listener;
}
},
/**
* Add a listener for the event.
Expand All @@ -419,7 +421,13 @@ WebSocket.CLOSED = 3;
* @public
*/
set (listener) {
this.removeAllListeners(method);
const listeners = this.listeners(method);
for (var i = 0; i < listeners.length; i++) {
//
// Remove only the listeners added via `addEventListener`.
//
if (listeners[i]._listener) this.removeListener(method, listeners[i]);
}
this.addEventListener(method, listener);
}
});
Expand Down

0 comments on commit 20585ee

Please sign in to comment.