[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] [torbutton/maint-1.2] Update XPCOM hooks once more.
Author: Mike Perry <mikeperry-git@xxxxxxxxxx>
Date: Wed, 16 Dec 2009 16:29:35 -0800
Subject: Update XPCOM hooks once more.
Commit: 86f0b862d5035fcc165dee1b38ed670854d6dafe
Returning is wrong. The error console errors are just how
the exception reporting works.. Hacked around it.
---
src/components/block-livemarks.js | 5 ++++-
src/components/certDialogsOverride.js | 5 ++++-
src/components/crash-observer.js | 7 ++++---
src/components/external-app-blocker.js | 28 +++++++++++++++++++---------
src/components/ignore-history.js | 21 ++++++++++-----------
5 files changed, 41 insertions(+), 25 deletions(-)
diff --git a/src/components/block-livemarks.js b/src/components/block-livemarks.js
index d9986dc..9666579 100644
--- a/src/components/block-livemarks.js
+++ b/src/components/block-livemarks.js
@@ -72,7 +72,10 @@ LivemarkWrapper.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+") return Components.results.NS_ERROR_XPC_NOT_ENOUGH_ARGS; try { return wrapped."+method+".apply(wrapped, arguments);} catch(e) { return e.result; }})";
+ 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);})";
newObj[method] = eval(fun);
} else {
newObj.__defineGetter__(method, function() { return wrapped[method]; });
diff --git a/src/components/certDialogsOverride.js b/src/components/certDialogsOverride.js
index a9e881c..e0b82d6 100644
--- a/src/components/certDialogsOverride.js
+++ b/src/components/certDialogsOverride.js
@@ -83,7 +83,10 @@ 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+") return Components.results.NS_ERROR_XPC_NOT_ENOUGH_ARGS; try { return wrapped."+method+".apply(wrapped, arguments);} catch(e) { return e.result; }})";
+ 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);})";
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 9301760..dd58800 100644
--- a/src/components/crash-observer.js
+++ b/src/components/crash-observer.js
@@ -89,9 +89,10 @@ 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+") 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;
+ 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);})";
newObj[method] = eval(fun);
} else {
newObj.__defineGetter__(method, function() { return wrapped[method]; });
diff --git a/src/components/external-app-blocker.js b/src/components/external-app-blocker.js
index 4b8e178..c423300 100644
--- a/src/components/external-app-blocker.js
+++ b/src/components/external-app-blocker.js
@@ -98,13 +98,7 @@ ExternalWrapper.prototype =
/* Copies methods from the true object we are wrapping */
copyMethods: function(wrapped) {
var mimic = function(newObj, method) {
- if(method == "XXXX") {
- // Hack to deal with unimplemented methods.
- // XXX: the API docs say to RETURN the not implemented error
- // for these functions as opposed to throw...
- var fun = "(function (){return Components.results.NS_ERROR_NOT_IMPLEMENTED; })";
- newObj[method] = eval(fun);
- } else if(typeof(wrapped[method]) == "function") {
+ if(typeof(wrapped[method]) == "function") {
// Code courtesy of timeless:
// http://www.webwizardry.net/~timeless/windowStubs.js
var params = [];
@@ -113,8 +107,24 @@ 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+") 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);
+ if(method == "getTypeFromFile" || method == "getTypeFromExtension") {
+ // XXX: Due to https://developer.mozilla.org/en/Exception_logging_in_JavaScript
+ // this is necessary to prevent error console noise on the return to C++ code.
+ // It is not technically correct, but as far as I can tell, returning null
+ // here should be equivalent to throwing an error for the codepaths invovled
+ var fun = "(function "+call+"{"+
+ "if (arguments.length < "+wrapped[method].length+")"+
+ " throw Components.results.NS_ERROR_XPC_NOT_ENOUGH_ARGS;"+
+ "try { return wrapped."+method+".apply(wrapped, arguments); }"+
+ "catch(e) { if(e.result == Components.results.NS_ERROR_NOT_AVAILABLE) return null; else throw e;} })";
+ newObj[method] = eval(fun);
+ } else {
+ 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);})";
+ newObj[method] = eval(fun);
+ }
} else {
newObj.__defineGetter__(method, function() { return wrapped[method]; });
newObj.__defineSetter__(method, function(val) { wrapped[method] = val; });
diff --git a/src/components/ignore-history.js b/src/components/ignore-history.js
index 046468a..4d9f4f6 100644
--- a/src/components/ignore-history.js
+++ b/src/components/ignore-history.js
@@ -162,25 +162,21 @@ HistoryWrapper.prototype =
},
- /*
+ /*
* Copies methods from the true history object we are wrapping
*/
copyMethods: function(wrapped) {
- // XXX: "Not all histories implement all methods"? wtf?? It's a
- // damned service. how are there more than one?
- // - http://developer.mozilla.org/en/docs/nsIGlobalHistory3
var mimic = function(newObj, method) {
if(method == "getURIGeckoFlags" || method == "setURIGeckoFlags"
|| method == "hidePage") {
- // Hack to deal with unimplemented methods.
- // XXX: the API docs say to RETURN the not implemented error
- // for these functions as opposed to throw.. Also,
- // what other "histories" actually DO implement these functions?
- // Did we just break them somehow?
+ // XXX: Due to https://developer.mozilla.org/en/Exception_logging_in_JavaScript
+ // this is necessary to prevent error console noise on the return to C++ code.
+ // It is not technically correct, but as far as I can tell, the return values
+ // for these calls are never checked anyway.
var fun = "(function (){return Components.results.NS_ERROR_NOT_IMPLEMENTED; })";
newObj[method] = eval(fun);
} else if(typeof(wrapped[method]) == "function") {
- // Code courtesy of timeless:
+ // Code courtesy of timeless:
// http://www.webwizardry.net/~timeless/windowStubs.js
var params = [];
params.length = wrapped[method].length;
@@ -188,7 +184,10 @@ 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+") return Components.results.NS_ERROR_XPC_NOT_ENOUGH_ARGS; try { return wrapped."+method+".apply(wrapped, arguments);} catch(e) { return e.result; }})";
+ 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);})";
newObj[method] = eval(fun);
} else {
newObj.__defineGetter__(method, function() { return wrapped[method]; });
--
1.5.6.5