⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nsinterfaceinfotoidl.js

📁 从国外的站点上淘的个人财务管理系统.开源.
💻 JS
📖 第 1 页 / 共 2 页
字号:
                bracketed = "[notxpcom] "            else if(m.isHidden)                bracketed = "[noscript] "            else                bracketed = "";            if(m.isGetter)            {                // Is an attribute                // figure out if this is readonly                m2 = i+1 < methodTotalCount ? info.getMethodInfo(i+1) : null;                readonly = !m2 || m2.name != m.name;                out.writeln("  " + bracketed + (readonly ? "readonly " : "") +                            "attribute " +                            formatTypeName(info, i, m.getParam(0), 0) +                            " " + m.name + ";\n");                if(!readonly)                    i++; // skip the next one, we have it covered.                continue;            }            // else...            paramCount = m.paramCount;            // 'last' param is used to figure out retvalTypeName            p = paramCount ? m.getParam(paramCount-1) : null;            if(m.isNotXPCOM)                retvalTypeName = formatTypeName(info, i, m.result, 0);            else if(p && "[retval] " == formatBracketForParam(info, i, p))            {                // Check for the exact string above because anything else                // indicates that there either is no expilict retval                // or there are additional braketed attributes (meaning that                // the retval must appear in the param list and not                // preceeding the method name).                retvalTypeName = formatTypeName(info, i, p, 0);                // no need to print it in the param list                paramCount-- ;            }            else                retvalTypeName = "void";            // print method name            out.writeln("  " + bracketed + retvalTypeName + " " + m.name +                        "(" + (paramCount ? "" : ");"));            // print params            for(k = 0; k < paramCount; k++)            {                p = m.getParam(k);                out.writeln("              "+                            formatBracketForParam(info, i, p) +                            (p.isOut ? p.isIn ? "inout " : "out " : "in ") +                            formatTypeName(info, i, p, 0) + " " +                            PARAM_NAME_PREFIX+k +                            (k+1 == paramCount ? ");\n" : ", "));            }        }    }    out.writeln("};\n");    // comment out nsISupports//    if(iid.equals(nsISupports))//        out.writeln("\n*/\n");}function appendForwardDeclarations(list, info){    list.push(info.name);    if(info.parent)        appendForwardDeclarations(list, info.parent);    var i, k, m, p;    for(i = 0; i < info.methodCount; i++)    {        m = info.getMethodInfo(i);        for(k = 0; k < m.paramCount; k++)        {            p = m.getParam(k);            if(p.type.dataType == nsIDataType.VTYPE_INTERFACE)            {                var name;                try {                    name = info.getInfoForParam(i, p).name;                } catch(e)  {                    name = MISSING_INTERFACE;                }                list.push(name);            }        }    }}function doForwardDeclarations(out, iid){    var i, cur, prev;    var list = [];    appendForwardDeclarations(list, new IInfo(iid));    list.sort();    out.writeln("// forward declarations...");    for(i = 0; i < list.length; i++)    {        cur = list[i];        if(cur != prev && cur != "nsISupports")        {            if(cur == MISSING_INTERFACE)                out.writeln("/*\n * !!! Unable to find details for a declared "+                            "interface (name unknown)!!!\n */");            else                out.writeln("interface " + cur +";");            prev = cur;        }    }}function buildForwardDeclarationsList(iid){    var i, cur, prev;    var list = [];    var outList = [];    appendForwardDeclarations(list, new IInfo(iid));    list.sort();    for(i = 0; i < list.length; i++)    {        cur = list[i];        if(cur != prev && cur != "nsISupports")        {            if(cur != MISSING_INTERFACE)                outList.push(cur);            prev = cur;        }    }    return outList;}/*********************************************************//* Our Componenent ctor */function nsInterfaceInfoToIDL() {}/* decorate prototype to provide ``class'' methods and property accessors */nsInterfaceInfoToIDL.prototype ={    // nsIInterfaceInfoToIDL methods...    // string generateIDL(in nsIIDRef aIID,    //                    in PRBool withIncludes,    //                    in PRBool withForwardDeclarations);    generateIDL : function(aIID, withIncludes, withForwardDeclarations) {        var out = new Buffer;        out.writeln();        if(withIncludes)        {            out.writeln('#include "nsISupports.idl"');            out.writeln();        }        if(withForwardDeclarations)        {            doForwardDeclarations(out, aIID);            out.writeln("");        }        doInterface(out, aIID);        return out.buffer;    },    // void getReferencedInterfaceNames(in nsIIDRef aIID,    //                                  out PRUint32 aArrayLength,    //                                  [retval, array, size_is(aArrayLength)]    //                                  out string aNames);    getReferencedInterfaceNames : function(aIID, aArrayLength) {        var list = buildForwardDeclarationsList(aIID);        aArrayLength.value = list.length;        return list;    },    // nsISupports methods...    QueryInterface: function (iid) {        if (iid.equals(Components.interfaces.nsIInterfaceInfoToIDL) ||            iid.equals(Components.interfaces.nsISupports))            return this;        Components.returnCode = Components.results.NS_ERROR_NO_INTERFACE;        return null;    }}/***************************************************************************//***************************************************************************/// parts specific to my use of the the generic module code...const MODULE_NAME        = "nsInterfaceInfoToIDL";const MODULE_CONTRACT_ID = "@mozilla.org/interfaceinfotoidl;1";const MODULE_CID         = "{47d98974-a1b7-46a6-bc99-8abc374bba3f}";const MODULE_CTOR        = nsInterfaceInfoToIDL;/***************************************************************************//***************************************************************************/// generic nsIModule part...function NSGetModule(compMgr, fileSpec) {    return new GenericModule(MODULE_NAME, MODULE_CONTRACT_ID,                             MODULE_CID, MODULE_CTOR);}function GenericModule (name, contractID, CID, ctor) {    this.name       = name;    this.contractID = contractID;    this.CID        = Components.ID(CID);    this.ctor       = ctor;}GenericModule.prototype = {    /*     * RegisterSelf is called at registration time (component installation     * or the only-until-release startup autoregistration) and is responsible     * for notifying the component manager of all components implemented in     * this module.  The fileSpec, location and type parameters are mostly     * opaque, and should be passed on to the registerComponent call     * unmolested.     */    registerSelf: function (compMgr, fileSpec, location, type) {        compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);        compMgr.registerFactoryLocation(this.CID, this.name, this.contractID,                                        fileSpec, location, type);    },    /*     * The GetClassObject method is responsible for producing Factory and     * SingletonFactory objects (the latter are specialized for services).     */    getClassObject: function (compMgr, cid, iid) {        if (!cid.equals(this.CID))            throw Components.results.NS_ERROR_NO_INTERFACE;        if (!iid.equals(Components.interfaces.nsIFactory))            throw Components.results.NS_ERROR_NOT_IMPLEMENTED;        this.myFactory.ctor = this.ctor;        return this.myFactory;    },    /* factory object */    myFactory: {        /*         * 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) {            if (outer != null)                throw Components.results.NS_ERROR_NO_AGGREGATION;            return (new this.ctor()).QueryInterface(iid);        }    },    /*     * 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_     * call it.     */    canUnload: function(compMgr) {        return true;    }}/***************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -