Skip to content

Commit

Permalink
only define _initBody once
Browse files Browse the repository at this point in the history
  • Loading branch information
wheresrhys committed May 4, 2015
1 parent 9d08342 commit 94dcbfe
Showing 1 changed file with 15 additions and 27 deletions.
42 changes: 15 additions & 27 deletions fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,22 +125,23 @@
function Body() {
this.bodyUsed = false

if (support.blob) {
this._initBody = function(body) {
this._bodyInit = body
if (typeof body === 'string') {
this._bodyText = body
} else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
this._bodyBlob = body
} else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
this._bodyFormData = body
} else if (!body) {
this._bodyText = ''
} else {
throw new Error('unsupported BodyInit type')
}

this._initBody = function(body) {
this._bodyInit = body
if (typeof body === 'string') {
this._bodyText = body
} else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
this._bodyBlob = body
} else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
this._bodyFormData = body
} else if (!body) {
this._bodyText = ''
} else {
throw new Error('unsupported BodyInit type')
}
}

if (support.blob) {
this.blob = function() {
var rejected = consumed(this)
if (rejected) {
Expand Down Expand Up @@ -175,19 +176,6 @@
}
}
} else {
this._initBody = function(body) {
this._bodyInit = body
if (typeof body === 'string') {
this._bodyText = body
} else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
this._bodyFormData = body
} else if (!body) {
this._bodyText = ''
} else {
throw new Error('unsupported BodyInit type')
}
}

this.text = function() {
var rejected = consumed(this)
return rejected ? rejected : Promise.resolve(this._bodyText)
Expand Down

0 comments on commit 94dcbfe

Please sign in to comment.