Define QI now that XPConnect wraps JS objects; fix comments (NOT PART OF BUILD).

This commit is contained in:
brendan%mozilla.org 2000-09-18 02:31:11 +00:00
parent a53ac69e4e
commit 0352ff10a7

View File

@ -18,8 +18,8 @@ function mySample() { /* big comment for no code, eh? */ }
/* decorate prototype to provide ``class'' methods and property accessors */
mySample.prototype = {
/*
* getter: and setter: are new Magic in JS1.5, borrowing intent -- if not
* complete syntax -- from the JS2 design. They define accessors for
* get and set are new Magic in JS1.5, borrowing the intent -- if not
* the exact syntax -- from the JS2 design. They define accessors for
* properties on the JS object, follow the expected rules for prototype
* delegation, and make a mean cup of coffee.
*/
@ -32,14 +32,18 @@ mySample.prototype = {
poke: function (aValue) { this.val = aValue; },
/*
* We don't need a QueryInterface method unless we're doing
* something fancy like supporting multiple interfaces (not
* counting nsISupports, of course), or aggregating with an outer.
*
* If you _are_ providing a QueryInterface method, note that until
* bug 14460 is resolved you need to name it QueryInterface, not
* queryInterface as you might believe.
* Note that until bug 14460 is resolved, you need to name the method
* QueryInterface, not queryInterface as you might expect given the
* interCaps naming convention used in most XPIDL.
*/
QueryInterface: function (iid) {
if (!iid.equals(Components.interfaces.nsISample) &&
!iid.equals(Components.interfaces.nsISupports)) {
throw Components.results.NS_ERROR_NO_INTERFACE;
}
return this;
},
val: "<default value>"
}
@ -63,8 +67,8 @@ var myModule = {
dump("*** Registering sample JS components\n");
compMgr.registerComponentWithType(this.myCID,
"Sample JS Component",
"@mozilla.org/jssample;1", fileSpec,
location, true, true,
this.myProgID, fileSpec,
location, true, true,
type);
},
@ -85,41 +89,32 @@ var myModule = {
/* CID for this class */
myCID: Components.ID("{dea98e50-1dd1-11b2-9344-8902b4805a2e}"),
/* ProgID for this class */
myProgID: "@mozilla.org/jssample;1",
/* factory object */
myFactory: {
/*
* Construct an instance of the interface specified by iid,
* possibly aggregating with the provided |outer|. (If you don't
* know what aggregation is all about, you don't need to. It reduces
* even the mightiest of XPCOM warriors to snivelling cowards.)
* Construct an instance of the interface specified by iid, possibly
* aggregating it with the provided outer. (If you don't know what
* aggregation is all about, you don't need to. It reduces even the
* mightiest of XPCOM warriors to snivelling cowards.)
*/
createInstance: function (outer, iid) {
dump("CI: " + iid + "\n");
if (outer != null)
throw Components.results.NS_ERROR_NO_AGGREGATION;
/*
* If we had a QueryInterface method (see above), we would write
* the following as:
* return (new mySample()).QueryInterface(iid);
* because our QI would check the IID correctly for us.
*/
if (!iid.equals(Components.interfaces.nsISample) &&
!iid.equals(Components.interfaces.nsISupports)) {
throw Components.results.NS_ERROR_INVALID_ARG;
}
return new mySample();
return (new mySample()).QueryInterface(iid);
}
},
/*
* canUnload is used to signal that the component is about to be unloaded.
* C++ components can return false to indicate that they don't wish to
* be unloaded, but the return value from JS components' canUnload is
* ignored: mark-and-sweep will keep everything around until it's no
* longer in use, making unconditional ``unload'' safe.
* The canUnload method signals that the component is about to be unloaded.
* C++ components can return false to indicate that they don't wish to be
* unloaded, but the return value from JS components' canUnload is ignored:
* mark-and-sweep will keep everything around until it's no longer in use,
* making unconditional ``unload'' safe.
*
* You still need to provide a (likely useless) canUnload method, though:
* it's part of the nsIModule interface contract, and the JS loader _will_
@ -130,7 +125,7 @@ var myModule = {
return true;
}
};
function NSGetModule(compMgr, fileSpec) {
return myModule;
}