LibJS: Make JS::Cell a Weakable

This makes things easier downstream of Cell, and is preparation for
using weak pointers in prototype chain property caches.
This commit is contained in:
Andreas Kling 2024-05-02 10:24:23 +02:00
parent b5a7a8dbfd
commit 3945e1a82a
Notes: sideshowbarker 2024-07-17 08:59:18 +09:00
12 changed files with 13 additions and 31 deletions

View file

@ -12,6 +12,7 @@
#include <AK/HashMap.h>
#include <AK/Noncopyable.h>
#include <AK/StringView.h>
#include <AK/Weakable.h>
#include <LibJS/Forward.h>
#include <LibJS/Heap/GCPtr.h>
#include <LibJS/Heap/Internals.h>
@ -27,7 +28,7 @@ public: \
} \
friend class JS::Heap;
class Cell {
class Cell : public Weakable<Cell> {
AK_MAKE_NONCOPYABLE(Cell);
AK_MAKE_NONMOVABLE(Cell);

View file

@ -50,11 +50,7 @@ Heap::Heap(VM& vm)
gc_perf_string_id = perf_register_string(gc_signpost_string.characters_without_null_termination(), gc_signpost_string.length());
#endif
if constexpr (HeapBlock::min_possible_cell_size <= 16) {
m_size_based_cell_allocators.append(make<CellAllocator>(16));
}
static_assert(HeapBlock::min_possible_cell_size <= 24, "Heap Cell tracking uses too much data!");
m_size_based_cell_allocators.append(make<CellAllocator>(32));
static_assert(HeapBlock::min_possible_cell_size <= 32, "Heap Cell tracking uses too much data!");
m_size_based_cell_allocators.append(make<CellAllocator>(64));
m_size_based_cell_allocators.append(make<CellAllocator>(96));
m_size_based_cell_allocators.append(make<CellAllocator>(128));

View file

@ -20,9 +20,7 @@
namespace JS {
// 9.3 Realms, https://tc39.es/ecma262/#realm-record
class Realm final
: public Cell
, public Weakable<Realm> {
class Realm final : public Cell {
JS_CELL(Realm, Cell);
JS_DECLARE_ALLOCATOR(Realm);

View file

@ -34,9 +34,7 @@ struct TransitionKey {
}
};
class Shape final
: public Cell
, public Weakable<Shape> {
class Shape final : public Cell {
JS_CELL(Shape, Cell);
JS_DECLARE_ALLOCATOR(Shape);

View file

@ -22,9 +22,7 @@ namespace Web::Bindings {
}
// https://webidl.spec.whatwg.org/#dfn-platform-object
class PlatformObject
: public JS::Object
, public Weakable<PlatformObject> {
class PlatformObject : public JS::Object {
JS_OBJECT(PlatformObject, JS::Object);
public:

View file

@ -25,9 +25,7 @@ struct CSSStyleSheetInit {
bool disabled { false };
};
class CSSStyleSheet final
: public StyleSheet
, public Weakable<CSSStyleSheet> {
class CSSStyleSheet final : public StyleSheet {
WEB_PLATFORM_OBJECT(CSSStyleSheet, StyleSheet);
JS_DECLARE_ALLOCATOR(CSSStyleSheet);

View file

@ -28,8 +28,7 @@
namespace Web::HTML {
class BrowsingContext final : public JS::Cell
, public Weakable<BrowsingContext> {
class BrowsingContext final : public JS::Cell {
JS_CELL(BrowsingContext, JS::Cell);
JS_DECLARE_ALLOCATOR(BrowsingContext);

View file

@ -45,9 +45,7 @@ struct TargetSnapshotParams {
};
// https://html.spec.whatwg.org/multipage/document-sequences.html#navigable
class Navigable
: public JS::Cell
, public Weakable<Navigable> {
class Navigable : public JS::Cell {
JS_CELL(Navigable, JS::Cell);
JS_DECLARE_ALLOCATOR(Navigable);

View file

@ -14,9 +14,7 @@ namespace Web::HTML {
// NOTE: Temporary class to handle console messages from inside Workers
class WorkerDebugConsoleClient final
: public JS::ConsoleClient
, public Weakable<WorkerDebugConsoleClient> {
class WorkerDebugConsoleClient final : public JS::ConsoleClient {
JS_CELL(WorkerDebugConsoleClient, JS::ConsoleClient);
JS_DECLARE_ALLOCATOR(WorkerDebugConsoleClient);

View file

@ -37,8 +37,7 @@ enum class LayoutMode {
class Node
: public JS::Cell
, public TreeNode<Node>
, public Weakable<Node> {
, public TreeNode<Node> {
JS_CELL(Node, JS::Cell);
public:

View file

@ -55,7 +55,7 @@ HTML::Navigable& Page::focused_navigable()
void Page::set_focused_navigable(Badge<EventHandler>, HTML::Navigable& navigable)
{
m_focused_navigable = navigable.make_weak_ptr();
m_focused_navigable = navigable;
}
void Page::load(URL::URL const& url)

View file

@ -18,8 +18,7 @@
namespace WebContent {
class WebContentConsoleClient final : public JS::ConsoleClient
, public Weakable<WebContentConsoleClient> {
class WebContentConsoleClient final : public JS::ConsoleClient {
JS_CELL(WebContentConsoleClient, JS::ConsoleClient);
JS_DECLARE_ALLOCATOR(WebContentConsoleClient);