[Pkg-javascript-commits] [sockjs-client] 308/434: IE7 doesn't look at /info, thus returns different error (2000 not 1002)

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:21 UTC 2014


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

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

commit 76686f53c84c29a434938c108ff40d1cf260fd35
Author: Marek Majkowski <majek04 at gmail.com>
Date:   Mon Jan 16 11:48:19 2012 +0000

    IE7 doesn't look at /info, thus returns different error (2000 not 1002)
---
 lib/dom2.js                         | 17 +++++++++++++++
 lib/info.js                         | 43 +++++++++++++++++++------------------
 tests/html/src/endtoendtests.coffee | 20 +++++++++++------
 3 files changed, 53 insertions(+), 27 deletions(-)

diff --git a/lib/dom2.js b/lib/dom2.js
index b944715..426ef06 100644
--- a/lib/dom2.js
+++ b/lib/dom2.js
@@ -136,3 +136,20 @@ XDRObject.prototype.close = function() {
     that.nuke();
     that._cleanup(true);
 };
+
+// 1. Is natively via XHR
+// 2. Is natively via XDR
+// 3. Nope, but postMessage is there so it should work via the Iframe.
+// 4. Nope, sorry.
+utils.isXHRCorsCapable = function() {
+    if (_window.XMLHttpRequest && 'withCredentials' in new XMLHttpRequest()) {
+        return 1;
+    }
+    if (_window.XDomainRequest) {
+        return 2;
+    }
+    if (IframeTransport.enabled()) {
+        return 3;
+    }
+    return 4;
+};
diff --git a/lib/info.js b/lib/info.js
index 418bfec..b76b27a 100644
--- a/lib/info.js
+++ b/lib/info.js
@@ -1,19 +1,17 @@
-var InfoReceiver = function(base_url) {
+var InfoReceiver = function(base_url, AjaxObject) {
     var that = this;
-    that.base_url = base_url;
-    that.t0 = (new Date()).getTime();
-    utils.delay(function(){that.doXhr();});
+    utils.delay(function(){that.doXhr(base_url, AjaxObject);});
 };
 
 InfoReceiver.prototype = new EventEmitter(['finish']);
 
-InfoReceiver.prototype.doXhr = function() {
+InfoReceiver.prototype.doXhr = function(base_url, AjaxObject) {
     var that = this;
-    var AjaxObject = _window.XDomainRequest ? utils.XDRObject : utils.XHRObject;
-    var xo = new AjaxObject('GET', that.base_url + '/info' , null);
+    var t0 = (new Date()).getTime();
+    var xo = new AjaxObject('GET', base_url + '/info' , null);
     xo.onfinish = function(status, text) {
         if (status === 200) {
-            var rtt = (new Date()).getTime() - that.t0;
+            var rtt = (new Date()).getTime() - t0;
             var info = JSON.parse(text);
             if (typeof info !== 'object') info = {};
             that.emit('finish', info, rtt);
@@ -66,26 +64,29 @@ var InfoReceiverFake = function() {
 };
 InfoReceiverFake.prototype = new EventEmitter(['finish']);
 
-
-
 var createInfoReceiver = function(base_url) {
-    // 1. Local url or CORS
-    if (utils.isLocalUrl(base_url) ||
-        _window.XDomainRequest ||
-        (_window.XMLHttpRequest && 'withCredentials' in new XMLHttpRequest())) {
-        return new InfoReceiver(base_url);
+    if (utils.isLocalUrl(base_url)) {
+        // If, for some reason, we have SockJS locally - there's no
+        // need to start up the complex machinery. Just use ajax.
+        return new InfoReceiver(base_url, utils.XHRObject);
     }
-    // 2. Iframe - Opera
-    if (IframeTransport.enabled()) {
+    switch (utils.isXHRCorsCapable()) {
+    case 1:
+        return new InfoReceiver(base_url, utils.XHRObject);
+    case 2:
+        return new InfoReceiver(base_url, utils.XDRObject);
+    case 3:
+        // Opera
         return new InfoReceiverIframe(base_url);
-    }
-    // 3. IE 7
-    return new InfoReceiverFake();
+    default:
+        // IE 7
+        return new InfoReceiverFake();
+    };
 };
 
 
 var WInfoReceiverIframe = FacadeJS['w-iframe-info-receiver'] = function(ri, _trans_url, base_url) {
-    var ir = new InfoReceiver(base_url);
+    var ir = new InfoReceiver(base_url, utils.XHRObject);
     ir.onfinish = function(info, rtt) {
         ri._didMessage('m'+JSON.stringify([info, rtt]));
         ri._didClose();
diff --git a/tests/html/src/endtoendtests.coffee b/tests/html/src/endtoendtests.coffee
index 5238b7c..cadc697 100644
--- a/tests/html/src/endtoendtests.coffee
+++ b/tests/html/src/endtoendtests.coffee
@@ -59,9 +59,13 @@ asyncTest "invalid url 404", ->
     r.onmessage = (e) ->
         fail(true)
     r.onclose = (e) ->
-        log('404', e)
-        equals(e.code, 1002)
-        equals(e.reason, 'Can\'t connect to server')
+        if u.isXHRCorsCapable() < 4
+            equals(e.code, 1002)
+            equals(e.reason, 'Can\'t connect to server')
+        else
+            # IE 7 doesn't look at /info, unfortunately
+            equals(e.code, 2000)
+            equals(e.reason, 'All transports failed')
         equals(e.wasClean, false)
         start()
 
@@ -73,8 +77,12 @@ asyncTest "invalid url port", ->
     r.onopen = (e) ->
         fail(true)
     r.onclose = (e) ->
-        log('port', e)
-        equals(e.code, 1002)
-        equals(e.reason, 'Can\'t connect to server')
+        if u.isXHRCorsCapable() < 4
+            equals(e.code, 1002)
+            equals(e.reason, 'Can\'t connect to server')
+        else
+            # IE 7 doesn't look at /info, unfortunately
+            equals(e.code, 2000)
+            equals(e.reason, 'All transports failed')
         equals(e.wasClean, false)
         start()

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