-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Commit
By making sure the _events is always an object there is one less check that needs to be performed by emit. Use undefined instead of null. typeof checks are a lot faster than isArray. There are a few places where the this._events check cannot be removed because it is possible for the user to call those methods after using utils.extend to create their own EventEmitter, but before it has actually been instantiated.
- Loading branch information
There are no files selected for viewing
4 comments
on commit 4f7f8bb
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.
This commit triggers an error in the current nodeunit module:
events.js:80
var handler = this._events[type];
^
TypeError: Cannot read property 'set' of undefined
at Results.EventEmitter.emit (events.js:80:29)
at Results.addSet (/Users/bkelly/Dropbox/devel/test/node_modules/nodeunit/node_modules/tap/lib/tap-results.js:38:8)
at new Results (/Users/bkelly/Dropbox/devel/test/node_modules/nodeunit/node_modules/tap/lib/tap-results.js:13:8)
at GlobalHarness.Harness (/Users/bkelly/Dropbox/devel/test/node_modules/nodeunit/node_modules/tap/lib/tap-harness.js:31:18)
at new GlobalHarness (/Users/bkelly/Dropbox/devel/test/node_modules/nodeunit/node_modules/tap/lib/tap-global-harness.js:20:23)
at Object.<anonymous> (/Users/bkelly/Dropbox/devel/test/node_modules/nodeunit/node_modules/tap/lib/main.js:8:28)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
To reproduce all you have to do is:
[xykon-2:~] bkelly% mkdir hmm
[xykon-2:~] bkelly% cd hmm
[xykon-2:~/hmm] bkelly% npm install nodeunit
[xykon-2:~/hmm] bkelly% ./node_modules/nodeunit/bin/nodeunit foo
It doesn't seem to matter if you run nodeunit on a real set of tests or not, the error is the same.
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.
It appears this is occurring because tap Results
constructor is not chaining to its parent EventEmitter
constructor.
This is probably a bug in Results
, but could inflict widespread damage in many modules. Might want to consider lazy initializing since EventEmitter
has been around for a while without requiring its constructor called.
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.
Sorry, spoke too soon. It does still lazy initialize, but deleting line 80 in events.js causes it to trigger this error if no one has called addListener()
or on()
yet.
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.
See #4891
Suggest adding this line back.