[Pkg-javascript-commits] [sockjs-client] 374/434: Fix #55: don't leak iframe object, expose postMessage interface only

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:26 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 51b3a47274e53ac38c9dd67a8a407ba3861e2c9a
Author: Marek Majkowski <majek04 at gmail.com>
Date:   Mon Mar 26 17:08:51 2012 +0100

    Fix #55: don't leak iframe object, expose postMessage interface only
---
 lib/dom.js                     | 23 +++++++++++++++++++++--
 lib/trans-iframe.js            |  2 +-
 tests/html/src/domtests.coffee |  2 +-
 3 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/lib/dom.js b/lib/dom.js
index 011d8d9..789a42d 100644
--- a/lib/dom.js
+++ b/lib/dom.js
@@ -115,6 +115,16 @@ utils.createIframe = function (iframe_url, error_callback) {
             error_callback(r);
         }
     };
+    var post = function(msg, origin) {
+        try {
+            // When the iframe is not loaded, IE raises an exception
+            // on 'contentWindow'.
+            if (iframe && iframe.contentWindow) {
+                iframe.contentWindow.postMessage(msg, origin);
+            }
+        } catch (x) {};
+    };
+
     iframe.src = iframe_url;
     iframe.style.display = 'none';
     iframe.style.position = 'absolute';
@@ -129,7 +139,7 @@ utils.createIframe = function (iframe_url, error_callback) {
     tref = setTimeout(function(){onerror('timeout');}, 5000);
     utils.attachEvent('unload', cleanup);
     return {
-        iframe: iframe,
+        post: post,
         cleanup: cleanup,
         loaded: unattach
     };
@@ -160,6 +170,15 @@ utils.createHtmlfile = function (iframe_url, error_callback) {
             error_callback(r);
         }
     };
+    var post = function(msg, origin) {
+        try {
+            // When the iframe is not loaded, IE raises an exception
+            // on 'contentWindow'.
+            if (iframe && iframe.contentWindow) {
+                iframe.contentWindow.postMessage(msg, origin);
+            }
+        } catch (x) {};
+    };
 
     doc.open();
     doc.write('<html><s' + 'cript>' +
@@ -175,7 +194,7 @@ utils.createHtmlfile = function (iframe_url, error_callback) {
     tref = setTimeout(function(){onerror('timeout');}, 5000);
     utils.attachEvent('unload', cleanup);
     return {
-        iframe: iframe,
+        post: post,
         cleanup: cleanup,
         loaded: unattach
     };
diff --git a/lib/trans-iframe.js b/lib/trans-iframe.js
index afde859..cf4d5e0 100644
--- a/lib/trans-iframe.js
+++ b/lib/trans-iframe.js
@@ -69,7 +69,7 @@ IframeTransport.prototype.onmessage = function(e) {
 
 IframeTransport.prototype.postMessage = function(type, data) {
     var that = this;
-    that.iframeObj.iframe.contentWindow.postMessage(that.window_id + type + (data || ''), that.origin);
+    that.iframeObj.post(that.window_id + type + (data || ''), that.origin);
 };
 
 IframeTransport.prototype.doSend = function (message) {
diff --git a/tests/html/src/domtests.coffee b/tests/html/src/domtests.coffee
index 2a72281..29ec0fe 100644
--- a/tests/html/src/domtests.coffee
+++ b/tests/html/src/domtests.coffee
@@ -81,7 +81,7 @@ else
                         hook.iobj.loaded()
                         ok(true, 'start frame send')
                         origin = u.getOrigin(u.amendUrl('/'))
-                        hook.iobj.iframe.contentWindow.postMessage(hook.id + ' ' + 's' , origin)
+                        hook.iobj.post(hook.id + ' ' + 's' , origin)
                     when 'e'
                         ok(true, 'done hook called by an iframe')
                         hook.iobj.cleanup()

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