1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/sample/nsSample.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,60 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 + 1.10 +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); 1.11 + 1.12 +/** 1.13 + * We set up a sample component. The constructor is empty, all the interesting 1.14 + * stuff goes in the prototype. 1.15 + */ 1.16 +function mySample() { } 1.17 + 1.18 +mySample.prototype = { 1.19 + /** 1.20 + * .classID is required for generateNSGetFactory to work correctly. 1.21 + * Make sure this CID matches the "component" in your .manifest file. 1.22 + */ 1.23 + classID: Components.ID("{dea98e50-1dd1-11b2-9344-8902b4805a2e}"), 1.24 + 1.25 + /** 1.26 + * .classDescription and .contractID are only used for 1.27 + * backwards compatibility with Gecko 1.9.2 and 1.28 + * XPCOMUtils.generateNSGetModule. 1.29 + */ 1.30 + classDescription: "nsSample: JS version", // any human-readable string 1.31 + contractID: "@mozilla.org/jssample;1", 1.32 + 1.33 + /** 1.34 + * List all the interfaces your component supports. 1.35 + * @note nsISupports is generated automatically; you don't need to list it. 1.36 + */ 1.37 + QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsISample]), 1.38 + 1.39 + /* 1.40 + * get and set are new Magic in JS1.5, borrowing the intent -- if not 1.41 + * the exact syntax -- from the JS2 design. They define accessors for 1.42 + * properties on the JS object, follow the expected rules for prototype 1.43 + * delegation, and make a mean cup of coffee. 1.44 + */ 1.45 + get value() { return this.val; }, 1.46 + set value(newval) { return this.val = newval; }, 1.47 + 1.48 + writeValue: function (aPrefix) { 1.49 + debug("mySample::writeValue => " + aPrefix + this.val + "\n"); 1.50 + }, 1.51 + poke: function (aValue) { this.val = aValue; }, 1.52 + 1.53 + val: "<default value>" 1.54 +}; 1.55 + 1.56 +/** 1.57 + * XPCOMUtils.generateNSGetFactory was introduced in Mozilla 2 (Firefox 4). 1.58 + * XPCOMUtils.generateNSGetModule is for Mozilla 1.9.2 (Firefox 3.6). 1.59 + */ 1.60 +if (XPCOMUtils.generateNSGetFactory) 1.61 + this.NSGetFactory = XPCOMUtils.generateNSGetFactory([mySample]); 1.62 +else 1.63 + var NSGetModule = XPCOMUtils.generateNSGetModule([mySample]);