Commit graph

5 commits

Author SHA1 Message Date
Andreas Kling
a36f8aa36d LibWeb: Keep ResizeObserver targets weakly
Store ResizeObservation targets weakly, matching Blink and WebKit. A
ResizeObserver can be kept alive by the document while it has observed
targets, but the observation itself should not keep a removed target and
its subtree alive forever.

Prune dead observations before gathering active resize observations.
Snapshot the document observer list before pruning so unregistering an
observer cannot mutate the intrusive list being iterated. Keep gathered
active targets rooted while broadcasting callbacks, since an earlier
callback can remove a later target and trigger GC before delivery.

Expose an internals helper to force environment-bound test objects to be
treated as garbage. Add text coverage for both pruning a dead observer
during gather and GC during an earlier resize observer callback.
2026-05-16 18:48:52 +02:00
Andreas Kling
5fdcf207f8 LibWeb: Avoid GC allocation in ResizeObservation::is_active()
Extract the box size computation into a new compute_box_size() that
returns a plain struct with two doubles, and use it in is_active()
instead of calculate_box_size() which allocates a GC-managed
ResizeObserverSize object.

Since is_active() only needs to compare sizes and immediately discards
the result, there's no reason to involve the GC. The GC-allocating
calculate_box_size() now delegates to compute_box_size() internally.

This was 2.6% of CPU time while playing a YouTube video.
2026-02-21 03:51:28 +01:00
Shannon Booth
f87041bf3a LibGC+Everywhere: Factor out a LibGC from LibJS
Resulting in a massive rename across almost everywhere! Alongside the
namespace change, we now have the following names:

 * JS::NonnullGCPtr -> GC::Ref
 * JS::GCPtr -> GC::Ptr
 * JS::HeapFunction -> GC::Function
 * JS::CellImpl -> GC::Cell
 * JS::Handle -> GC::Root
2024-11-15 14:49:20 +01:00
Shannon Booth
9b79a686eb LibJS+LibWeb: Use realm.create<T> instead of heap.allocate<T>
The main motivation behind this is to remove JS specifics of the Realm
from the implementation of the Heap.

As a side effect of this change, this is a bit nicer to read than the
previous approach, and in my opinion, also makes it a little more clear
that this method is specific to a JavaScript Realm.
2024-11-13 16:51:44 -05:00
Timothy Flynn
93712b24bf Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
Renamed from Userland/Libraries/LibWeb/ResizeObserver/ResizeObservation.cpp (Browse further)