http: fix legacy http.Client instanceof
Checklist
-
make -j4 test
(UNIX), orvcbuild test nosign
(Windows) passes -
tests and/or benchmarks are included -
documentation is changed or added -
commit message follows commit guidelines
Affected core subsystem(s)
http
Description of change
Ensures that objects created with http.createClient()
have http.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:
http.createClient() instanceof http.Client
Alternatives
- Instantiate the wrapped class. This would work fine, but you'd double up the deprecation messages, which is undesirable.
-
Use
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. -
Ignore this since it's deprecated. I'd rather not, since this is something intuitive and previously working (the
instanceof
relationship) that was broken by deprecating.