mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-12 01:46:46 +02:00
Move weak container cleanup (remove_dead_cells) out of both sweep_dead_cells() and start_incremental_sweep() to the place where it is actually safe to inspect cell state: collect_garbage(). Previously, remove_dead_cells could access cells that had already been swept and poisoned by ASAN, causing use-after-poison crashes when a new GC triggered while an incremental sweep was in progress.
45 lines
1.1 KiB
C++
45 lines
1.1 KiB
C++
/*
|
|
* Copyright (c) 2021-2022, Idan Horowitz <idan.horowitz@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibGC/WeakContainer.h>
|
|
#include <LibJS/Runtime/GlobalObject.h>
|
|
#include <LibJS/Runtime/Object.h>
|
|
|
|
namespace JS {
|
|
|
|
class WeakRef final
|
|
: public Object
|
|
, public GC::WeakContainer {
|
|
JS_OBJECT(WeakRef, Object);
|
|
GC_DECLARE_ALLOCATOR(WeakRef);
|
|
|
|
public:
|
|
static GC::Ref<WeakRef> create(Realm&, Object&);
|
|
static GC::Ref<WeakRef> create(Realm&, Symbol&);
|
|
|
|
virtual ~WeakRef() override = default;
|
|
|
|
auto const& value() const { return m_value; }
|
|
|
|
void update_execution_generation() { m_last_execution_generation = vm().execution_generation(); }
|
|
|
|
virtual Cell const& owner_cell(Badge<GC::Heap>) const override { return *this; }
|
|
virtual void remove_dead_cells(Badge<GC::Heap>) override;
|
|
|
|
private:
|
|
explicit WeakRef(Object&, Object& prototype);
|
|
explicit WeakRef(Symbol&, Object& prototype);
|
|
|
|
virtual void visit_edges(Visitor&) override;
|
|
|
|
Variant<GC::Ptr<Object>, GC::Ptr<Symbol>, Empty> m_value;
|
|
u32 m_last_execution_generation { 0 };
|
|
};
|
|
|
|
}
|