michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * vim: set ts=8 sts=4 et sw=4 tw=99: 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: #ifndef js_WeakMapPtr_h michael@0: #define js_WeakMapPtr_h michael@0: michael@0: #include "jspubtd.h" michael@0: michael@0: #include "js/TypeDecls.h" michael@0: michael@0: namespace JS { michael@0: michael@0: // A wrapper around the internal C++ representation of SpiderMonkey WeakMaps, michael@0: // usable outside the engine. michael@0: // michael@0: // The supported template specializations are enumerated in WeakMapPtr.cpp. If michael@0: // you want to use this class for a different key/value combination, add it to michael@0: // the list and the compiler will generate the relevant machinery. michael@0: template michael@0: class JS_PUBLIC_API(WeakMapPtr) michael@0: { michael@0: public: michael@0: WeakMapPtr() : ptr(nullptr) {}; michael@0: bool init(JSContext *cx); michael@0: bool initialized() { return ptr != nullptr; }; michael@0: void destroy(); michael@0: virtual ~WeakMapPtr() { MOZ_ASSERT(!initialized()); } michael@0: void trace(JSTracer *tracer); michael@0: michael@0: V lookup(const K &key); michael@0: bool put(JSContext *cx, const K &key, const V &value); michael@0: michael@0: static void keyMarkCallback(JSTracer *trc, K key, void *data); michael@0: michael@0: private: michael@0: void *ptr; michael@0: michael@0: // WeakMapPtr is neither copyable nor assignable. michael@0: WeakMapPtr(const WeakMapPtr &wmp) MOZ_DELETE; michael@0: WeakMapPtr &operator=(const WeakMapPtr &wmp) MOZ_DELETE; michael@0: }; michael@0: michael@0: } /* namespace JS */ michael@0: michael@0: #endif /* js_WeakMapPtr_h */