-
-
Notifications
You must be signed in to change notification settings - Fork 16.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix inheritance should not overwrite the methods of http.ServerRespon…
…se and http.IncomingMessage
- Loading branch information
Showing
3 changed files
with
62 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
function setPrototypeUntil(obj, proto, until) { | ||
var currentProto = proto; | ||
until = until || proto; | ||
var last = Object.getPrototypeOf(until); | ||
while (currentProto && currentProto !== last) { | ||
Object.keys(currentProto).forEach(function (key) { | ||
setPrototypeKey(obj, proto, key, until) | ||
}); | ||
currentProto = Object.getPrototypeOf(currentProto) | ||
} | ||
} | ||
|
||
function setPrototypeKey(obj, proto, key, until) { | ||
Object.defineProperty(obj, key, { | ||
configurable: true, | ||
enumerable: proto.propertyIsEnumerable(key), | ||
get: function () { | ||
var desc = Object.getOwnPropertyDescriptor(until, key) | ||
if (desc && typeof desc.get === 'function') { | ||
// property defined with defineGetter, we need to change the `this` of the getter accordingly | ||
return desc.get.call(obj) | ||
} | ||
return proto[key] | ||
}, | ||
set: function (v) { | ||
proto[key] = v | ||
} | ||
}) | ||
} | ||
|
||
module.exports = setPrototypeUntil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters