events: add ability to prepend event listeners
Pull Request check-list
-
Does make -j8 test
(UNIX) orvcbuild test nosign
(Windows) pass with this change (including linting)? -
Is the commit message formatted according to [CONTRIBUTING.md][0]? -
If this change fixes a bug (or a performance problem), is a regression test (or a benchmark) included? -
Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
NOTE: these things are not required to open a PR and can be done afterwards / while the PR is open.
Affected core subsystem(s)
events
Description of change
A handful of modules (including readable-streams) make inappropriate use of the internal _events property. One such use is to prepend an event listener to the front of the array of listeners.
To address part of the issue, this adds a new optional bitwise flag to the addListener/on/once methods that, when set, causes the listener to be prepended.
Doc update and test case is included.
Fixes: https://github.com/nodejs/node/issues/1817
/cc @ChALkeR