-
Notifications
You must be signed in to change notification settings - Fork 30k
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
http: fix legacy http.Client instanceof #8103
Conversation
Ensures that objects created with http.createClient() have http.Client.prototype as their prototype.
Good catch. Maybe this change should just have assigned the prototype instead of extending the chain, i.e. |
We should probably remove this altogether in v7. The old http client API has been (hard) deprecated at least since 2012. |
@mscdex Yup, for sure. For now though I think this needs to be unbroken for LTS branches. @addaleax Hmm that's probably a more correct change, and fixes any general case of deprecating both the class and the factory like was done here. Also has the bonus of not touching deprecated code. I'll give that a shot, and if it works and breaks nothing, I'll PR-ify it and close this one. |
Ensure the wrapped class prototype is exactly the unwrapped class prototype, rather than an object whose prototype is the unwrapped class prototype. This ensures that instances of the unwrapped class are instances of the wrapped class. This is useful when both a wrapped class and a factory for the unwrapped class are both exposed. Ref: nodejs#8103
Closing in favor of #8105 |
Ensure the wrapped class prototype is exactly the unwrapped class prototype, rather than an object whose prototype is the unwrapped class prototype. This ensures that instances of the unwrapped class are instances of the wrapped class. This is useful when both a wrapped class and a factory for the unwrapped class are both exposed. Ref: #8103 PR-URL: #8105 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Ensure the wrapped class prototype is exactly the unwrapped class prototype, rather than an object whose prototype is the unwrapped class prototype. This ensures that instances of the unwrapped class are instances of the wrapped class. This is useful when both a wrapped class and a factory for the unwrapped class are both exposed. Ref: #8103 PR-URL: #8105 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Checklist
make -j4 test
(UNIX), orvcbuild test nosign
(Windows) passesAffected core subsystem(s)
http
Description of change
Ensures that objects created with
http.createClient()
havehttp.Client.prototype
as their prototype.The new
internalUtil.deprecate()
fixes instantiation of deprecated classes, but in this case, since the unwrapped deprecated class is instantiated and returned, the prototype on the created object is not the same as the exposed class.Setting the prototype on the new object to be prototype of the wrapped/exposed class fixes this, so now the following works fine:
Alternatives
Object.create(http.Client.prototype)
and then call the unwrapped constructor on the result (e.g. withClient.call(client, port, host)
). I think this is pretty much equivalent to what I did, so I'm happy to change it to this if people think it's cleaner.instanceof
relationship) that was broken by deprecating.