2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2018-11-30 18:39:55 +03:00
|
|
|
* vim: set ts=8 sts=2 et sw=2 tw=80:
|
2014-02-21 23:35:48 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef js_WeakMapPtr_h
|
|
|
|
#define js_WeakMapPtr_h
|
|
|
|
|
|
|
|
#include "jspubtd.h"
|
|
|
|
|
|
|
|
#include "js/TypeDecls.h"
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
// A wrapper around the internal C++ representation of SpiderMonkey WeakMaps,
|
|
|
|
// usable outside the engine.
|
|
|
|
//
|
2018-02-15 01:00:46 +03:00
|
|
|
// The supported template specializations are enumerated in gc/WeakMapPtr.cpp.
|
|
|
|
// If you want to use this class for a different key/value combination, add it
|
|
|
|
// to the list and the compiler will generate the relevant machinery.
|
2014-02-21 23:35:48 +04:00
|
|
|
template <typename K, typename V>
|
2018-11-19 20:02:47 +03:00
|
|
|
class JS_PUBLIC_API WeakMapPtr {
|
2014-02-21 23:35:48 +04:00
|
|
|
public:
|
2014-08-18 23:20:39 +04:00
|
|
|
WeakMapPtr() : ptr(nullptr) {}
|
2015-03-29 01:22:11 +03:00
|
|
|
bool init(JSContext* cx);
|
2014-08-18 23:20:39 +04:00
|
|
|
bool initialized() { return ptr != nullptr; }
|
2014-02-21 23:35:48 +04:00
|
|
|
void destroy();
|
|
|
|
virtual ~WeakMapPtr() { MOZ_ASSERT(!initialized()); }
|
2015-03-29 01:22:11 +03:00
|
|
|
void trace(JSTracer* tracer);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
V lookup(const K& key);
|
|
|
|
bool put(JSContext* cx, const K& key, const V& value);
|
2017-10-10 18:42:18 +03:00
|
|
|
V removeValue(const K& key);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-02-21 23:35:48 +04:00
|
|
|
private:
|
2015-03-29 01:22:11 +03:00
|
|
|
void* ptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-02-21 23:35:48 +04:00
|
|
|
// WeakMapPtr is neither copyable nor assignable.
|
2015-03-29 01:22:11 +03:00
|
|
|
WeakMapPtr(const WeakMapPtr& wmp) = delete;
|
|
|
|
WeakMapPtr& operator=(const WeakMapPtr& wmp) = delete;
|
2014-02-21 23:35:48 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace JS */
|
|
|
|
|
|
|
|
#endif /* js_WeakMapPtr_h */
|