Skip to content

Conversation

@DavidCai1111
Copy link
Member

@DavidCai1111DavidCai1111 commented Mar 20, 2017

Since EventEmitter.defaultMaxListeners and emitter.setMaxListeners(n) are both public APIs listed in the document, so it is reasonable to check EventEmitter.defaultMaxListeners getter's input like what emitter.setMaxListeners(n) does to avoid potential confusing results or error messages caused by some userland mistaken input, like:

'use strict'constE=require('events')E.defaultMaxListeners=newProxy({},{get: ()=>{}})lete=newE()e.addListener('1',function(){})e.addListener('1',function(){})// output:// events.js:260// if (m && m > 0 && existing.length > m){// ^//// TypeError: Cannot convert object to primitive value// at _addListener (events.js:260:18)// at EventEmitter.addListener (events.js:279:10)// at Object.<anonymous> (/Users/caiwei/workspace/benchmarks/index.js:7:3)// at Module._compile (module.js:571:32)// at Object.Module._extensions..js (module.js:580:10)// at Module.load (module.js:488:32)// at tryModuleLoad (module.js:447:12)// at Function.Module._load (module.js:439:3)// at Module.runMain (module.js:605:10)// at run (bootstrap_node.js:425:7)
Checklist
  • [-] make -j4 test (UNIX), or vcbuild test (Windows) passes
  • [-] tests and/or benchmarks are included
  • [-] documentation is changed or added
  • [-] commit message follows commit guidelines
Affected core subsystem(s)

events, doc

@nodejs-github-botnodejs-github-bot added the events Issues and PRs related to the events subsystem / EventEmitter. label Mar 20, 2017
lib/events.js Outdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we replace isNaN(n) with n !== n, possibly with a comment with a short explanation?

Copy link
Contributor

@vsemozhetbytvsemozhetbytMar 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mscdex Is this similar place also worth replacing then?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, but as a separate commit I'd say.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DavidCai1111DavidCai1111force-pushed the events/add-default-max-listeners-type-checking branch from aa568e6 to 58f7610CompareMarch 20, 2017 14:33
@DavidCai1111
Copy link
MemberAuthor

@vsemozhetbyt Thanks for reminding, changed it to a shorter one :)

@vsemozhetbyt
Copy link
Contributor

@DavidCai1111DavidCai1111force-pushed the events/add-default-max-listeners-type-checking branch 2 times, most recently from ce92c12 to 35db7e6CompareMarch 20, 2017 15:35
@vsemozhetbyt
Copy link
Contributor

New CI: https://ci.nodejs.org/job/node-test-pull-request/6934/

lib/events.js Outdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'which value is larger than zero' should probably instead be something like 'whose value is zero or greater'

@jasnelljasnell added the semver-major PRs that contain breaking changes and should be released in the next major version. label Mar 20, 2017
Copy link
Contributor

@cjihrigcjihrig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a couple nits.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I suggest rewording this as:

If this value is not a positive number, a TypeError will be thrown.

lib/events.js Outdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing this variable name seems unnecessary.

Copy link
Member

@jasnelljasnell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with nits addressed

@DavidCai1111DavidCai1111force-pushed the events/add-default-max-listeners-type-checking branch from 35db7e6 to b3c06f2CompareMarch 21, 2017 00:20
@DavidCai1111
Copy link
MemberAuthor

@mscdex@cjihrig Thanks for reviewing. Just updated, PTAL. 😃

@mscdex
Copy link
Contributor

@jasnell
Copy link
Member

@mscdex ... does this LGTY?

// check whether the input is a positive number (whose value is zero or
// greater and not a NaN).
if(typeofarg!=='number'||arg<0||arg!==arg)
thrownewTypeError('defaultMaxListeners must be a positive number');
Copy link
Contributor

@mscdexmscdexMar 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'defaultMaxListeners' should be enclosed in double quotes to match the style when referencing property names in error messages.

@mscdex
Copy link
Contributor

One minor nit, but otherwise LGTM.

@jasnell
Copy link
Member

I can take care of that nit while landing

jasnell pushed a commit that referenced this pull request Mar 22, 2017
PR-URL: #11938 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: Brian White <[email protected]>
@jasnell
Copy link
Member

Landed in 221b03a

@jasnelljasnell closed this Mar 22, 2017
@jasnelljasnell mentioned this pull request Apr 4, 2017
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

eventsIssues and PRs related to the events subsystem / EventEmitter.semver-majorPRs that contain breaking changes and should be released in the next major version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants

@DavidCai1111@vsemozhetbyt@mscdex@jasnell@lpinca@cjihrig@hiroppy@nodejs-github-bot@davidtaikocha