[Pkg-javascript-commits] [node-stream-http] 164/208: if xhr.open throws, then no xhr is allowed

Bastien Roucariès rouca at moszumanska.debian.org
Sun Aug 13 13:39:40 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-stream-http.

commit 1b077bf2494f2322eb9fb6adbad96d5e3cafdf59
Author: Dominic Tarr <dominic.tarr at gmail.com>
Date:   Fri Dec 9 21:04:31 2016 +0100

    if xhr.open throws, then no xhr is allowed
---
 lib/capability.js | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/lib/capability.js b/lib/capability.js
index cc19253..7b11328 100644
--- a/lib/capability.js
+++ b/lib/capability.js
@@ -2,28 +2,33 @@ exports.fetch = isFunction(global.fetch) && isFunction(global.ReadableStream)
 
 exports.blobConstructor = false
 try {
-	new Blob([new ArrayBuffer(1)])
-	exports.blobConstructor = true
+  new Blob([new ArrayBuffer(1)])
+  exports.blobConstructor = true
 } catch (e) {}
 
 // Service workers don't have XHR
 if (global.XMLHttpRequest) {
-	var 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
-	xhr.open('GET', global.XDomainRequest ? '/' : 'https://example.com')
+  var 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(_) {
+    xhr = null
+  }
 } else {
-	var xhr = null
+  var xhr = null
 }
 
 
 function checkTypeSupport (type) {
-	if (!xhr) return false
-	try {
-		xhr.responseType = type
-		return xhr.responseType === type
-	} catch (e) {}
-	return false
+  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'.
@@ -36,7 +41,7 @@ exports.arraybuffer = haveArrayBuffer && checkTypeSupport('arraybuffer')
 // 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')
+  checkTypeSupport('moz-chunked-arraybuffer')
 exports.overrideMimeType = xhr ? isFunction(xhr.overrideMimeType) : false
 exports.vbArray = isFunction(global.VBArray)
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-stream-http.git



More information about the Pkg-javascript-commits mailing list