1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #ifndef ModuleMapKey_h__ 6 #define ModuleMapKey_h__ 7 8 #include "nsURIHashKey.h" 9 #include "nsIGlobalObject.h" 10 11 namespace mozilla::dom { 12 13 class ModuleMapKey : public nsURIHashKey { 14 public: 15 using KeyType = ModuleMapKey&; 16 using KeyTypePointer = const ModuleMapKey*; 17 18 ModuleMapKey() = default; 19 ModuleMapKey(const nsIURI* aURI, nsIGlobalObject* aWebExtGlobal); 20 explicit ModuleMapKey(const ModuleMapKey* aKey); 21 ModuleMapKey(ModuleMapKey&& aToMove) noexcept; 22 23 ModuleMapKey& operator=(const ModuleMapKey& aOther) = default; 24 GetKey()25 KeyType GetKey() { return *this; } GetKeyPointer()26 KeyTypePointer GetKeyPointer() const { return this; } KeyToPointer(KeyType aKey)27 static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; } 28 29 bool KeyEquals(KeyTypePointer aOther) const; 30 static PLDHashNumber HashKey(KeyTypePointer aKey); 31 32 nsCOMPtr<nsIGlobalObject> mWebExtGlobal; 33 }; 34 ImplCycleCollectionUnlink(ModuleMapKey & aField)35inline void ImplCycleCollectionUnlink(ModuleMapKey& aField) { 36 ImplCycleCollectionUnlink(aField.mWebExtGlobal); 37 } 38 39 inline void ImplCycleCollectionTraverse( 40 nsCycleCollectionTraversalCallback& aCallback, ModuleMapKey& aField, 41 const char* aName, uint32_t aFlags = 0) { 42 ImplCycleCollectionTraverse(aCallback, aField.mWebExtGlobal, aName, aFlags); 43 } 44 45 } // namespace mozilla::dom 46 47 #endif 48