WeakRefObject.h (1385B)
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_WeakRefObject_h 8 #define builtin_WeakRefObject_h 9 10 #include "gc/FinalizationObservers.h" 11 #include "vm/NativeObject.h" 12 13 namespace js { 14 15 class WeakRefObject : public gc::ObserverListObject { 16 public: 17 enum { TargetSlot = ObserverListObject::SlotCount, SlotCount }; 18 19 static const JSClass class_; 20 static const JSClass protoClass_; 21 22 Value target(); 23 24 void setTargetUnbarriered(Value target); 25 void clearTargetAndUnlink(); 26 27 private: 28 static const JSClassOps classOps_; 29 static const ClassSpec classSpec_; 30 static const JSPropertySpec properties[]; 31 static const JSFunctionSpec methods[]; 32 33 [[nodiscard]] static bool construct(JSContext* cx, unsigned argc, Value* vp); 34 static void trace(JSTracer* trc, JSObject* obj); 35 static void finalize(JS::GCContext* gcx, JSObject* obj); 36 37 static bool preserveDOMWrapper(JSContext* cx, HandleObject obj); 38 39 static bool deref(JSContext* cx, unsigned argc, Value* vp); 40 static void readBarrier(JSContext* cx, Handle<WeakRefObject*> self); 41 }; 42 43 } // namespace js 44 45 #endif /* builtin_WeakRefObject_h */