| 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/. */ |
| 6 |
|
| 7 |
#ifndef builtin_WeakMapObject_h |
| 8 |
#define builtin_WeakMapObject_h |
| 9 |
|
| 10 |
#include "gc/WeakMap.h" |
| 11 |
#include "vm/NativeObject.h" |
| 12 |
|
| 13 |
namespace js { |
| 14 |
|
| 15 |
// Abstract base class for WeakMapObject and WeakSetObject. |
| 16 |
class WeakCollectionObject : public NativeObject { |
| 17 |
public: |
| 18 |
enum { DataSlot, SlotCount }; |
| 19 |
|
| 20 |
ValueValueWeakMap* getMap() { |
| 21 |
return maybePtrFromReservedSlot<ValueValueWeakMap>(DataSlot); |
| 22 |
} |
| 23 |
|
| 24 |
size_t sizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf); |
| 25 |
|
| 26 |
[[nodiscard]] static bool nondeterministicGetKeys( |
| 27 |
JSContext* cx, Handle<WeakCollectionObject*> obj, |
| 28 |
MutableHandleObject ret); |
| 29 |
|
| 30 |
protected: |
| 31 |
static const JSClassOps classOps_; |
| 32 |
}; |
| 33 |
|
| 34 |
class WeakMapObject : public WeakCollectionObject { |
| 35 |
public: |
| 36 |
static const JSClass class_; |
| 37 |
static const JSClass protoClass_; |
| 38 |
|
| 39 |
[[nodiscard]] static bool has(JSContext* cx, unsigned argc, Value* vp); |
| 40 |
[[nodiscard]] static bool get(JSContext* cx, unsigned argc, Value* vp); |
| 41 |
[[nodiscard]] static bool set(JSContext* cx, unsigned argc, Value* vp); |
| 42 |
|
| 43 |
private: |
| 44 |
static const ClassSpec classSpec_; |
| 45 |
|
| 46 |
static const JSPropertySpec properties[]; |
| 47 |
static const JSFunctionSpec methods[]; |
| 48 |
|
| 49 |
[[nodiscard]] static bool construct(JSContext* cx, unsigned argc, Value* vp); |
| 50 |
|
| 51 |
[[nodiscard]] static bool tryOptimizeCtorWithIterable( |
| 52 |
JSContext* cx, Handle<WeakMapObject*> obj, Handle<Value> iterableVal, |
| 53 |
bool* optimized); |
| 54 |
|
| 55 |
[[nodiscard]] static MOZ_ALWAYS_INLINE bool is(HandleValue v); |
| 56 |
|
| 57 |
[[nodiscard]] static MOZ_ALWAYS_INLINE bool has_impl(JSContext* cx, |
| 58 |
const CallArgs& args); |
| 59 |
[[nodiscard]] static MOZ_ALWAYS_INLINE bool get_impl(JSContext* cx, |
| 60 |
const CallArgs& args); |
| 61 |
[[nodiscard]] static MOZ_ALWAYS_INLINE bool delete_impl(JSContext* cx, |
| 62 |
const CallArgs& args); |
| 63 |
[[nodiscard]] static bool delete_(JSContext* cx, unsigned argc, Value* vp); |
| 64 |
[[nodiscard]] static MOZ_ALWAYS_INLINE bool set_impl(JSContext* cx, |
| 65 |
const CallArgs& args); |
| 66 |
#ifdef NIGHTLY_BUILD |
| 67 |
[[nodiscard]] static MOZ_ALWAYS_INLINE bool getOrInsert_impl( |
| 68 |
JSContext* cx, const CallArgs& args); |
| 69 |
[[nodiscard]] static bool getOrInsert(JSContext* cx, unsigned argc, |
| 70 |
Value* vp); |
| 71 |
#endif // #ifdef NIGHTLY_BUILD |
| 72 |
}; |
| 73 |
|
| 74 |
} // namespace js |
| 75 |
|
| 76 |
#endif /* builtin_WeakMapObject_h */ |