Debian Codegraph @

polyfills/http-lib/capability.js

raw
1 export var hasFetch = isFunction(global.fetch) && isFunction(global.ReadableStream)
2
3 var _blobConstructor;
4 export function blobConstructor() {
5 if (typeof _blobConstructor !== 'undefined') {
6 return _blobConstructor;
7 }
8 try {
9 new global.Blob([new ArrayBuffer(1)])
10 _blobConstructor = true
11 } catch (e) {
12 _blobConstructor = false
13 }
14 return _blobConstructor
15 }
16 var xhr;
17
18 function checkTypeSupport(type) {
19 if (!xhr) {
20 xhr = new global.XMLHttpRequest()
21 // If location.host is empty, e.g. if this page/worker was loaded
22 // from a Blob, then use example.com to avoid an error
23 xhr.open('GET', global.location.host ? '/' : 'https://example.com')
24 }
25 try {
26 xhr.responseType = type
27 return xhr.responseType === type
28 } catch (e) {
29 return false
30 }
31
32 }
33
34 // For some strange reason, Safari 7.0 reports typeof global.ArrayBuffer === 'object'.
35 // Safari 7.1 appears to have fixed this bug.
36 var haveArrayBuffer = typeof global.ArrayBuffer !== 'undefined'
37 var haveSlice = haveArrayBuffer && isFunction(global.ArrayBuffer.prototype.slice)
38
39 export var arraybuffer = haveArrayBuffer && checkTypeSupport('arraybuffer')
40 // These next two tests unavoidably show warnings in Chrome. Since fetch will always
41 // be used if it's available, just return false for these to avoid the warnings.
42 export var msstream = !hasFetch && haveSlice && checkTypeSupport('ms-stream')
43 export var mozchunkedarraybuffer = !hasFetch && haveArrayBuffer &&
44 checkTypeSupport('moz-chunked-arraybuffer')
45 export var overrideMimeType = isFunction(xhr.overrideMimeType)
46 export var vbArray = isFunction(global.VBArray)
47
48 function isFunction(value) {
49 return typeof value === 'function'
50 }
51
52 xhr = null // Help gc