[Pkg-javascript-commits] [sockjs-client] 175/434: IE9 fires `onerror` event randomly. Let's delay it for a while to make sure that json really wasn't loaded.

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:12 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 e140196b577fce90c2b08ec4f27cab8abd07a79e
Author: Marek Majkowski <majek04 at gmail.com>
Date:   Thu Oct 20 14:27:01 2011 +0100

    IE9 fires `onerror` event randomly. Let's delay it for a while to make sure that json really wasn't loaded.
---
 lib/trans-jsonp-receiver.js | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/lib/trans-jsonp-receiver.js b/lib/trans-jsonp-receiver.js
index b35cd5d..749c741 100644
--- a/lib/trans-jsonp-receiver.js
+++ b/lib/trans-jsonp-receiver.js
@@ -22,12 +22,25 @@ var jsonPGenericReceiver = function(url, callback) {
         }
     };
 
+    // IE9 fires 'error' event after orsc or before, in random order.
+    var loaded_okay = false;
+    var error_timer = null;
+
     script.id = 'a' + utils.random_string(8);
     script.src = url;
     script.type = 'text/javascript';
     script.charset = 'UTF-8';
-    script.onerror = function() {
-        close_script(utils.closeFrame(1006, "JSONP script loaded abnormally (onerror)"));
+    script.onerror = function(e) {
+        if (!error_timer) {
+            // Delay firing close_script.
+            error_timer = setTimeout(function() {
+                if (!loaded_okay) {
+                    close_script(utils.closeFrame(
+                        1006,
+                        "JSONP script loaded abnormally (onerror)"));
+                }
+            }, 1000);
+        }
     };
     script.onload = function(e) {
         close_script(utils.closeFrame(1006, "JSONP script loaded abnormally (onload)"));
@@ -36,6 +49,7 @@ var jsonPGenericReceiver = function(url, callback) {
     script.onreadystatechange = function(e) {
         if (/loaded|closed/.test(script.readyState)) {
             if (script && script.htmlFor && script.onclick) {
+                loaded_okay = true;
                 try {
                     // In IE, actually execute the script.
                     script.onclick();

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