Commit graph

5928 commits

Author SHA1 Message Date
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
Andreas Kling
2a5dbedad4 Revert "LibWeb/CSS: Keep invalid parts of <forgiving-selector-list>s around"
This reverts commit 698dd600f2.

This caused multiple tests to crash on macOS:
https://github.com/LadybirdBrowser/ladybird/pull/2317#issuecomment-2474725826
2024-11-13 21:37:34 +01:00
Sam Atkins
698dd600f2 LibWeb/CSS: Keep invalid parts of <forgiving-selector-list>s around
Selectors like `:is(.valid, &!?!?!invalid)` need to keep the invalid
part around, even though it will never match, for a couple of reasons:

- Serialization needs to include them
- For nesting, we care if a `&` appeared anywhere in the selector, even
  in an invalid part.

So this patch introduces an `Invalid` simple selector type, which simply
holds its original ComponentValues. We search through these looking for
`&`, and we dump them out directly when asked to serialize.
2024-11-13 20:38:12 +01:00
Timothy Flynn
83b1db785a LibWebView+WebContent+UI: Remember the current system visibility state
We will want to re-inform WebContent of the system visibility state when
we create a new process after a crash. This changes the IPC to just send
the enum value directly, instead of a boolean, so that we can just store
that enum value directly on the ViewImplementation class.
2024-11-13 20:36:47 +01:00
Shannon Booth
c04b14d0cb LibWeb: Use alternative workaround for null strategy algorithm on abort
Some checks are pending
CI / Lagom (false, FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (true, NO_FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Push notes / build (push) Waiting to run
This unfortunately caused a regression for the included WPT test.
Instead of reordering the spec step, fall back to the default size
strategy of 1.
2024-11-13 10:44:22 -05:00
Sam Atkins
a6822986bb LibWeb/Painting: Apply clip and mask operations that are off-screen
These operations should still apply even if they are off screen, because
they affect painting of things outside of their bounding rectangles.

This commit makes us always apply these, regardless of if they are in
the visible region. However, if they are outside that region, we
replace them with simple clip-rect commands, which have the same
effect (not painting anything) but are cheaper than computing a full
mask bitmap.
2024-11-13 16:10:15 +01:00
Timothy Flynn
3e5476c9e0 LibWeb: Guard MediaQueryList event listener removal against null
A recently imported WPT test has a subtest that effectively does the
following:

    const mql = window.matchMedia("");
    mql.removeListener(null);
2024-11-13 14:59:14 +01:00
Timothy Flynn
213155ad7d LibWeb: Use GCPtr in MediaQueryList 2024-11-13 14:59:14 +01:00
Luke Wilde
4dd14d812f LibWeb: Make iframe insertion steps check the shadow including root
The insertion steps for iframes were following an old version of the
spec, where it was checking if the iframe was "in a document tree",
which doesn't cross shadow root boundaries. The spec has since been
updated to check the shadow including root instead.

This is now needed for Cloudflare Turnstile iframe widgets to appear,
as they are now inserted into a shadow root.
2024-11-13 14:40:02 +01:00
Luke Wilde
6df4e5f5e7 LibWeb: Actually traverse the shadow root of the inclusive descendant
Previously, the inclusive descendant, which is the node that
for_each_shadow_including_inclusive_descendant was called on, would not
have it's shadow root traversed if it had one.

This is because the shadow root traversal was in the `for` loop, which
begins with the node's first child. The fix here is to move the shadow
root traversal outside of the loop, and check if the current node is an
element instead.
2024-11-13 14:40:02 +01:00
Tim Ledbetter
d3c21e4038 LibWeb: Copy bitmap onto the returned canvas when taking a screenshot 2024-11-13 14:38:39 +01:00
Tim Ledbetter
b08f12d3e6 LibGfx: Add a method to copy a Bitmap to a PaintingSurface 2024-11-13 14:38:39 +01:00
Jelle Raaijmakers
3d8ab0e67c LibWeb: Add WebGLShaderPrecisionFormat
Some checks are pending
CI / Lagom (false, FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (true, NO_FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Push notes / build (push) Waiting to run
2024-11-13 11:41:54 +01:00
Jelle Raaijmakers
d63a979bde LibWeb: Add WebGLActiveInfo 2024-11-13 11:41:54 +01:00
Jelle Raaijmakers
889e7942fa LibWeb: Add WebGLUniformLocation 2024-11-13 11:41:54 +01:00
Jelle Raaijmakers
f2a1643650 LibWeb: Add WebGLTexture 2024-11-13 11:41:54 +01:00
Jelle Raaijmakers
2b09afb971 LibWeb: Add WebGLShader 2024-11-13 11:41:54 +01:00
Jelle Raaijmakers
d53cb9833b LibWeb: Add WebGLRenderbuffer 2024-11-13 11:41:54 +01:00
Jelle Raaijmakers
6b7d5dbec6 LibWeb: Add WebGLProgram 2024-11-13 11:41:54 +01:00
Jelle Raaijmakers
5d0b206d6e LibWeb: Add WebGLFramebuffer 2024-11-13 11:41:54 +01:00
Jelle Raaijmakers
b21857b265 LibWeb: Add WebGLBuffer 2024-11-13 11:41:54 +01:00
Jelle Raaijmakers
e6ee7f3e64 LibWeb: Add WebGLObject interface 2024-11-13 11:41:54 +01:00
Jelle Raaijmakers
e8d91f2234 LibWeb: Add missing RGBA8 constant to WebGLRenderingContext 2024-11-13 11:41:54 +01:00
Michael Watt
3b1d1d4582 LibWeb: Compute display: contents as none for unusual elements
https://drafts.csswg.org/css-display-3/#unbox-html specifies certain
elements that have their `display` style computed as `none` when
specified as `contents`.

This fixes at least one WPT test:
http://wpt.live/css/css-display/display-contents-suppression-dynamic-001.html
2024-11-13 11:11:07 +01:00
Shannon Booth
eef9a53eec LibJS: Make Heap own its own StackInfo instance
While this does mean that we keep one copy of the stack info in the VM,
and another in the Heap; keeping a separate instance removes one more
instance of coupling between the heap and LibJS specific details.
2024-11-13 11:08:35 +01:00
Shannon Booth
d199bf60cf LibJS: Do not clear VM's string cache in Heap's destructor
There is definitely a possibility I am misunderstanding the reason
behind it - but this does not appear neccessary. The VM owns both the
string cache and Heap. On destruction, the VM should clear out both
the heap and its string cache.
2024-11-13 11:08:35 +01:00
Shannon Booth
cf27eef583 LibJS: Move WeakContainer into the Heap folder
While this is used in the implementation of Runtime objects itself, Heap
seems like a more appropriate home. This will also help in factoring out
the GC implementation into it's own library as the heap explicitly has
knowledge of WeakContainer.
2024-11-13 11:08:35 +01:00
Shannon Booth
2f6bcb3538 LibJS: Remove some unused runtime headers from Heap folder 2024-11-13 11:08:35 +01:00
Shannon Booth
520aa04092 LibJS: Move Handle's Value specialization to Value header
This is part of an effort to keep JS runtime specifics outside of the
Heap implementation.
2024-11-13 11:08:35 +01:00
Hermes Junior
77a46ab1b8 LibJS: Correctly return cached value for global var bindings
Some checks are pending
CI / Lagom (false, FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (true, NO_FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Push notes / build (push) Waiting to run
When the cached value was not an accessor, it was simply ignored.
This is the value we really want, so we can just return it.
Shows up to 5x improvements on some benchmarks,
and 1.4x in general js-benchmarks.
2024-11-12 21:13:48 +01:00
Andreas Kling
b6a5b7e186 LibJS: Stop having AsyncFunctionDriverWrapper leak itself
Some checks are pending
CI / Lagom (false, FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (true, NO_FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Push notes / build (push) Waiting to run
Async functions whose promise is never resolved were leaking, since they
had a strong root JS::Handle on themselves.

This doesn't appear to actually be necessary, since the wrapper will be
kept alive as long as it's reachable (and if it's not reachable, nobody
is going to resolve/reject the promise either).

This fixes the vast majority of leaks on Speedometer, bringing memory
usage at the end of a full run from ~12 GiB to ~3 GiB.
2024-11-12 17:38:21 +01:00
Andreas Kling
10724a7cb3 LibJS: Use ConservativeVector when instantiating static class fields
This fixes an issue where a badly-timed garbage collection could swallow
a static field initializer.

Caught by running test262 in GC-on-every-allocation mode.
2024-11-12 17:38:21 +01:00
Andreas Kling
2fb3b6c542 LibJS: Make ConservativeVector<T> visit all possible values
We were miscalculating the length of the buffer in pointer-sized chunks,
which is what the conservative root scan cares about.

This could cause some values to be prematurely garbage-collected.
2024-11-12 17:38:21 +01:00
Luke Wilde
faf6fd1189 LibWeb: Remove LegacyOverrideBuiltIns flag from Storage
This was preventing https://ubereats.com/ from fully loading, because
they are attempting to overwrite setItem. They seem to be trying to add
error logging to setItem if it throws, as all they do is add a
try/catch block that emits an error log to their monitoring service if
it throws.

However, because Storage is a legacy platform object with a named
property setter (setItem), it will call setItem with the stringified
version of the function. This is actually expected as per the spec,
Firefox (Gecko) and Epiphany (WebKit) does this too, but Chromium does
not as it actually overwrites the function with the new function and
does not store the stringified function.

The problem is that we had the LegacyOverrideBuiltIns flag accidentally
set, so it would return the stored string instead of the built-in
function (hence the name), then it would try and call it and throw a
"not a function" error. This prevented their JS from going any further.

This fix allows their UI to fully load and be fully interactive, though
it is quite slow at the moment!
2024-11-12 15:34:36 +01:00
Timothy Flynn
4add737e88 LibWebView: Log the last URL we loaded when WebContent crashes
We display this URL in the error page, but let's log it for headless-
browser as well.
2024-11-12 14:25:59 +00:00
Timothy Flynn
d2151e444e LibWebView: Make loading an error page after a crash optional
We won't need this in headless-browser (who isn't calling this helper
yet).
2024-11-12 14:25:59 +00:00
Luke Wilde
956b279ae1 LibJS: Parse dates like "November 19 2024 00:00:00 +0900"
This format is used on https://jojowiki.com/ to show countdowns to new
releases.
2024-11-12 13:23:34 +01:00
Ali Mohammad Pur
dabd60180f LibRegex: Don't ignore references that weren't bound in checked blocks
Fixes #2281.
2024-11-12 10:37:57 +01:00
sideshowbarker
55b19c3177 LibWeb: Remove unused append_with_space etc functions from DOM::Node
Some checks are pending
CI / Lagom (false, FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (true, NO_FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Push notes / build (push) Waiting to run
This change removes the append_without_space, append_with_space,
prepend_without_space, and prepend_with_space functions from DOM::Node.

All those methods were added with the initial “Implement Accessible Name
and Description Calculation” commit in da5c918 and were only used in the
code related to accessible-name computation. But subsequent changes to
that code have removed all the calls to those functions — so now they’re
all completely unused.
2024-11-11 14:56:46 -07:00
sideshowbarker
dfd50afa4e LibWeb: Add an alternative_text() getter
This change adds an alternative_text()·getter, for use in computing
accessible names.
2024-11-11 14:56:46 -07:00
sideshowbarker
6d29afaa6c LibWeb: Fix accessible-name computation for aria-labelledby cases
This change ensures that when the aria-labelledby attribute is used, the
expected text from the element referenced in the aria-labelledby value
appears in the computed accessible name. Otherwise, without this change,
the expected text doesn’t appear in the computed accessible name.
2024-11-11 14:56:46 -07:00
sideshowbarker
b1587cc60f LibWeb: Fix accessible-name computation for pseudo-element content
This change fixes handling for substep ii of the “F. Name From Content”
step at https://w3c.github.io/accname/#step2F in the “Accessible Name
and Description Computation” spec — to correctly include any ::before
and ::after pseudo-element content in the computation of accessible
names. Otherwise, without this change, accessible names unexpectedly
don’t include that pseudo-element content.
2024-11-11 14:56:46 -07:00
sideshowbarker
3ba7c53668 LibWeb: Ensure spaces get added where expected within accessible names
This change implements the https://w3c.github.io/accname/#comp_append
step in the “Accessible Name and Description Computation” spec — so that
when an accessible name is computed from multiple sources in a document
subtree, the parts of the computed text are joined together with spaces.

Otherwise without this change, in accessible names computed from
multiple sources in a document subtree, the parts of the computed text
are unexpectedly run together, with no spaces between the parts.
2024-11-11 14:56:46 -07:00
Andreas Kling
b3b97d2049 LibWeb: Unregister network requests *after* invoking callbacks
This ensures that the network request actually gets unreffed and deleted
at the right time.
2024-11-11 21:40:56 +01:00
Andreas Kling
b397a0d535 LibWeb: Make Document::m_intersection_observers a weak mapping
These registrations are not meant to keep the observers alive.
This fixes a handful of world leaks on Speedometer.
2024-11-11 21:40:56 +01:00
Andreas Kling
6a6618f5ea LibJS: Add RawNonnullGCPtr<T>
This is really just a type alias for NonnullGCPtr<T>, but it provides
a way to have non-owning non-visited NonnullGCPtr<T> without getting
yelled at by the Clang plugin for catching GC errors.
2024-11-11 21:40:56 +01:00
Andreas Kling
e240084437 LibJS: Use correct cell address for HeapFunction captures in GC dumps
We were previously dumping the address of the cell pointer instead of
the address of the cell itself. This was causing mysterious orphans
in GC dumps, and it took me way too long to figure this out.
2024-11-11 21:40:56 +01:00
Aliaksandr Kalenik
7efc89e92b LibWeb: Remove usage of containing_block to get available height in GFC
There is no need to do containing block lookup when this value is
provided in argument of ::run()
2024-11-11 20:20:39 +01:00
Aliaksandr Kalenik
a073e35562 LibWeb: Delete unused functions in FormattingContext 2024-11-11 20:20:39 +01:00
Aliaksandr Kalenik
a8c1d12e84 LibWeb: Fix percentage insets resolution for grid items
compute_inset() was incorrectly retrieving the containing block size
because containing_block() is unaware of grid areas that form a
containing block for grid items but do not exist in the layout tree.
With this change, we explicitly pass the containing block into
compute_inset(), allowing it to correctly provide the containing block
sizes for grid items.
2024-11-11 20:20:39 +01:00