Factor out Body mixin
This commit is contained in:
parent
f08b120771
commit
9e140039ac
10
src/body.js
10
src/body.js
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in New Issue