[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] [torbutton/maint-1.2] Alter how we wrap XPCOM calls.



Author: Mike Perry <mikeperry-git@xxxxxxxxxx>
Date: Sat, 12 Dec 2009 17:40:12 -0800
Subject: Alter how we wrap XPCOM calls.
Commit: 855488536a6f0429dc90dd1924c142c760ece930

Throws seem to need to be converted to returns. Of course
this could be wrong. Need timeless to review it.
---
 src/components/certDialogsOverride.js  |    2 +-
 src/components/crash-observer.js       |    2 +-
 src/components/external-app-blocker.js |    2 +-
 src/components/ignore-history.js       |    2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/components/certDialogsOverride.js b/src/components/certDialogsOverride.js
index c844380..a9e881c 100644
--- a/src/components/certDialogsOverride.js
+++ b/src/components/certDialogsOverride.js
@@ -83,7 +83,7 @@ CertDialogsWrapper.prototype =
           var call;
           if(params.length) call = "("+params.join().replace(/(?:)/g,function(){return "p"+(++x)})+")";
           else call = "()";
-          var fun = "(function "+call+"{if (arguments.length < "+wrapped[method].length+") throw Components.results.NS_ERROR_XPC_NOT_ENOUGH_ARGS; return wrapped."+method+".apply(wrapped, arguments);})";
+          var fun = "(function "+call+"{if (arguments.length < "+wrapped[method].length+") return Components.results.NS_ERROR_XPC_NOT_ENOUGH_ARGS; try { return wrapped."+method+".apply(wrapped, arguments);} catch(e) { return e.result; }})";
           newObj[method] = eval(fun);
           //dump("wrapped: "+method+": "+fun+"\n");
       } else {
diff --git a/src/components/crash-observer.js b/src/components/crash-observer.js
index b64c7f0..9301760 100644
--- a/src/components/crash-observer.js
+++ b/src/components/crash-observer.js
@@ -89,7 +89,7 @@ StoreWrapper.prototype =
           var x = 0;
           if(params.length) call = "("+params.join().replace(/(?:)/g,function(){return "p"+(++x)})+")";
           else call = "()";
-          var fun = "(function "+call+"{if (arguments.length < "+wrapped[method].length+") throw Components.results.NS_ERROR_XPC_NOT_ENOUGH_ARGS; return wrapped."+method+".apply(wrapped, arguments);})";
+          var fun = "(function "+call+"{if (arguments.length < "+wrapped[method].length+") return Components.results.NS_ERROR_XPC_NOT_ENOUGH_ARGS; try { return wrapped."+method+".apply(wrapped, arguments);} catch(e) { return e.result; }})";
           // already in scope
           //var Components = this.Components;
           newObj[method] = eval(fun);
diff --git a/src/components/external-app-blocker.js b/src/components/external-app-blocker.js
index fc8993b..4b8e178 100644
--- a/src/components/external-app-blocker.js
+++ b/src/components/external-app-blocker.js
@@ -113,7 +113,7 @@ ExternalWrapper.prototype =
           var call;
           if(params.length) call = "("+params.join().replace(/(?:)/g,function(){return "p"+(++x)})+")";
           else call = "()";
-          var fun = "(function "+call+"{if (arguments.length < "+wrapped[method].length+") throw Components.results.NS_ERROR_XPC_NOT_ENOUGH_ARGS; return wrapped."+method+".apply(wrapped, arguments);})";
+          var fun = "(function "+call+"{if (arguments.length < "+wrapped[method].length+") return Components.results.NS_ERROR_XPC_NOT_ENOUGH_ARGS; try { return wrapped."+method+".apply(wrapped, arguments);} catch(e) { return e.result; }})";
           newObj[method] = eval(fun);
        } else {
           newObj.__defineGetter__(method, function() { return wrapped[method]; });
diff --git a/src/components/ignore-history.js b/src/components/ignore-history.js
index 730690e..046468a 100644
--- a/src/components/ignore-history.js
+++ b/src/components/ignore-history.js
@@ -188,7 +188,7 @@ HistoryWrapper.prototype =
           var call;
           if(params.length) call = "("+params.join().replace(/(?:)/g,function(){return "p"+(++x)})+")";
           else call = "()";
-          var fun = "(function "+call+"{if (arguments.length < "+wrapped[method].length+") throw Components.results.NS_ERROR_XPC_NOT_ENOUGH_ARGS; return wrapped."+method+".apply(wrapped, arguments);})";
+          var fun = "(function "+call+"{if (arguments.length < "+wrapped[method].length+") return Components.results.NS_ERROR_XPC_NOT_ENOUGH_ARGS; try { return wrapped."+method+".apply(wrapped, arguments);} catch(e) { return e.result; }})";
           newObj[method] = eval(fun);
        } else {
           newObj.__defineGetter__(method, function() { return wrapped[method]; });
-- 
1.5.6.5