WeakRef.h 882 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibJS/Runtime/GlobalObject.h>
  8. #include <LibJS/Runtime/Object.h>
  9. #include <LibJS/Runtime/WeakContainer.h>
  10. namespace JS {
  11. class WeakRef final
  12. : public Object
  13. , public WeakContainer {
  14. JS_OBJECT(WeakRef, Object);
  15. public:
  16. static WeakRef* create(GlobalObject&, Object*);
  17. explicit WeakRef(Object*, Object& prototype);
  18. virtual ~WeakRef() override;
  19. Object* value() const { return m_value; };
  20. void update_execution_generation() { m_last_execution_generation = vm().execution_generation(); };
  21. virtual void remove_swept_cells(Badge<Heap>, Vector<Cell*>&) override;
  22. private:
  23. virtual void visit_edges(Visitor&) override;
  24. Object* m_value { nullptr };
  25. u32 m_last_execution_generation { 0 };
  26. };
  27. }