51 lines
1.7 KiB
JavaScript
51 lines
1.7 KiB
JavaScript
exports.fetch = isFunction(global.fetch) && isFunction(global.ReadableStream)
|
|
|
|
exports.blobConstructor = false
|
|
try {
|
|
new Blob([new ArrayBuffer(1)])
|
|
exports.blobConstructor = true
|
|
} catch (e) {}
|
|
|
|
// Service workers don't have XHR
|
|
var xhr = null
|
|
if (global.XMLHttpRequest) {
|
|
xhr = new global.XMLHttpRequest()
|
|
// If XDomainRequest is available (ie only, where xhr might not work
|
|
// cross domain), use the page location. Otherwise use example.com
|
|
// Note: this doesn't actually make an http request.
|
|
try {
|
|
xhr.open('GET', global.XDomainRequest ? '/' : 'https://example.com')
|
|
} catch(e) {
|
|
xhr = null
|
|
}
|
|
}
|
|
|
|
function checkTypeSupport (type) {
|
|
if (!xhr) return false
|
|
try {
|
|
xhr.responseType = type
|
|
return xhr.responseType === type
|
|
} catch (e) {}
|
|
return false
|
|
}
|
|
|
|
// For some strange reason, Safari 7.0 reports typeof global.ArrayBuffer === 'object'.
|
|
// Safari 7.1 appears to have fixed this bug.
|
|
var haveArrayBuffer = typeof global.ArrayBuffer !== 'undefined'
|
|
var haveSlice = haveArrayBuffer && isFunction(global.ArrayBuffer.prototype.slice)
|
|
|
|
exports.arraybuffer = haveArrayBuffer && checkTypeSupport('arraybuffer')
|
|
// These next two tests unavoidably show warnings in Chrome. Since fetch will always
|
|
// be used if it's available, just return false for these to avoid the warnings.
|
|
exports.msstream = !exports.fetch && haveSlice && checkTypeSupport('ms-stream')
|
|
exports.mozchunkedarraybuffer = !exports.fetch && haveArrayBuffer &&
|
|
checkTypeSupport('moz-chunked-arraybuffer')
|
|
exports.overrideMimeType = xhr ? isFunction(xhr.overrideMimeType) : false
|
|
exports.vbArray = isFunction(global.VBArray)
|
|
|
|
function isFunction (value) {
|
|
return typeof value === 'function'
|
|
}
|
|
|
|
xhr = null // Help gc
|