1
|
exports.fetch = isFunction(global.fetch) && isFunction(global.ReadableStream)
|
2
|
|
3
|
exports.writableStream = isFunction(global.WritableStream)
|
4
|
|
5
|
exports.abortController = isFunction(global.AbortController)
|
6
|
|
7
|
exports.blobConstructor = false
|
8
|
try {
|
9
|
new Blob([new ArrayBuffer(1)])
|
10
|
exports.blobConstructor = true
|
11
|
} catch (e) {}
|
12
|
|
13
|
// The xhr request to example.com may violate some restrictive CSP configurations,
|
14
|
// so if we're running in a browser that supports `fetch`, avoid calling getXHR()
|
15
|
// and assume support for certain features below.
|
16
|
var xhr
|
17
|
function getXHR () {
|
18
|
// Cache the xhr value
|
19
|
if (xhr !== undefined) return xhr
|
20
|
|
21
|
if (global.XMLHttpRequest) {
|
22
|
xhr = new global.XMLHttpRequest()
|
23
|
// If XDomainRequest is available (ie only, where xhr might not work
|
24
|
// cross domain), use the page location. Otherwise use example.com
|
25
|
// Note: this doesn't actually make an http request.
|
26
|
try {
|
27
|
xhr.open('GET', global.XDomainRequest ? '/' : 'https://example.com')
|
28
|
} catch(e) {
|
29
|
xhr = null
|
30
|
}
|
31
|
} else {
|
32
|
// Service workers don't have XHR
|
33
|
xhr = null
|
34
|
}
|
35
|
return xhr
|
36
|
}
|
37
|
|
38
|
function checkTypeSupport (type) {
|
39
|
var xhr = getXHR()
|
40
|
if (!xhr) return false
|
41
|
try {
|
42
|
xhr.responseType = type
|
43
|
return xhr.responseType === type
|
44
|
} catch (e) {}
|
45
|
return false
|
46
|
}
|
47
|
|
48
|
// For some strange reason, Safari 7.0 reports typeof global.ArrayBuffer === 'object'.
|
49
|
// Safari 7.1 appears to have fixed this bug.
|
50
|
var haveArrayBuffer = typeof global.ArrayBuffer !== 'undefined'
|
51
|
var haveSlice = haveArrayBuffer && isFunction(global.ArrayBuffer.prototype.slice)
|
52
|
|
53
|
// If fetch is supported, then arraybuffer will be supported too. Skip calling
|
54
|
// checkTypeSupport(), since that calls getXHR().
|
55
|
exports.arraybuffer = exports.fetch || (haveArrayBuffer && checkTypeSupport('arraybuffer'))
|
56
|
|
57
|
// These next two tests unavoidably show warnings in Chrome. Since fetch will always
|
58
|
// be used if it's available, just return false for these to avoid the warnings.
|
59
|
exports.msstream = !exports.fetch && haveSlice && checkTypeSupport('ms-stream')
|
60
|
exports.mozchunkedarraybuffer = !exports.fetch && haveArrayBuffer &&
|
61
|
checkTypeSupport('moz-chunked-arraybuffer')
|
62
|
|
63
|
// If fetch is supported, then overrideMimeType will be supported too. Skip calling
|
64
|
// getXHR().
|
65
|
exports.overrideMimeType = exports.fetch || (getXHR() ? isFunction(getXHR().overrideMimeType) : false)
|
66
|
|
67
|
exports.vbArray = isFunction(global.VBArray)
|
68
|
|
69
|
function isFunction (value) {
|
70
|
return typeof value === 'function'
|
71
|
}
|
72
|
|
73
|
xhr = null // Help gc
|