diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2021-06-12 17:38:34 +0300 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-06-12 18:39:23 +0100 |
commit | 7eba63a8a30aa155c13bd2b475294c3f327fa9a1 (patch) | |
tree | 9b73a27dbc7e1f47d800d151879672985cda3c71 /Userland/Libraries/LibJS/Runtime/WeakRef.h | |
parent | 6913f06b6f8c58be771caa5af155d775e570aa73 (diff) | |
download | serenity-7eba63a8a30aa155c13bd2b475294c3f327fa9a1.zip |
LibJS: Add the WeakRef built-in object
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/WeakRef.h')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/WeakRef.h | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/WeakRef.h b/Userland/Libraries/LibJS/Runtime/WeakRef.h new file mode 100644 index 0000000000..43f03e3c2c --- /dev/null +++ b/Userland/Libraries/LibJS/Runtime/WeakRef.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <LibJS/Runtime/GlobalObject.h> +#include <LibJS/Runtime/Object.h> +#include <LibJS/Runtime/WeakContainer.h> + +namespace JS { + +class WeakRef final + : public Object + , public WeakContainer { + JS_OBJECT(WeakRef, Object); + +public: + static WeakRef* create(GlobalObject&, Object*); + + explicit WeakRef(Object& prototype, Object*); + virtual ~WeakRef() override; + + Object* value() const { return m_value; }; + + void update_execution_generation() { m_last_execution_generation = vm().execution_generation(); }; + + virtual void remove_sweeped_cells(Badge<Heap>, Vector<Cell*>&) override; + +private: + virtual void visit_edges(Visitor&) override; + + Object* m_value { nullptr }; + u32 m_last_execution_generation { 0 }; +}; + +} |