Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.2k
events: fix not emit removeListener#31847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Conversation
fuxingZhang commented Feb 18, 2020 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Fix not emit removeListener when eventName type is 'symbol'. ```js const EventEmitter = require('events'); const myEmitter = new EventEmitter(); const sym = Symbol('symbol'); const fn = () =>{}; myEmitter.on(sym, fn); myEmitter.on('removeListener', (...args) =>{console.log('removeListener'); console.log(args, args[0] === sym, args[1] === fn)}); myEmitter.removeAllListeners() ```
addaleax left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Do you think you could add test for this?
fuxingZhang commented Feb 18, 2020
I don't know yet, I'm not sure, but I can learn how to do it tomorrow or the day after tomorrow |
cjihrig left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, and based on your OP, you can probably use something like this as the test:
'use strict';constcommon=require('../common');constassert=require('assert');constEventEmitter=require('events');constmyEmitter=newEventEmitter();constsym=Symbol('symbol');constfn=()=>{};myEmitter.on(sym,fn);myEmitter.on('removeListener',common.mustCall((...args)=>{assert.deepStrictEqual(args,[sym,fn]);}));myEmitter.removeAllListeners();
BridgeAR left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a test added
When the listener's eventName type is 'symbol' and removeListener is called with no parameters, removeListener should be emitted.
fuxingZhang commented Feb 19, 2020
Thank you, it was very helpful for me. |
nodejs-github-bot commented Feb 19, 2020
nodejs-github-bot commented Mar 7, 2020
ronag commented Mar 7, 2020
CI was 404, started another one |
Fix removeListener when eventName type is 'symbol'. ```js const EventEmitter = require('events'); const myEmitter = new EventEmitter(); const sym = Symbol('symbol'); const fn = () =>{}; myEmitter.on(sym, fn); myEmitter.on('removeListener', (...args) =>{console.log('removeListener'); console.log(args, args[0] === sym, args[1] === fn)}); myEmitter.removeAllListeners() ``` When the listener's eventName type is 'symbol' and removeListener is called with no parameters, removeListener should be emitted. PR-URL: #31847 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Shelley Vohr <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>Trott commented Mar 7, 2020
Landed in 1b3dbc9. Thanks for the contribution! 🎉 |
Fix removeListener when eventName type is 'symbol'. ```js const EventEmitter = require('events'); const myEmitter = new EventEmitter(); const sym = Symbol('symbol'); const fn = () =>{}; myEmitter.on(sym, fn); myEmitter.on('removeListener', (...args) =>{console.log('removeListener'); console.log(args, args[0] === sym, args[1] === fn)}); myEmitter.removeAllListeners() ``` When the listener's eventName type is 'symbol' and removeListener is called with no parameters, removeListener should be emitted. PR-URL: #31847 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Shelley Vohr <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>Fix removeListener when eventName type is 'symbol'. ```js const EventEmitter = require('events'); const myEmitter = new EventEmitter(); const sym = Symbol('symbol'); const fn = () =>{}; myEmitter.on(sym, fn); myEmitter.on('removeListener', (...args) =>{console.log('removeListener'); console.log(args, args[0] === sym, args[1] === fn)}); myEmitter.removeAllListeners() ``` When the listener's eventName type is 'symbol' and removeListener is called with no parameters, removeListener should be emitted. PR-URL: #31847 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Shelley Vohr <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>Fix removeListener when eventName type is 'symbol'. ```js const EventEmitter = require('events'); const myEmitter = new EventEmitter(); const sym = Symbol('symbol'); const fn = () =>{}; myEmitter.on(sym, fn); myEmitter.on('removeListener', (...args) =>{console.log('removeListener'); console.log(args, args[0] === sym, args[1] === fn)}); myEmitter.removeAllListeners() ``` When the listener's eventName type is 'symbol' and removeListener is called with no parameters, removeListener should be emitted. PR-URL: #31847 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Shelley Vohr <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>Fix removeListener when eventName type is 'symbol'. ```js const EventEmitter = require('events'); const myEmitter = new EventEmitter(); const sym = Symbol('symbol'); const fn = () =>{}; myEmitter.on(sym, fn); myEmitter.on('removeListener', (...args) =>{console.log('removeListener'); console.log(args, args[0] === sym, args[1] === fn)}); myEmitter.removeAllListeners() ``` When the listener's eventName type is 'symbol' and removeListener is called with no parameters, removeListener should be emitted. PR-URL: #31847 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Shelley Vohr <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>Fix removeListener when eventName type is 'symbol'. ```js const EventEmitter = require('events'); const myEmitter = new EventEmitter(); const sym = Symbol('symbol'); const fn = () =>{}; myEmitter.on(sym, fn); myEmitter.on('removeListener', (...args) =>{console.log('removeListener'); console.log(args, args[0] === sym, args[1] === fn)}); myEmitter.removeAllListeners() ``` When the listener's eventName type is 'symbol' and removeListener is called with no parameters, removeListener should be emitted. PR-URL: #31847 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Shelley Vohr <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
Fix not emit removeListener when eventName type is 'symbol'.
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes