michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: michael@0: function FooComponent() { michael@0: this.wrappedJSObject = this; michael@0: } michael@0: FooComponent.prototype = michael@0: { michael@0: // nsIClassInfo + information for XPCOM registration code in XPCOMUtils.jsm michael@0: classDescription: "Foo Component", michael@0: classID: Components.ID("{6b933fe6-6eba-4622-ac86-e4f654f1b474}"), michael@0: contractID: "@mozilla.org/tests/module-importer;1", michael@0: michael@0: // nsIClassInfo michael@0: implementationLanguage: Components.interfaces.nsIProgrammingLanguage.JAVASCRIPT, michael@0: flags: 0, michael@0: michael@0: getInterfaces: function getInterfaces(aCount) { michael@0: var interfaces = [Components.interfaces.nsIClassInfo]; michael@0: aCount.value = interfaces.length; michael@0: michael@0: // Guerilla test for line numbers hiding in this method michael@0: var threw = true; michael@0: try { michael@0: thereIsNoSuchIdentifier; michael@0: threw = false; michael@0: } catch (ex) { michael@0: do_check_true(ex.lineNumber == 28); michael@0: } michael@0: do_check_true(threw); michael@0: michael@0: return interfaces; michael@0: }, michael@0: michael@0: getHelperForLanguage: function getHelperForLanguage(aLanguage) { michael@0: return null; michael@0: }, michael@0: michael@0: // nsISupports michael@0: QueryInterface: function QueryInterface(aIID) { michael@0: if (aIID.equals(Components.interfaces.nsIClassInfo) || michael@0: aIID.equals(Components.interfaces.nsISupports)) michael@0: return this; michael@0: michael@0: throw Components.results.NS_ERROR_NO_INTERFACE; michael@0: } michael@0: }; michael@0: michael@0: function BarComponent() { michael@0: } michael@0: BarComponent.prototype = michael@0: { michael@0: // nsIClassInfo + information for XPCOM registration code in XPCOMUtils.jsm michael@0: classDescription: "Module importer test 2", michael@0: classID: Components.ID("{708a896a-b48d-4bff-906e-fc2fd134b296}"), michael@0: contractID: "@mozilla.org/tests/module-importer;2", michael@0: michael@0: // nsIClassInfo michael@0: implementationLanguage: Components.interfaces.nsIProgrammingLanguage.JAVASCRIPT, michael@0: flags: 0, michael@0: michael@0: getInterfaces: function getInterfaces(aCount) { michael@0: var interfaces = [Components.interfaces.nsIClassInfo]; michael@0: aCount.value = interfaces.length; michael@0: return interfaces; michael@0: }, michael@0: michael@0: getHelperForLanguage: function getHelperForLanguage(aLanguage) { michael@0: return null; michael@0: }, michael@0: michael@0: // nsISupports michael@0: QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIClassInfo]) michael@0: }; michael@0: michael@0: function do_check_true(cond, text) { michael@0: // we don't have the test harness' utilities in this scope, so we need this michael@0: // little helper. In the failure case, the exception is propagated to the michael@0: // caller in the main run_test() function, and the test fails. michael@0: if (!cond) michael@0: throw "Failed check: " + text; michael@0: } michael@0: michael@0: var gComponentsArray = [FooComponent, BarComponent]; michael@0: this.NSGetFactory = XPCOMUtils.generateNSGetFactory(gComponentsArray);