1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:37:43 +00:00

LibJS: Add a basic mark&sweep garbage collector :^)

Objects can now be allocated via the interpreter's heap. Objects that
are allocated in this way will need to be provably reachable from at
least one of the known object graph roots.

The roots are currently determined by Heap::collect_roots().

Anything that wants be collectable garbage should inherit from Cell,
the fundamental atom of the GC heap.

This is pretty neat! :^)
This commit is contained in:
Andreas Kling 2020-03-08 19:23:58 +01:00
parent 6da131d5db
commit 63e4b744ed
13 changed files with 498 additions and 6 deletions

View file

@ -27,21 +27,24 @@
#pragma once
#include <AK/HashMap.h>
#include <LibJS/Cell.h>
#include <LibJS/Forward.h>
#include <LibJS/Cell.h>
namespace JS {
class Object {
class Object : public Cell {
public:
Object() {}
virtual ~Object() {}
Object();
virtual ~Object();
Value get(String property_name) const;
void put(String property_name, Value);
virtual bool is_function() const { return false; }
virtual const char* class_name() const { return "Object"; }
virtual const char* class_name() const override { return "Object"; }
virtual void visit_graph(Cell::Visitor&) override;
private:
HashMap<String, Value> m_properties;