tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

xpctest_module.cpp (1507B)


      1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
      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/. */
      6 
      7 /* module registration and factory code. */
      8 
      9 #include "mozilla/GenericFactory.h"
     10 #include "mozilla/Try.h"
     11 #include "nsComponentManager.h"
     12 #include "xpctest_private.h"
     13 
     14 template <typename T>
     15 nsresult RegisterFactory(const char* aContractID) {
     16  auto constructor = [](REFNSIID aIID, void** aResult) {
     17    RefPtr inst = new T();
     18    return inst->QueryInterface(aIID, aResult);
     19  };
     20 
     21  nsCOMPtr<nsIFactory> factory = new mozilla::GenericFactory(constructor);
     22 
     23  nsID cid;
     24  MOZ_TRY(nsID::GenerateUUIDInPlace(cid));
     25 
     26  return nsComponentManagerImpl::gComponentManager->RegisterFactory(
     27      cid, aContractID, aContractID, factory);
     28 }
     29 
     30 nsresult xpcTestRegisterComponents() {
     31  MOZ_TRY(RegisterFactory<xpcTestObjectReadOnly>(
     32      "@mozilla.org/js/xpc/test/native/ObjectReadOnly;1"));
     33  MOZ_TRY(RegisterFactory<xpcTestObjectReadWrite>(
     34      "@mozilla.org/js/xpc/test/native/ObjectReadWrite;1"));
     35  MOZ_TRY(RegisterFactory<nsXPCTestParams>(
     36      "@mozilla.org/js/xpc/test/native/Params;1"));
     37  MOZ_TRY(RegisterFactory<nsXPCTestESMReturnCodeParent>(
     38      "@mozilla.org/js/xpc/test/native/ESMReturnCodeParent;1"));
     39  MOZ_TRY(RegisterFactory<xpcTestCEnums>(
     40      "@mozilla.org/js/xpc/test/native/CEnums;1"));
     41 
     42  return NS_OK;
     43 }