mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:37:36 +00:00
LibJS: Add the WeakRef built-in object
This commit is contained in:
parent
6913f06b6f
commit
7eba63a8a3
12 changed files with 268 additions and 1 deletions
39
Userland/Libraries/LibJS/Runtime/WeakRef.h
Normal file
39
Userland/Libraries/LibJS/Runtime/WeakRef.h
Normal file
|
@ -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 };
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue