Comparing version 8.10.0 to 8.11.0
@@ -181,3 +181,3 @@ 'use strict'; | ||
* @param {String} type A string representing the event type to listen for | ||
* @param {Function} listener The listener to add | ||
* @param {(Function|Object)} handler The listener to add | ||
* @param {Object} [options] An options object specifies characteristics about | ||
@@ -190,3 +190,13 @@ * the event listener | ||
*/ | ||
addEventListener(type, listener, options = {}) { | ||
addEventListener(type, handler, options = {}) { | ||
for (const listener of this.listeners(type)) { | ||
if ( | ||
!options[kForOnEventAttribute] && | ||
listener[kListener] === handler && | ||
!listener[kForOnEventAttribute] | ||
) { | ||
return; | ||
} | ||
} | ||
let wrapper; | ||
@@ -201,3 +211,3 @@ | ||
event[kTarget] = this; | ||
listener.call(this, event); | ||
callListener(handler, this, event); | ||
}; | ||
@@ -213,3 +223,3 @@ } else if (type === 'close') { | ||
event[kTarget] = this; | ||
listener.call(this, event); | ||
callListener(handler, this, event); | ||
}; | ||
@@ -224,3 +234,3 @@ } else if (type === 'error') { | ||
event[kTarget] = this; | ||
listener.call(this, event); | ||
callListener(handler, this, event); | ||
}; | ||
@@ -232,3 +242,3 @@ } else if (type === 'open') { | ||
event[kTarget] = this; | ||
listener.call(this, event); | ||
callListener(handler, this, event); | ||
}; | ||
@@ -240,3 +250,3 @@ } else { | ||
wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute]; | ||
wrapper[kListener] = listener; | ||
wrapper[kListener] = handler; | ||
@@ -254,3 +264,3 @@ if (options.once) { | ||
* @param {String} type A string representing the event type to remove | ||
* @param {Function} handler The listener to remove | ||
* @param {(Function|Object)} handler The listener to remove | ||
* @public | ||
@@ -275,1 +285,17 @@ */ | ||
}; | ||
/** | ||
* Call an event listener | ||
* | ||
* @param {(Function|Object)} listener The listener to call | ||
* @param {*} thisArg The value to use as `this`` when calling the listener | ||
* @param {Event} event The event to pass to the listener | ||
* @private | ||
*/ | ||
function callListener(listener, thisArg, event) { | ||
if (typeof listener === 'object' && listener.handleEvent) { | ||
listener.handleEvent.call(listener, event); | ||
} else { | ||
listener.call(thisArg, event); | ||
} | ||
} |
{ | ||
"name": "ws", | ||
"version": "8.10.0", | ||
"version": "8.11.0", | ||
"description": "Simple to use, blazing fast and thoroughly tested websocket client and server for Node.js", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
135341
3921
2