no bug - Import translations from android-l10n r=release a=l10n CLOSED TREE
[gecko.git] / js / xpconnect / tests / components / native / xpctest_module.cpp
blob11200240b1966608541e8c1e1f304a426e760b15
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* module registration and factory code. */
9 #include "mozilla/GenericFactory.h"
10 #include "mozilla/ResultExtensions.h"
11 #include "mozilla/Try.h"
12 #include "nsComponentManager.h"
13 #include "xpctest_private.h"
15 template <typename T>
16 nsresult RegisterFactory(const char* aContractID) {
17 auto constructor = [](REFNSIID aIID, void** aResult) {
18 RefPtr inst = new T();
19 return inst->QueryInterface(aIID, aResult);
22 nsCOMPtr<nsIFactory> factory = new mozilla::GenericFactory(constructor);
24 nsID cid;
25 MOZ_TRY(nsID::GenerateUUIDInPlace(cid));
27 return nsComponentManagerImpl::gComponentManager->RegisterFactory(
28 cid, aContractID, aContractID, factory);
31 nsresult xpcTestRegisterComponents() {
32 MOZ_TRY(RegisterFactory<xpcTestObjectReadOnly>(
33 "@mozilla.org/js/xpc/test/native/ObjectReadOnly;1"));
34 MOZ_TRY(RegisterFactory<xpcTestObjectReadWrite>(
35 "@mozilla.org/js/xpc/test/native/ObjectReadWrite;1"));
36 MOZ_TRY(RegisterFactory<nsXPCTestParams>(
37 "@mozilla.org/js/xpc/test/native/Params;1"));
38 MOZ_TRY(RegisterFactory<nsXPCTestESMReturnCodeParent>(
39 "@mozilla.org/js/xpc/test/native/ESMReturnCodeParent;1"));
40 MOZ_TRY(RegisterFactory<xpcTestCEnums>(
41 "@mozilla.org/js/xpc/test/native/CEnums;1"));
43 return NS_OK;