()
| 120 | } |
| 121 | |
| 122 | function Body() { |
| 123 | this.bodyUsed = false |
| 124 | |
| 125 | |
| 126 | this._initBody = function(body) { |
| 127 | this._bodyInit = body |
| 128 | if (typeof body === 'string') { |
| 129 | this._bodyText = body |
| 130 | } else if (support.blob && Blob.prototype.isPrototypeOf(body)) { |
| 131 | this._bodyBlob = body |
| 132 | } else if (support.formData && FormData.prototype.isPrototypeOf(body)) { |
| 133 | this._bodyFormData = body |
| 134 | } else if (!body) { |
| 135 | this._bodyText = '' |
| 136 | } else { |
| 137 | throw new Error('unsupported BodyInit type') |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | if (support.blob) { |
| 142 | this.blob = function() { |
| 143 | var rejected = consumed(this) |
| 144 | if (rejected) { |
| 145 | return rejected |
| 146 | } |
| 147 | |
| 148 | if (this._bodyBlob) { |
| 149 | return Promise.resolve(this._bodyBlob) |
| 150 | } else if (this._bodyFormData) { |
| 151 | throw new Error('could not read FormData body as blob') |
| 152 | } else { |
| 153 | return Promise.resolve(new Blob([this._bodyText])) |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | this.arrayBuffer = function() { |
| 158 | return this.blob().then(readBlobAsArrayBuffer) |
| 159 | } |
| 160 | |
| 161 | this.text = function() { |
| 162 | var rejected = consumed(this) |
| 163 | if (rejected) { |
| 164 | return rejected |
| 165 | } |
| 166 | |
| 167 | if (this._bodyBlob) { |
| 168 | return readBlobAsText(this._bodyBlob) |
| 169 | } else if (this._bodyFormData) { |
| 170 | throw new Error('could not read FormData body as text') |
| 171 | } else { |
| 172 | return Promise.resolve(this._bodyText) |
| 173 | } |
| 174 | } |
| 175 | } else { |
| 176 | this.text = function() { |
| 177 | var rejected = consumed(this) |
| 178 | return rejected ? rejected : Promise.resolve(this._bodyText) |
| 179 | } |
nothing calls this directly
no test coverage detected