11/**
22 * cross-storage - Cross domain local storage
33 *
4- * @version 0.4.0
4+ * @version 0.4.1
55 * @link https://github.com/zendesk/cross-storage
66 * @author Daniel St. Jules <[email protected] > 77 * @copyright Zendesk
@@ -252,7 +252,7 @@ CrossStorageClient.prototype._installListener = function() {
252252 var client = this ;
253253
254254 this . _listener = function ( message ) {
255- var i , error ;
255+ var i , error , response ;
256256
257257 if ( client . _closed ) return ;
258258
@@ -286,7 +286,12 @@ CrossStorageClient.prototype._installListener = function() {
286286 if ( message . data === 'ready' ) return ;
287287
288288 // All other messages
289- var response = JSON . parse ( message . data ) ;
289+ try {
290+ response = JSON . parse ( message . data ) ;
291+ } catch ( e ) {
292+ return ;
293+ }
294+
290295 if ( ! response . id ) return ;
291296
292297 if ( client . _requests [ response . id ] ) {
@@ -330,11 +335,13 @@ CrossStorageClient.prototype._poll = function() {
330335 * returns {HTMLIFrameElement} The iFrame element itself
331336 */
332337CrossStorageClient . prototype . _createFrame = function ( url ) {
333- var frame = window . document . createElement ( 'iframe' ) ;
338+ var frame , key ;
339+
340+ frame = window . document . createElement ( 'iframe' ) ;
334341 frame . id = this . _frameId ;
335342
336343 // Style the iframe
337- for ( var key in CrossStorageClient . frameStyle ) {
344+ for ( key in CrossStorageClient . frameStyle ) {
338345 if ( CrossStorageClient . frameStyle . hasOwnProperty ( key ) ) {
339346 frame . style [ key ] = CrossStorageClient . frameStyle [ key ] ;
340347 }
@@ -374,8 +381,10 @@ CrossStorageClient.prototype._request = function(method, params) {
374381 } ;
375382
376383 return new this . _promise ( function ( resolve , reject ) {
384+ var timeout , originalToJSON ;
385+
377386 // Timeout if a response isn't received after 4s
378- var timeout = setTimeout ( function ( ) {
387+ timeout = setTimeout ( function ( ) {
379388 if ( ! client . _requests [ req . id ] ) return ;
380389
381390 delete client . _requests [ req . id ] ;
@@ -391,8 +400,6 @@ CrossStorageClient.prototype._request = function(method, params) {
391400
392401 // In case we have a broken Array.prototype.toJSON, e.g. because of
393402 // old versions of prototype
394- var originalToJSON ;
395-
396403 if ( Array . prototype . toJSON ) {
397404 originalToJSON = Array . prototype . toJSON ;
398405 Array . prototype . toJSON = null ;
0 commit comments