Bug 1867190 - Add prefs for PHC probablities r=glandium
[gecko.git] / js / public / WeakMapPtr.h
blobf3fd5135d8b4f5c3b5f4b9c9d311572de2642ce4
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
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 #ifndef js_WeakMapPtr_h
8 #define js_WeakMapPtr_h
10 #include "jstypes.h"
12 #include "js/TypeDecls.h"
14 class JS_PUBLIC_API JSTracer;
16 namespace JS {
18 // A wrapper around the internal C++ representation of SpiderMonkey WeakMaps,
19 // usable outside the engine.
21 // The supported template specializations are enumerated in gc/WeakMapPtr.cpp.
22 // If you want to use this class for a different key/value combination, add it
23 // to the list and the compiler will generate the relevant machinery.
24 template <typename K, typename V>
25 class JS_PUBLIC_API WeakMapPtr {
26 public:
27 WeakMapPtr() : ptr(nullptr) {}
28 bool init(JSContext* cx);
29 bool initialized() { return ptr != nullptr; }
30 void destroy();
31 virtual ~WeakMapPtr() { MOZ_ASSERT(!initialized()); }
32 void trace(JSTracer* trc);
34 V lookup(const K& key);
35 bool put(JSContext* cx, const K& key, const V& value);
36 V removeValue(const K& key);
38 private:
39 void* ptr;
41 // WeakMapPtr is neither copyable nor assignable.
42 WeakMapPtr(const WeakMapPtr& wmp) = delete;
43 WeakMapPtr& operator=(const WeakMapPtr& wmp) = delete;
46 } /* namespace JS */
48 #endif /* js_WeakMapPtr_h */