xpcom/sample/nsSample.js

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
     9 /**
    10  * We set up a sample component. The constructor is empty, all the interesting
    11  * stuff goes in the prototype.
    12  */
    13 function mySample() { }
    15 mySample.prototype = {
    16     /**
    17      * .classID is required for generateNSGetFactory to work correctly.
    18      * Make sure this CID matches the "component" in your .manifest file.
    19      */
    20     classID: Components.ID("{dea98e50-1dd1-11b2-9344-8902b4805a2e}"),
    22     /**
    23      * .classDescription and .contractID are only used for
    24      * backwards compatibility with Gecko 1.9.2 and
    25      * XPCOMUtils.generateNSGetModule.
    26      */
    27     classDescription: "nsSample: JS version", // any human-readable string
    28     contractID: "@mozilla.org/jssample;1",
    30     /**
    31      * List all the interfaces your component supports.
    32      * @note nsISupports is generated automatically; you don't need to list it.
    33      */
    34     QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsISample]),
    36     /*
    37      * get and set are new Magic in JS1.5, borrowing the intent -- if not
    38      * the exact syntax -- from the JS2 design.  They define accessors for
    39      * properties on the JS object, follow the expected rules for prototype
    40      * delegation, and make a mean cup of coffee.
    41      */
    42     get value()       { return this.val; },
    43     set value(newval) { return this.val = newval; },
    45     writeValue: function (aPrefix) {
    46         debug("mySample::writeValue => " + aPrefix + this.val + "\n");
    47     },
    48     poke: function (aValue) { this.val = aValue; },
    50     val: "<default value>"
    51 };
    53 /**
    54  * XPCOMUtils.generateNSGetFactory was introduced in Mozilla 2 (Firefox 4).
    55  * XPCOMUtils.generateNSGetModule is for Mozilla 1.9.2 (Firefox 3.6).
    56  */
    57 if (XPCOMUtils.generateNSGetFactory)
    58     this.NSGetFactory = XPCOMUtils.generateNSGetFactory([mySample]);
    59 else
    60     var NSGetModule = XPCOMUtils.generateNSGetModule([mySample]);

mercurial