Factor out Body mixin

This commit is contained in:
Timothy Gu 2017-02-26 14:42:09 -08:00
parent f08b120771
commit 9e140039ac
3 changed files with 12 additions and 12 deletions

View File

@ -121,6 +121,16 @@ Body.prototype = {
};
Body.mixIn = function (proto) {
for (const name of Object.getOwnPropertyNames(Body.prototype)) {
// istanbul ignore else: future proof
if (!(name in proto)) {
const desc = Object.getOwnPropertyDescriptor(Body.prototype, name);
Object.defineProperty(proto, name, desc);
}
}
};
/**
* Decode buffers into utf-8 string
*

View File

@ -101,12 +101,7 @@ export default class Request {
}
}
for (const name of Object.getOwnPropertyNames(Body.prototype)) {
if (!(name in Request.prototype)) {
const desc = Object.getOwnPropertyDescriptor(Body.prototype, name);
Object.defineProperty(Request.prototype, name, desc);
}
}
Body.mixIn(Request.prototype);
Object.defineProperty(Request.prototype, Symbol.toStringTag, {
value: 'RequestPrototype',

View File

@ -58,12 +58,7 @@ export default class Response {
}
}
for (const name of Object.getOwnPropertyNames(Body.prototype)) {
if (!(name in Response.prototype)) {
const desc = Object.getOwnPropertyDescriptor(Body.prototype, name);
Object.defineProperty(Response.prototype, name, desc);
}
}
Body.mixIn(Response.prototype);
Object.defineProperty(Response.prototype, Symbol.toStringTag, {
value: 'ResponsePrototype',