From 881a6cd11f333c3bb3017e403f14107ac0b5baa0 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Thu, 10 Nov 2011 16:45:31 +0100 Subject: [PATCH] Rethrow exceptions for a better resolution to #9 --- postmessage.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/postmessage.js b/postmessage.js index 47f8822..5ff7d52 100644 --- a/postmessage.js +++ b/postmessage.js @@ -237,13 +237,14 @@ var NO_JQUERY = {}; } continue; } + + function sendReply ( data ) { + if (msg.callback) { + pm.send({target:e.source, data:data, type:msg.callback}); + } + } + try { - function sendReply ( data ) { - if (msg.callback) { - pm.send({target:e.source, data:data, type:msg.callback}); - } - } - if ( o.callback ) { o.fn(msg.data, sendReply, e); } else { @@ -254,6 +255,8 @@ var NO_JQUERY = {}; if (msg.errback) { // notify post message errback pm.send({target:e.source, data:ex, type:msg.errback}); + } else { + throw ex; } } }; @@ -381,13 +384,14 @@ var NO_JQUERY = {}; continue; } } + + function sendReply ( data ) { + if (msg.callback) { + pm.send({target:source_window, data:data, type:msg.callback, hash:true, url:hash.source.url}); + } + } + try { - function sendReply ( data ) { - if (msg.callback) { - pm.send({target:source_window, data:data, type:msg.callback, hash:true, url:hash.source.url}); - } - } - if ( o.callback ) { o.fn(msg.data, sendReply); } else { @@ -398,6 +402,8 @@ var NO_JQUERY = {}; if (msg.errback) { // notify post message errback pm.send({target:source_window, data:ex, type:msg.errback, hash:true, url:hash.source.url}); + } else { + throw ex; } } };