-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
lib,events: replace the attr listener of the wrapped listener with symbol. #36558
Conversation
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.
PTAL
lib/events.js
Outdated
kEventListener: { | ||
value: kEventListener, | ||
enumerable: false, | ||
configurable: false, | ||
writable: false, |
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.
Why is this property needs to be attached to the ``EventEmitter` object?
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.
Seem EventTarget needs to use the attributes, should keep the attr same, maybe could use common define, where do you think I can define it.
lib/events.js
Outdated
const l = listener[kEventListener] ? listener[kEventListener] : listener; | ||
target.emit('newListener', type, l); |
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.
l
is not a very verbose name and doesn't dictates the meaning.
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.
Fixed. remove the useless temporary variables.
lib/events.js
Outdated
let handleListener = handler ? handler[kEventListener] : undefined; | ||
while (handleListener !== undefined) { | ||
ArrayPrototypePush(listeners, handleListener); |
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.
Why the need for removing null check?
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.
Fixed, still use the optional chaining
@@ -24,6 +24,7 @@ | |||
require('../common'); | |||
const assert = require('assert'); | |||
const events = require('events'); | |||
const { kEventListener } = events; |
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.
Why is this required, can it be restructured?
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.
Test the wrapped listener has this attr, and the value is the origin listener.
I've added the semver-major label as the property is used by user land modules. |
@nodejs/events |
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.
We should not remove the existing listener
property without a proper deprecation cycle. It could be made an alias of the new symbol. Also, the symbol should be declared directly in events.js rather than in internal/util
requiring a new import here. It would also likely be a good idea to use Symbol.for()
(SymbolFor
from primordials
) to define it.
@jasnell I have some questions:
|
I think the goal is to let it be accessible to users, so they can mutate its value, but you decrease the risk of a clash with a user-specific utility (I mean, if someone is setting |
@aduh95 thanks for your reply. |
I don't disagree on the philosophical level, the issue is it's being used by user land modules, so removing it wouldn't be acceptable without going through a deprecation cycle first. Improving the documentation is of course always welcome. |
Sure, I agree. but it may require the module developers to decide whether the modification is necessary and how to deal with it. |
Fixes: #36522
Replace the attr
listener
of the wrapped listener with a symbol.Related Issues
Fixes: #36522
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes