提交 0c27c943 编写于 作者: J Joshua Peek

Merge pull request #78 from matthew-andrews/centralise-support-checks

Centralise the checks for blob and form data support
...@@ -92,26 +92,29 @@ ...@@ -92,26 +92,29 @@
return fileReaderReady(reader) return fileReaderReady(reader)
} }
var blobSupport = 'FileReader' in self && 'Blob' in self && (function() { var support = {
try { blob: 'FileReader' in self && 'Blob' in self && (function() {
new Blob(); try {
return true new Blob();
} catch(e) { return true
return false } catch(e) {
} return false
})(); }
})(),
formData: 'FormData' in self
}
function Body() { function Body() {
this.bodyUsed = false this.bodyUsed = false
if (blobSupport) { if (support.blob) {
this._initBody = function(body) { this._initBody = function(body) {
this._bodyInit = body this._bodyInit = body
if (typeof body === 'string') { if (typeof body === 'string') {
this._bodyText = body this._bodyText = body
} else if ('Blob' in self && Blob.prototype.isPrototypeOf(body)) { } else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
this._bodyBlob = body this._bodyBlob = body
} else if ('FormData' in self && FormData.prototype.isPrototypeOf(body)) { } else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
this._bodyFormData = body this._bodyFormData = body
} else if (!body) { } else if (!body) {
this._bodyText = '' this._bodyText = ''
...@@ -158,7 +161,7 @@ ...@@ -158,7 +161,7 @@
this._bodyInit = body this._bodyInit = body
if (typeof body === 'string') { if (typeof body === 'string') {
this._bodyText = body this._bodyText = body
} else if ('FormData' in self && FormData.prototype.isPrototypeOf(body)) { } else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
this._bodyFormData = body this._bodyFormData = body
} else if (!body) { } else if (!body) {
this._bodyText = '' this._bodyText = ''
...@@ -173,7 +176,7 @@ ...@@ -173,7 +176,7 @@
} }
} }
if ('FormData' in self) { if (support.formData) {
this.formData = function() { this.formData = function() {
return this.text().then(decode) return this.text().then(decode)
} }
...@@ -278,7 +281,7 @@ ...@@ -278,7 +281,7 @@
} }
xhr.open(self.method, self.url, true) xhr.open(self.method, self.url, true)
if ('responseType' in xhr && blobSupport) { if ('responseType' in xhr && support.blob) {
xhr.responseType = 'blob' xhr.responseType = 'blob'
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册