Commit graph

8827 commits

Author SHA1 Message Date
stasoid
e1f70d532c LibCore: Implement LocalSocket on Windows
Windows flavor of non-blocking IO, overlapped IO, differs from that on
Linux. On Windows, the OS handles writing to overlapped buffer, while
on Linux user must do it manually.

Additionally, we can only have overlapped sockets because it is the
requirement to be able to wait on them - WSAEventSelect automatically
sets socket to nonblocking mode.

So we end up emulating Linux-nonblocking sockets with
Windows-nonblocking sockets.

Pending IO state (ERROR_IO_PENDING) must not escape read/write
functions. If that happens, all synchronization like WSAPoll and
WaitForMultipleObjects stops working (WaitForMultipleObjects stops
working because with overlapped IO you are supposed to wait on an event
in OVERLAPPED structure, while we are waiting on WSA Event, see
EventLoopImplementationWindows.cpp).
2025-02-10 12:46:25 -07:00
Shannon Booth
8088ab5306 LibWeb/URLPattern: Add a stub for URLPattern.exec
Just enough to get the IDL compiling :^)
2025-02-10 17:05:15 +00:00
Shannon Booth
f3ec727555 LibWeb/Bindings: Support returning nullable types in dictionaries
We were previously assuming that dictionary members were always
required when being returned.

This is a bit of a weird case, because unlike _input_ dictionaries
which the spec marks as required, 'result' dictionaries do not seem to
be marked in spec IDL as required. This is still fine from the POV that
the spec is written as it states that we should only be putting the
values into the dictionary if the value exists.

We could do this through some metaprogramming constexpr type checks.
For example, if the type in our C++ representation was not an
Optional, we can skip the has_value check.

Instead of doing that, change the IDL of the result dictionaries to
annotate these members so that the IDL generator knows this
information up front. While all current cases have every single
member returned or not returned, it is conceivable that the spec
could have a situation that one member is always returned (and
should get marked as required), while the others are optionally
returned. Therefore, this new GenerateAsRequired attribute is
applied for each individual member.
2025-02-10 17:05:15 +00:00
Shannon Booth
dc2c62825b LibURL: Add a representation of a URL Pattern 'result'
This is the return value of a URLPattern after `exec` is called on it.
It conveys information about the named (or unammed) regex groups
matched for each component of the URL. For example,

```
let p = new URLPattern({ hostname: "{:subdomain.}*example.com" });
const result = pattern.exec({ hostname: "foo.bar.example.com" });
console.log(result.hostname.groups.subdomain);
```

Will log 'foo.bar'.
2025-02-10 17:05:15 +00:00
Timothy Flynn
d873dc0744 LibWeb+WebDriver: Validate WebDriver proxy capabilities
We don't yet support a proxy configuration, but we can still validate
the capability received from the WebDriver client. We should also fail
to create a WebDriver session if a proxy configuration is present.
2025-02-10 11:33:53 -05:00
Timothy Flynn
88eda159af LibWeb: Remove "serenity:" prefix from custom WebDriver capabilities
We currently define our custom WebDriver capabilities with a dictionary
of the form:

    "serenity:ladybird": {
        "headless": true
    }

This patch flattens the configuration, such that each Ladybird option
will be its own capability. This matches how Firefox configures their
own options with geckodriver. So we now have:

    "ladybird:headless": true
2025-02-10 11:33:53 -05:00
Timothy Flynn
e0ecf3b033 LibWeb: Do not reject unknown WebDriver extension capabilities 2025-02-10 11:33:53 -05:00
Timothy Flynn
de34351ba8 LibWeb+WebDriver: Convert WebDriver session flags to an enumeration
Rather than a list of strings, this will be easier to deal with as a
bitwise enumeration.
2025-02-10 11:33:53 -05:00
Undefine
0c882c441e LibCompress: Remove unused Lzma compression and decompression 2025-02-10 16:22:32 +00:00
Undefine
f30fd8af4c LibCompress: Remove unused Lzma2 decompression 2025-02-10 16:22:32 +00:00
Undefine
a49b7c0125 LibCompress: Remove unused Xz decompression 2025-02-10 16:22:32 +00:00
Undefine
50d4479ddb LibCompress: Remove unused brotli decompression 2025-02-10 16:22:32 +00:00
Timothy Flynn
5f9ed343b3 LibThreading: Pass ownership of a BackgroundAction result to its caller
There is no need to create a copy of potentially expensive structures.
2025-02-10 16:05:43 +00:00
Timothy Flynn
f20aa82c27 LibThreading: Avert a reference cycle in BackgroundAction
When a BackgroundAction completes, it resolves a Promise (stored on the
BackgroundAction object) with a reference to itself. The Promise will
never unset this resolved value, thus it will hold a strong reference to
the BackgroundAction until it is destroyed. But because the Promise is
owned by the BackgroundAction itself, we have a reference cycle, and
neither object can be destroyed.

The only user of BackgroundAction is the ImageDecoder process. The
consequence was that the ImageDecoder process would never release any
image data for successfully decoded images.

To fix this, instead of storing the promise on the class itself, we can
just create it as a local variable and pass it around.
2025-02-10 16:05:43 +00:00
Timothy Flynn
063a3afe02 ImageDecoder: Fix memory leak of partially decoded invalid JPEG images
We have to be careful to always destroy the jpeglib decompression struct
before returning from JPEGLoadingContext::decode. We were doing this in
jpeglib error handlers, but we have a couple of paths that bail from the
decoder via TRY. These paths were neither cleaning up memory nor setting
the image decoder to an error state.

So this patch sets up a scope guard to ensure we free the decompressor
upon exit from the function. And it delegates the responsibility of
setting the decoder state to the caller (of which there is only one),
to ensure all error paths result in an error state.
2025-02-10 16:05:43 +00:00
Shannon Booth
03370dc76a LibWeb/HTML: Improve assertion for apply the history step mismatch
This more directly catches the bug we have that causes this
assertion to happen on certain sites and WPT tests.
2025-02-10 15:55:46 +00:00
Sam Atkins
dc58f6567f LibWeb: Support :open for file and color <input> elements 2025-02-10 13:57:36 +00:00
Sam Atkins
52a92b7937 LibWeb/HTML: Extract dialog show_modal() into its own algorithm
Corresponds to https://github.com/whatwg/html/pull/10961
2025-02-10 13:56:59 +00:00
Kenneth Myhra
21989ef543 LibWeb: Align ReadableByteStreamControllerEnqueue
Align ReadableByteStreamControllerEnqueue with current spec steps.
2025-02-10 13:25:51 +00:00
Kenneth Myhra
4699bf24dc LibWeb: Align ReadableByteStreamControllerRespondInClosedState
Align ReadableByteStreamControllerRespondInClosedState with current spec
steps.
2025-02-10 13:25:51 +00:00
Kenneth Myhra
4b917d366c LibWeb: Align ReadableByteStream(...)FillPullIntoDescriptorFromQueue
Align ReadableByteStreamControllerFillPullIntoDescriptorFromQueue with
current spec steps.
2025-02-10 13:25:51 +00:00
Psychpsyo
14e354bc29 LibWeb: Implement playbackRate 2025-02-10 11:38:02 +00:00
Shannon Booth
c954d0be27 LibWeb/DOM: Add missing UTF-8 decode without BOM on fragment ID
We were previously crashing instead of using the replacement
character on invalid bytes.
2025-02-10 09:48:08 +00:00
Aliaksandr Kalenik
adc17c3576 LibWeb: Deduplicate code for pseudo class selector matching
Moves pseudo class matching helpers into Element methods, so they don't
have to be duplicated between SelectorEngine and function that checks if
element is included in invalidation set.
2025-02-10 01:26:47 +01:00
Andreas Kling
0084d992d4 LibWeb: Remove unnecessary re-measurement of cross sizes in flex layout
This was an old hack from before we understood how and when to resolve
percentages in flex layout. Removing it should not change anything,
but it does avoid a lot of redundant layout work on many pages.
2025-02-10 01:26:34 +01:00
Aliaksandr Kalenik
e677ab1699 LibWeb: Narrow :has() style invalidation to ancestor nodes
The current implementation of `:has()` style invalidation is divided
into two cases:
- When used in subject position (e.g., `.a:has(.b)`).
- When in a non-subject position (e.g., `.a > .b:has(.c)`).

This change focuses on improving the first case. For non-subject usage,
we still perform a full tree traversal and invalidate all elements
affected by the `:has()` pseudo-class invalidation set.

We already optimize subject `:has()` invalidations by limiting
invalidated elements to ones that were tested against `has()` selectors
during selector matching. However, selectors like `div:has(.a)`
currently cause every div element in the document to be invalidated.
By modifying the invalidation traversal to consider only ancestor nodes
(and, optionally, their siblings), we can drastically reduce the number
of invalidated elements for broad selectors like the example above.

On Discord, when scrolling through message history, this change allows
to reduce number of invalidated elements from ~1k to ~5.
2025-02-10 01:13:53 +01:00
Shannon Booth
7441aa34e4 LibWeb/HTML: Bail from HTML parsing when EOF hit on document.close
This fixes a crash in the included test that regressed in 0adf261,
and is hit by the following HTML:

```html
<body></body>
<script>
  const frame = document.body.appendChild(document.createElement("iframe"));
  frame.contentDocument.open();
  const child = frame.contentDocument.createElement("html")
  const html = frame.contentDocument.appendChild(child);
  frame.contentDocument.close();
</script>
```

I am not 100% sure this is fully the correct fix and there are other
cases which would not work properly. But it's definitely an improvement
to make the confuisingly named 'insert_an_eof' function of the tokenizer
actually do something.
2025-02-09 19:20:09 +00:00
Tim Ledbetter
9e556972ae LibWeb: Reset find-in-page index if selection is cleared
Previously, if the user made a find-in-page query, then cleared the
selection made by that query, subsequent queries would inadvertently
advance to the next match instead of reselecting the first match.
2025-02-09 18:19:58 +00:00
Andreas Kling
5f10f8c54c LibWeb: Do includes_properties_from_invalidation_set() for :link & co
Fixes #3511.
2025-02-09 15:20:53 +01:00
Tim Ledbetter
c4bc0842c1 LibWeb: Prevent AudioBuffer data being copied to or from a shared buffer 2025-02-09 14:13:46 +00:00
Luke Wilde
958938655d LibWeb/WebGL: Implement WEBGL_compressed_texture_s3tc extension 2025-02-09 01:00:51 +01:00
Luke Wilde
484008d440 LibWeb/WebGL: Implement compressedTex(Sub)Image2D 2025-02-09 01:00:51 +01:00
Luke Wilde
f1b81b1ae2 LibWeb/WebGL2: Implement getActiveUniforms 2025-02-09 01:00:51 +01:00
Luke Wilde
071a445015 LibWeb/WebGL2: Implement drawArraysInstanced 2025-02-09 01:00:51 +01:00
Luke Wilde
13f28cb941 LibWeb/WebGL: Reimplement OpenGLContext::clear_buffer_to_default_values
The implementation was removed with the migration to ANGLE. This
reimplements it. This is required by Stimulation Clicker on neal.fun,
which does not clear the framebuffer itself, instead relying on the
browser doing it.
2025-02-09 01:00:51 +01:00
Andreas Kling
dbf52a1b5f LibJS: Allocate RegExp.{lastMatch,leftContext,rightContext} lazily
These properties are always substrings of the RegExp input string,
and so we can store them as views and lazily construct strings if
they're actually accessed (which most of the time they aren't).

This avoids a bunch of unnecessary memory copying, saving roughly
2.1 seconds per iteration of Speedometer.
2025-02-09 00:28:15 +01:00
Andreas Kling
39abd75d59 LibWeb: Use invalidation sets for link-related pseudo classes
- :any-link
- :link
- :local-link
2025-02-08 18:11:24 +01:00
Andreas Kling
719a2e448f LibWeb: Use invalidation sets for :checked style invalidation 2025-02-08 18:11:24 +01:00
Tim Ledbetter
8b2de413ae LibWeb: Ensure selected options collection is created prior to access 2025-02-08 07:32:24 -05:00
Tim Ledbetter
dccb374876 LibWeb: Treat execCommand command names as case insensitive 2025-02-08 07:30:27 -05:00
Luke Wilde
cae0ee6fa7 LibWeb: Implement TextEncoderStream
Required by the server-side rendering mode of React Router, used by
https://chatgpt.com/

Note that the imported tests do not have the worker variants to prevent
freezing on macOS.
2025-02-07 11:04:46 -05:00
Luke Wilde
24d5f24749 LibWeb: Extract the TextEncoderCommon mixin to its own IDL file
Co-Authored-By: Tim Flynn <trflynn89@pm.me>
2025-02-07 11:04:46 -05:00
Luke Wilde
c14d5f27f9 LibWeb: Use DefaultReader request in read_all_chunks instead of ReadLoop
ReadLoop requests require the chunks to be Uint8Array objects, however,
TextEncoderStream requires a String (Convertible) value. This is fixed
by implementing read_all_chunks as a loop of DefaultReader requests
instead, which is an identity transformation. This should be okay to
do, as stream chunk steps expect a JS::Value, and convert it to the
type they want.
2025-02-07 11:04:46 -05:00
Andreas Kling
187f8c5460 LibWeb: Run queued HTML tasks after associated document is destroyed
Before this change, tasks associated with a destroyed document would get
stuck in the task queue forever, since document-associated tasks are not
allowed to run when their document isn't fully active (and destroyed
documents never become fully active again). This caused everything
captured by task callbacks to leak.

We now treat tasks for destroyed documents as runnable immediately,
which gets them out of the queue.

This fixes another massive GC leak on Speedometer.
2025-02-07 16:53:11 +01:00
Andreas Kling
53c9c6f3ee LibWeb: Make Agent's MutationObserver list weak
Before this change, Agent held on to all of the live MutationObserver
objects via GC::Root. This prevented them from ever getting
garbage-collected.

Instead of roots, we now use a simple IntrusiveList and remove them
from it in the finalizer for MutationObserver.

This fixes a massive GC leak on Speedometer.
2025-02-07 16:53:11 +01:00
Aliaksandr Kalenik
ccb513abf7 LibWeb: Invalidate layout tree of parent of inserted node
f7a3f78 made the layout tree invalidate only the inserted nodes
themselves, but it turned out that CSS containment invalidation relies
on the parent being invalidated as well.
2025-02-07 01:23:10 +01:00
stasoid
f696f20cd8 LibCore: Port SystemServerTakeover.cpp to Windows 2025-02-06 15:25:14 -07:00
stasoid
52d0341c5d LibJS: Port to Windows 2025-02-06 15:16:50 -07:00
stasoid
a291a7f770 LibCore: Add System::sleep_ms 2025-02-06 15:16:50 -07:00
stasoid
e6e233fd64 LibCore: Correctly pass arguments with spaces to Process on Windows 2025-02-06 15:15:16 -07:00