GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Prototype bleeding in events.js by martinheidegger · Pull Request #2044 · nodejs/node

Conversation

@martinheidegger

@martinheidegger martinheidegger commented Jun 23, 2015

Copy link
Copy Markdown

Inheriting from EventEmitter using .prototype-old-school-notation like this:

var MyClass = function() {};
MyClass.prototype = new EventEmitter();

will result in the listeners added to one instance being executed by listeners of another instance.

var ok = new MyClass();
var broken = new MyClass();
broken.on('x', function () { console.log('b'); });
ok.on('x', function () { console.log('a'); });
ok.emit('x'); // b a

This can be quite easily resolved by changing the inheritance to:

util.inherits(MyClass, EventEmitter);

or

MyClass.prototype = Object.create(EventEmitter.prototype);

but it still is a problem because even developers like substack seem to not be aware of this: https://github.com/substack/node-charm/blob/c6646deed2dcee7f512bbbfac6d2ab58fb528a68/index.js#L67

This PR - at the time of writing this - still just contains just the test. I am not sure how to fix this. Any help welcome.

Note: This fixes a problem that exists in older node versions as well, however: I found this bug/problem while investigating a different bug that started to appear in io.js after version 1.3.0 either due to 7061669dba or 630f636334 However my other bug was too hard to properly reproduce. Fixing this will fix the other bug as well.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@martinheidegger
Added new test for prototype bleeding
a38f9cf
@brendanashworth brendanashworth added events Issues and PRs related to EventEmitter and the events module. test Issues and PRs related to Node.js core tests and test infrastructure. labels Jun 23, 2015
@vkurchatkin

vkurchatkin commented Jun 23, 2015

Copy link
Copy Markdown
Contributor

This is a regression (I think)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bnoordhuis

bnoordhuis commented Jun 23, 2015

Copy link
Copy Markdown
Member

I think so too. nodejs/node-v0.x-archive#7157 was fixed over a year ago.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

thefourtheye
thefourtheye reviewed Jun 23, 2015
View reviewed changes
Comment thread test/parallel/test-event-emitter-prototype-bleeding.js Outdated

@thefourtheye thefourtheye Jun 23, 2015

Copy link
Copy Markdown
Contributor

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 function must be called, right? Why not assign some value to a variable here and check if the value is set in process.exit?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vkurchatkin vkurchatkin mentioned this pull request Jun 23, 2015
events: _events should be an own property #2046
Closed
@martinheidegger
Correcting style to be lint-conform.
21706a7
@martinheidegger

martinheidegger commented Jun 24, 2015

Copy link
Copy Markdown
Author

@thefourtheye Thank you for pointing the various things out. I pushed a style correction.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rvagg
rvagg force-pushed the master branch from 9d21135 to 628a3ab Compare June 25, 2015 09:18
@thefourtheye

thefourtheye commented Jul 12, 2015

Copy link
Copy Markdown
Contributor

I think we really have nothing to do here. Just clarifying how to properly inherit from EventEmitter in the docs should be enough. #2168

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@indutny
indutny force-pushed the master branch from bffb204 to eb35968 Compare July 22, 2015 21:21
@brendanashworth

brendanashworth commented Sep 3, 2015

Copy link
Copy Markdown
Contributor

The doc change was landed in d168d01. @thefourtheye is this still up for landing or should it be closed?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rvagg
rvagg force-pushed the master branch from 11c25c2 to ba02bd0 Compare September 6, 2015 11:55
@martinheidegger

martinheidegger commented Sep 7, 2015

Copy link
Copy Markdown
Author

https://github.com/search?utf8=%E2%9C%93&q=%22.prototype+%3D+new+EventEmitter%28%29%22&type=Code&ref=searchresults 4000 entries + in github that use that problematic, non-standard use of EventEmitter (word by word). And they are usually submissions of people that are confident enough to submit something to github. If it is only treated as a "documentation fixes this issue" (which I think it doesnt) then it should specifically mention that incompatibility.

Note: Old-school JavaScript inheritance like MyEventEmitter.prototype = new EventEmitter() does not work.

Also I think that it should be more prominent in the docs that this way of inheritance is actively regarded as harmful.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thefourtheye

thefourtheye commented Sep 10, 2015

Copy link
Copy Markdown
Contributor

@brendanashworth sorry. I couldn't respond earlier. But we already have this regression here https://github.com/nodejs/node/blob/master/test/parallel/test-event-emitter-subclass.js#L38-L49. So we can close this.

@martinheidegger You may want to propose a documentation change in a separate PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brendanashworth

brendanashworth commented Sep 10, 2015

Copy link
Copy Markdown
Contributor

It is unfortunate that so many people use this inheritance, but it doesn't make sense in the least. I agree a documentation fix is in order. Closing.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brendanashworth brendanashworth closed this Sep 10, 2015
This was referenced Aug 5, 2021
[Snyk] Fix for 1 vulnerabilities timzwit/node#14
Open
[Snyk] Fix for 1 vulnerabilities 137717unity/node#30
Open
[Snyk] Fix for 1 vulnerabilities thakursachin467/node#13
Open
[Snyk] Fix for 1 vulnerabilities Rednickle/node-1#25
Open
[Snyk] Fix for 1 vulnerabilities adamlaska/node#53
Open
[Snyk] Fix for 1 vulnerabilities aliceUnhinged613/node#29
Open
[Snyk] Fix for 1 vulnerabilities vaibhavb/node#15
Open
[Snyk] Fix for 1 vulnerabilities Bhanditz/node#15
Open
[Snyk] Fix for 1 vulnerabilities meghasfdc/node#39
Open
[Snyk] Fix for 1 vulnerabilities ajesse11x/node#24
Open
@zynda zynda mentioned this pull request Mar 22, 2024
[Snyk] Fix for 1 vulnerabilities zynda/node#20
Open
@olegnn olegnn mentioned this pull request Mar 22, 2024
[Snyk] Fix for 1 vulnerabilities olegnn/node#54
Open
@aborovsky aborovsky mentioned this pull request Mar 22, 2024
[Snyk] Fix for 1 vulnerabilities aborovsky/node#13
Closed
@ron-a20 ron-a20 mentioned this pull request Mar 22, 2024
[Snyk] Fix for 1 vulnerabilities ron-a20/node#120
Open
@solebox solebox mentioned this pull request Mar 22, 2024
[Snyk] Fix for 1 vulnerabilities solebox/node#37
Open
@timzwit timzwit mentioned this pull request Mar 22, 2024
[Snyk] Fix for 1 vulnerabilities timzwit/node#38
Open
@kissofire kissofire mentioned this pull request Mar 22, 2024
[Snyk] Fix for 1 vulnerabilities kissofire/node#123
Open
@AyushG3112 AyushG3112 mentioned this pull request Mar 22, 2024
[Snyk] Fix for 1 vulnerabilities AyushG3112/node#39
Open
@thakursachin467 thakursachin467 mentioned this pull request Mar 22, 2024
[Snyk] Fix for 1 vulnerabilities thakursachin467/node#36
Open
@ShubhraKar ShubhraKar mentioned this pull request Mar 22, 2024
[Snyk] Fix for 1 vulnerabilities ShubhraKar/node#43
Open
@RoeeOren RoeeOren mentioned this pull request Mar 22, 2024
[Snyk] Fix for 1 vulnerabilities RoeeOren/node#51
Open
@vaibhavb vaibhavb mentioned this pull request Mar 22, 2024
[Snyk] Fix for 1 vulnerabilities vaibhavb/node#51
Open
@GregorFendt GregorFendt mentioned this pull request Mar 22, 2024
[Snyk] Fix for 1 vulnerabilities GregorFendt/node#33
Open
@bumplzz69 bumplzz69 mentioned this pull request Mar 22, 2024
[Snyk] Fix for 1 vulnerabilities bumplzz69/node#65
Open
@luke7oaks luke7oaks mentioned this pull request Mar 22, 2024
[Snyk] Fix for 1 vulnerabilities luke7oaks/node-1#46
Open
@adamlaska adamlaska mentioned this pull request Mar 22, 2024
[Snyk] Fix for 1 vulnerabilities adamlaska/node#142
Open
@137717unity 137717unity mentioned this pull request Mar 22, 2024
[Snyk] Fix for 1 vulnerabilities 137717unity/node#123
Open
@fishbar fishbar mentioned this pull request Mar 22, 2024
[Snyk] Fix for 1 vulnerabilities fishbar/node-1#37
Open
@s4sc s4sc mentioned this pull request Mar 22, 2024
[Snyk] Fix for 1 vulnerabilities s4sc/node#37
Open
@jhudaz jhudaz mentioned this pull request Mar 22, 2024
[Snyk] Fix for 1 vulnerabilities jhudaz/node#66
Open
@Redwoodtj Redwoodtj mentioned this pull request Mar 22, 2024
[Snyk] Fix for 1 vulnerabilities Redwoodtj/node#15
Open
@Matthelonianxl Matthelonianxl mentioned this pull request Mar 22, 2024
[Snyk] Fix for 1 vulnerabilities Matthelonianxl/node#65
Open
@molllyn1 molllyn1 mentioned this pull request Mar 22, 2024
[Snyk] Fix for 1 vulnerabilities molllyn1/node#107
Open
@takeratta takeratta mentioned this pull request Mar 23, 2024
[Snyk] Fix for 1 vulnerabilities takeratta/node#15
Open
@awaisab172 awaisab172 mentioned this pull request Mar 23, 2024
[Snyk] Fix for 1 vulnerabilities awaisab172/node#57
Open
@wedataintelligence wedataintelligence mentioned this pull request Mar 23, 2024
[Snyk] Fix for 1 vulnerabilities wedataintelligence/node#106
Open
@enterstudio enterstudio mentioned this pull request Mar 23, 2024
[Snyk] Fix for 1 vulnerabilities enterstudio/node#37
Open
@ajesse11x ajesse11x mentioned this pull request Mar 23, 2024
[Snyk] Fix for 1 vulnerabilities ajesse11x/node#52
Open
@Bhanditz Bhanditz mentioned this pull request Mar 23, 2024
[Snyk] Fix for 1 vulnerabilities Bhanditz/node#41
Open
@sirinartk sirinartk mentioned this pull request Mar 24, 2024
[Snyk] Fix for 1 vulnerabilities sirinartk/node#56
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

events Issues and PRs related to EventEmitter and the events module. test Issues and PRs related to Node.js core tests and test infrastructure.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@martinheidegger @vkurchatkin @bnoordhuis @thefourtheye @brendanashworth
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.