瀏覽代碼

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.
Andreas Kling 1 年之前
父節點
當前提交
3945e1a82a

+ 2 - 1
Userland/Libraries/LibJS/Heap/Cell.h

@@ -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);
 

+ 1 - 5
Userland/Libraries/LibJS/Heap/Heap.cpp

@@ -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));

+ 1 - 3
Userland/Libraries/LibJS/Runtime/Realm.h

@@ -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);
 

+ 1 - 3
Userland/Libraries/LibJS/Runtime/Shape.h

@@ -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);
 

+ 1 - 3
Userland/Libraries/LibWeb/Bindings/PlatformObject.h

@@ -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:

+ 1 - 3
Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h

@@ -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);
 

+ 1 - 2
Userland/Libraries/LibWeb/HTML/BrowsingContext.h

@@ -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);
 

+ 1 - 3
Userland/Libraries/LibWeb/HTML/Navigable.h

@@ -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);
 

+ 1 - 3
Userland/Libraries/LibWeb/HTML/WorkerDebugConsoleClient.h

@@ -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);
 

+ 1 - 2
Userland/Libraries/LibWeb/Layout/Node.h

@@ -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:

+ 1 - 1
Userland/Libraries/LibWeb/Page/Page.cpp

@@ -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)

+ 1 - 2
Userland/Services/WebContent/WebContentConsoleClient.h

@@ -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);