[Pkg-javascript-commits] [sockjs-client] 161/350: Fix end-to-end in IE6

tonnerre at ancient-solutions.com tonnerre at ancient-solutions.com
Fri Aug 5 01:03:58 UTC 2016


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

tonnerre-guest pushed a commit to branch upstream
in repository sockjs-client.

commit 27e294cef57d012bc68b1bcb4df2585c832b721e
Author: Bryce Kahle <bkahle at gmail.com>
Date:   Thu Oct 16 21:50:37 2014 -0400

    Fix end-to-end in IE6
---
 lib/info-receiver.js                  |  4 ++--
 lib/transport/browser/abstract-xhr.js | 20 ++++++++++++++------
 tests/lib/end-to-end.js               |  8 ++++++++
 3 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/lib/info-receiver.js b/lib/info-receiver.js
index c4cb768..42ac813 100644
--- a/lib/info-receiver.js
+++ b/lib/info-receiver.js
@@ -19,7 +19,7 @@ function InfoReceiver(baseUrl) {
   EventEmitter.call(this);
 
   process.nextTick(function(){
-    self.doXhr(baseUrl, self._getReceiver(baseUrl));
+    self.doXhr(baseUrl, InfoReceiver._getReceiver(baseUrl));
   });
 }
 
@@ -27,7 +27,7 @@ util.inherits(InfoReceiver, EventEmitter);
 
 // TODO this is currently ignoring the list of available transports and the whitelist
 
-InfoReceiver.prototype._getReceiver = function (baseUrl) {
+InfoReceiver._getReceiver = function (baseUrl) {
   // determine method of CORS support (if needed)
   if (origin.isSameOriginUrl(baseUrl, loc.href)) {
     return XHRLocal;
diff --git a/lib/transport/browser/abstract-xhr.js b/lib/transport/browser/abstract-xhr.js
index eda938e..b157b15 100644
--- a/lib/transport/browser/abstract-xhr.js
+++ b/lib/transport/browser/abstract-xhr.js
@@ -16,11 +16,6 @@ function AbstractXHRObject(method, url, payload, opts) {
   } catch(x) {}
 
   if (!this.xhr) {
-    try {
-      this.xhr = new global.ActiveXObject('Microsoft.XMLHTTP');
-    } catch(x) {}
-  }
-  if (!this.xhr) {
     debug('no xhr');
     this.emit('finish', 0, 'no xhr support');
     this._cleanup();
@@ -49,10 +44,11 @@ function AbstractXHRObject(method, url, payload, opts) {
     return;
   }
 
-  if (!opts || !opts.noCredentials) {
+  if ((!opts || !opts.noCredentials) && AbstractXHRObject.supportsCORS) {
     debug('withCredentials');
     // Mozilla docs says https://developer.mozilla.org/en/XMLHttpRequest :
     // "This never affects same-site requests."
+
     this.xhr.withCredentials = 'true';
   }
   if (opts && opts.headers) {
@@ -142,6 +138,18 @@ AbstractXHRObject.prototype.close = function() {
 };
 
 AbstractXHRObject.enabled = !!global.XMLHttpRequest;
+// override XMLHttpRequest for IE6/7
+if (!AbstractXHRObject.enabled && global.ActiveXObject) {
+  debug('overriding xmlhttprequest');
+  global.XMLHttpRequest = function () {
+    try {
+      return new global.ActiveXObject('Microsoft.XMLHTTP');
+    } catch (e) {
+      return null;
+    }
+  };
+  AbstractXHRObject.enabled = !!new global.XMLHttpRequest();
+}
 
 var cors = false;
 try { cors = 'withCredentials' in new global.XMLHttpRequest(); }
diff --git a/tests/lib/end-to-end.js b/tests/lib/end-to-end.js
index bfbfe4c..977410f 100644
--- a/tests/lib/end-to-end.js
+++ b/tests/lib/end-to-end.js
@@ -2,6 +2,8 @@
 
 var expect = require('expect.js')
   , testUtils = require('./test-utils')
+  , InfoReceiver = require('../../lib/info-receiver')
+  , XHRFake = require('../../lib/transport/sender/xhr-fake')
   ;
 
 describe('End to End', function () {
@@ -30,6 +32,12 @@ describe('End to End', function () {
       } else {
         badUrl = 'http://localhost:1079';
       }
+      // TODO this isn't a greay way to disable this test
+      if (InfoReceiver._getReceiver(badUrl) === XHRFake) {
+        // CORS unsupported, won't actually hit info server
+        done();
+        return;
+      }
 
       var sjs = testUtils.newSockJs(badUrl, 'jsonp-polling');
       expect(sjs).to.be.ok();

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/sockjs-client.git



More information about the Pkg-javascript-commits mailing list