tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

WeakMapObject.h (3044B)


      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  using Map = WeakMap<Value, Value, ZoneAllocPolicy>;
     21  Map* getMap() { return maybePtrFromReservedSlot<Map>(DataSlot); }
     22 
     23  size_t sizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf);
     24 
     25  size_t nondeterministicGetSize();
     26  [[nodiscard]] static bool nondeterministicGetKeys(
     27      JSContext* cx, Handle<WeakCollectionObject*> obj,
     28      MutableHandleObject ret);
     29 
     30 protected:
     31  static const JSClassOps classOps_;
     32 
     33  static void trace(JSTracer* trc, JSObject* obj);
     34  static void finalize(JS::GCContext* gcx, JSObject* obj);
     35 };
     36 
     37 class WeakMapObject : public WeakCollectionObject {
     38 public:
     39  static const JSClass class_;
     40  static const JSClass protoClass_;
     41 
     42  [[nodiscard]] static bool has(JSContext* cx, unsigned argc, Value* vp);
     43  [[nodiscard]] static bool get(JSContext* cx, unsigned argc, Value* vp);
     44  [[nodiscard]] static bool set(JSContext* cx, unsigned argc, Value* vp);
     45 
     46  static void getObject(WeakMapObject* weakMap, JSObject* obj, Value* result);
     47  static bool hasObject(WeakMapObject* weakMap, JSObject* obj);
     48 
     49 private:
     50  static const ClassSpec classSpec_;
     51 
     52  static const JSPropertySpec properties[];
     53  static const JSFunctionSpec methods[];
     54 
     55  [[nodiscard]] static bool construct(JSContext* cx, unsigned argc, Value* vp);
     56 
     57  [[nodiscard]] static bool tryOptimizeCtorWithIterable(
     58      JSContext* cx, Handle<WeakMapObject*> obj, Handle<Value> iterableVal,
     59      bool* optimized);
     60 
     61  [[nodiscard]] static MOZ_ALWAYS_INLINE bool is(HandleValue v);
     62 
     63  [[nodiscard]] static MOZ_ALWAYS_INLINE bool has_impl(JSContext* cx,
     64                                                       const CallArgs& args);
     65  [[nodiscard]] static MOZ_ALWAYS_INLINE bool get_impl(JSContext* cx,
     66                                                       const CallArgs& args);
     67  [[nodiscard]] static MOZ_ALWAYS_INLINE bool delete_impl(JSContext* cx,
     68                                                          const CallArgs& args);
     69  [[nodiscard]] static bool delete_(JSContext* cx, unsigned argc, Value* vp);
     70  [[nodiscard]] static MOZ_ALWAYS_INLINE bool set_impl(JSContext* cx,
     71                                                       const CallArgs& args);
     72  [[nodiscard]] static MOZ_ALWAYS_INLINE bool getOrInsert_impl(
     73      JSContext* cx, const CallArgs& args);
     74  [[nodiscard]] static bool getOrInsert(JSContext* cx, unsigned argc,
     75                                        Value* vp);
     76 };
     77 
     78 }  // namespace js
     79 
     80 #endif /* builtin_WeakMapObject_h */