[Pkg-javascript-commits] [node-stream-http] 07/208: Fix IE9

Bastien Roucariès rouca at moszumanska.debian.org
Sun Aug 13 13:39:23 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 1be1ca8a7fb83f3fedf161b378b5a1f93c8b4745
Author: John Hiesey <john at hiesey.com>
Date:   Wed Jul 1 20:52:02 2015 -0700

    Fix IE9
---
 capability.js | 14 ++++++++------
 response.js   | 16 ++++++++++------
 2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/capability.js b/capability.js
index 2dc7c6b..f262d7b 100644
--- a/capability.js
+++ b/capability.js
@@ -2,7 +2,10 @@ var util = require('util')
 
 exports.fetch = util.isFunction(window.fetch)
 
-function checkTypeSupport (xhr, type) {
+var xhr = new window.XMLHttpRequest()
+xhr.open('GET', '/')
+
+function checkTypeSupport (type) {
 	try {
 		xhr.responseType = type
 		return xhr.responseType === type
@@ -10,12 +13,11 @@ function checkTypeSupport (xhr, type) {
 	return false
 }
 
-var xhr = new window.XMLHttpRequest()
-xhr.open('GET', '/')
+var arrayBufferGood = util.isFunction(window.ArrayBuffer) && util.isFunction(window.ArrayBuffer.prototype.slice)
 
-exports.arraybuffer = checkTypeSupport('arraybuffer')
-exports.msstream = checkTypeSupport('ms-stream') && util.isFunction(ArrayBuffer.prototype.slice)
-exports.mozchunkedarraybuffer = checkTypeSupport('moz-chunked-arraybuffer')
+exports.arraybuffer = arrayBufferGood && checkTypeSupport(xhr, 'arraybuffer')
+exports.msstream = arrayBufferGood && checkTypeSupport(xhr, 'ms-stream')
+exports.mozchunkedarraybuffer = arrayBufferGood && checkTypeSupport('moz-chunked-arraybuffer')
 exports.overrideMimeType = util.isFunction(xhr.overrideMimeType)
 
 xhr = null // Help gc
diff --git a/response.js b/response.js
index e038896..d4d3552 100644
--- a/response.js
+++ b/response.js
@@ -86,10 +86,12 @@ IncomingMessage.prototype._onXHRReadyStateChange = function () {
 
 	var xhr = self._xhr
 
+	var response
 	switch (self._mode) {
 		case 'text': // slice
-			if (xhr.response.length > self._pos) {
-				var newData = xhr.response.substr(self._pos)
+			response = xhr.responseText
+			if (response.length > self._pos) {
+				var newData = response.substr(self._pos)
 				if (self._charset === 'x-user-defined') {
 					var buffer = new Buffer(newData.length)
 					for (var i = 0; i < newData.length; i++)
@@ -99,15 +101,17 @@ IncomingMessage.prototype._onXHRReadyStateChange = function () {
 				} else {
 					self.push(newData, self._charset)
 				}
-				self._pos = xhr.response.length
+				self._pos = response.length
 			}
 			break
 		case 'moz-chunked-arraybuffer': // take whole
-			if (xhr.readyState !== rStates.LOADING || !xhr.response)
+			response = xhr.response
+			if (xhr.readyState !== rStates.LOADING || !response)
 				break
-			self.push(new Buffer(new Uint8Array(xhr.response)))
+			self.push(new Buffer(new Uint8Array(response)))
 			break
 		case 'ms-stream':
+			response = xhr.response
 			if (xhr.readyState !== rStates.LOADING)
 				break
 			var reader = new window.MSStreamReader()
@@ -122,7 +126,7 @@ IncomingMessage.prototype._onXHRReadyStateChange = function () {
 				self.emit('close')
 			}
 			// reader.onerror = ??? // TODO: this
-			reader.readAsArrayBuffer(xhr.response)
+			reader.readAsArrayBuffer(response)
 			break
 	}
 

-- 
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