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.

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

mercurial