Skip to content

Commit

Permalink
[fixup] remove hasListener in favour of listenerCount, document liste…
Browse files Browse the repository at this point in the history
…ners change
  • Loading branch information
apapirovski committed Nov 20, 2017
1 parent 88f0a14 commit b958ba3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
11 changes: 9 additions & 2 deletions doc/api/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,16 +344,23 @@ added: v3.2.0

Returns the number of listeners listening to the event named `eventName`.

### emitter.listeners(eventName)
### emitter.listeners(eventName[, unwrap])
<!-- YAML
added: v0.1.26
changes:
- version: v7.0.0
pr-url: https://github.com/nodejs/node/pull/6881
description: For listeners attached using `.once()` this returns the
original listeners instead of wrapper functions now.
- version: REPLACEME
pr-url: REPLACEME
description: Second optional argument `unwrap` allows the wrapped
listeners to be returned (such as ones created with
`.once()`)
-->
- `eventName` {any}
* `eventName` {any} The name of the event.
* `unwrap` {boolean} When set to true, will return the original listeners
instead of the wrapper functions created by `.once()`. **Default:** `true`

Returns a copy of the array of listeners for the event named `eventName`.

Expand Down
2 changes: 1 addition & 1 deletion lib/domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function setHasErrorListener(type) {
}

function removeHasErrorListener(type) {
if (type === 'error' && !this.hasListener('error'))
if (type === 'error' && !this.listenerCount('error'))
this._hasErrorListener = false;
}

Expand Down
4 changes: 0 additions & 4 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,10 +518,6 @@ EventEmitter.prototype.eventNames = function eventNames() {
return events !== undefined && events.size ? [...events.keys()] : [];
};

EventEmitter.prototype.hasListener = function hasListener(type) {
return this[kEvents] !== undefined && this[kEvents].has(type);
};

function arrayClone(arr) {
const copy = new Array(arr.length);
for (var i = 0; i < arr.length; ++i)
Expand Down
6 changes: 2 additions & 4 deletions lib/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ const realRunInThisContext = Script.prototype.runInThisContext;
const realRunInContext = Script.prototype.runInContext;

Script.prototype.runInThisContext = function(options) {
if (options && options.breakOnSigint && process.hasListener('SIGINT')) {
if (options && options.breakOnSigint && process.listenerCount('SIGINT')) {
return sigintHandlersWrap(realRunInThisContext, this, [options]);
} else {
return realRunInThisContext.call(this, options);
}
};

Script.prototype.runInContext = function(contextifiedSandbox, options) {
if (options && options.breakOnSigint && process.hasListener('SIGINT')) {
if (options && options.breakOnSigint && process.listenerCount('SIGINT')) {
return sigintHandlersWrap(realRunInContext, this,
[contextifiedSandbox, options]);
} else {
Expand Down Expand Up @@ -83,8 +83,6 @@ function createScript(code, options) {
// Remove all SIGINT listeners and re-attach them after the wrapped function
// has executed, so that caught SIGINT are handled by the listeners again.
function sigintHandlersWrap(fn, thisArg, argsArray) {
// Using the internal list here to make sure `.once()` wrappers are used,
// not the original ones.
const sigintListeners = process.listeners('SIGINT', false);

process.removeAllListeners('SIGINT');
Expand Down

0 comments on commit b958ba3

Please sign in to comment.