Bug 495167. Make XPCOMUtils.generateQI deal with string interface names. r+sr=bsmedberg

This commit is contained in:
Boris Zbarsky 2009-06-15 16:06:20 -07:00
parent 8ba9ed33c5
commit eb5f032de5
2 changed files with 28 additions and 2 deletions

View File

@ -82,7 +82,9 @@
* // QueryInterface implementation, e.g. using the generateQI helper
* QueryInterface: XPCOMUtils.generateQI(
* [Components.interfaces.nsIObserver,
* Components.interfaces.nsIMyInterface]),
* Components.interfaces.nsIMyInterface,
* "nsIFoo",
* "nsIBar" ]),
*
* // ...component implementation...
* };
@ -112,7 +114,8 @@ var XPCOMUtils = {
* param, and if it is, returns |this| (the object it was called on).
*/
generateQI: function(interfaces) {
return makeQI([i.name for each (i in interfaces) if (i)]);
/* Note that Ci[Ci.x] == Ci.x for all x */
return makeQI([Ci[i].name for each (i in interfaces) if (Ci[i])]);
},
/**

View File

@ -0,0 +1,23 @@
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
var x = {
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIClassInfo,
"nsIDOMNode"])
};
function run_test() {
try {
x.QueryInterface(Components.interfaces.nsIClassInfo);
} catch(e) {
do_throw("Should QI to nsIClassInfo");
}
try {
x.QueryInterface(Components.interfaces.nsIDOMNode);
} catch(e) {
do_throw("Should QI to nsIDOMNode");
}
try {
x.QueryInterface(Components.interfaces.nsIDOMDocument);
do_throw("QI should not have succeeded!");
} catch(e) {}
}