singletons that are retroactively turned into EventEmitters should ca… #10995
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.
This follows up on a discussion that @mgc, @MarshallOfSound, and I had this week tracking down the root of the AutoUpdater error case crash.
First try
At the end of that debugging session we'd decided to defer the singletons' instantiation until after
Object.setPrototypeOf(AutoUpdater.prototype, EventEmitter.prototype)
was called so that the newly-created AutoUpdater would have its EventEmitter parent fields initialized.Unfortunately that's not going to work. Calling
new AutoUpdater()
in JS doesn't actually create a C++ AutoUpdater object because AutoUpdater and the other singletons don't insert a constructor into the JS bindings: (a) it's unnecessary binding code to (b) give clients the ability to create multiple instances of things designed to be singletons. So, while we could add constructor bindings to make this possible, it opens up more potential problems.Second try
EventEmitter() defers its initialization to an
init()
helper function, and Samuel suggested that would work as well. I'm going to chalk this up to my inexperience with JS but I wasn't able to getautoUpdater.init()
to work (and it is defined a little differently from other members, ieEventEmitter.init = function(){...}
vs.EventEmitter.prototype.setMaxLixteners = function(){...}
) but IMO this is just as well because the approach I used is cleaner & should work even if Node changes EventEmitter's internals.Third try
So after much prologue (and more digging and learning how native_mate works), we actually wind up with a pretty small & simple patch. after reparenting the singletons' prototypes, we call the parent's constructor...