-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
Closed
Labels
eventsIssues and PRs related to the events subsystem / EventEmitter.Issues and PRs related to the events subsystem / EventEmitter.
Description
- Version:
v4.3.2
- Platform:
Linux osmith-ubuntu-t1700 4.2.0-30-generic #36-Ubuntu SMP Fri Feb 26 00:58:07 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
- Subsystem:
events
tl;dr; I think both of these lines should pass listener.listener || listener
https://github.com/nodejs/node/blob/master/lib/events.js#L309
https://github.com/nodejs/node/blob/master/lib/events.js#L338
When using ee.once()
, the user's listener function is wrapped. This is correctly accounted for during addListener
when emitting the 'newListener'
event, but not during removeListener
and the 'removeListener'
event.
I can PR later this evening - just opening the issue for the moment.
Test case:
'use strict';
const assert = require('assert');
const EventEmitter = require('events');
const ee = new EventEmitter();
function myListener () {};
let addedType = null;
let addedListener = null;
let removedType = null;
let removedListener = null;
ee.on('removeListener', (type, listener) => {
removedType = type;
removedListener = listener;
});
ee.on('newListener', (type, listener) => {
addedType = type;
addedListener = listener;
});
ee.once('foo', myListener);
ee.emit('foo');
process.on('exit', () => {
assert.equal('foo', addedType);
assert.equal(addedListener, myListener);
assert.equal('foo', removedType);
process._rawDebug('next assertion will fail');
assert.equal(removedListener, myListener);
});
next assertion will fail
assert.js:89
throw new assert.AssertionError({
^
AssertionError: { [Function: g] listener: [Function: myListener] } == [Function: myListener]
at process.<anonymous> (/home/omsmith/ee-remove-listener-test/index.js:33:9)
at emitOne (events.js:77:13)
at process.emit (events.js:169:7)
Metadata
Metadata
Assignees
Labels
eventsIssues and PRs related to the events subsystem / EventEmitter.Issues and PRs related to the events subsystem / EventEmitter.