Commit graph

70476 commits

Author SHA1 Message Date
Gingeh
28774efa22 LibWeb: Don't crash when drawing null image from offscreen canvas
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / 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
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
2025-07-20 08:54:53 +02:00
Gingeh
55129644d5 LibWeb: Don't crash when root element becomes a popover or fullscreen 2025-07-20 08:54:53 +02:00
Gingeh
f38e07e0c5 LibWeb: Don't crash when an unknown property begins with a single dash 2025-07-20 08:54:53 +02:00
Tim Ledbetter
48417152df LibWeb: Don't crash when creating empty bitmap from a HTMLCanvasElement 2025-07-20 16:26:57 +12:00
Tim Ledbetter
bd83f5bde6 test-web: Treat files in images directories as resources for WPT tests 2025-07-20 16:26:57 +12:00
Tim Ledbetter
4a223ad085 Meta: Don't check png sizes for images imported from WPT 2025-07-20 16:26:57 +12:00
Tim Ledbetter
7874f325a8 LibWeb: Implement InputEvent.getTargetRanges()
This returns a list of ranges that would be affected by a change to the
DOM if the input event is not cancelled.
2025-07-20 12:34:14 +12:00
Kenneth Myhra
ed3d0d76ec LibWeb: Implement transfer {,receiving} steps for ImageBitmap 2025-07-20 12:30:43 +12:00
Kenneth Myhra
c0976b18e0 LibWeb: Implement {,de}serialization steps for ImageBitmap
To make {,de}serialization of ImageBitmap work we also had to add
support for creating an ImageBitmap from a HTMLCanvasElement in
WindowOrWorkerGlobalScopeMixin::create_image_bitmap_impl().
2025-07-20 12:30:43 +12:00
Kenneth Myhra
7b4ee57037 LibWeb: Add get_bitmap_from_surface() and use it from to_blob()
This refactors out the reading part of Gfx::Bitmap from
HtmlCanvasElement::surface(). We can then reuse this from
WindowOrWorkerGlobalScopeMixin::create_image_bitmap_impl() when we
create an ImageBitmap from a HtmlCanvasElement.
2025-07-20 12:30:43 +12:00
Kenneth Myhra
09f336bf8f LibGfx: Use static_cast instead of C-style cast 2025-07-20 12:30:43 +12:00
Kenneth Myhra
2394845d58 LibWeb: Align specification step text with current specification 2025-07-20 12:30:43 +12:00
Timothy Flynn
27d139e817 LibWeb: Define Wasm native errors correctly
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / 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
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
1. Fix typos in some macro invocations of these error types. We now use
   a single xmacro to instantiate error definitions to prevent such
   errors in the future.

2. Use the "WebAssembly." prefix as needed.

3. Allocate the error constructors and prototypes with `realm.create`
   rather than `heap.allocate`. The latter does not invoke `initialize`
   methods. This exposed the next issue:

4. Use the correct intrinsic prototype in the error constructor. We were
   using the base native error prototype. We unfortunately cannot invoke
   OrdinaryCreateFromConstructor from LibJS directly with the correct
   prototype, so an implementation was added here.

5. Use intrinsic accessors to create the constructors. I don't think
   this one was actually a fix, but it makes the setup look more like
   other built-ins.
2025-07-19 16:48:01 -04:00
Timothy Flynn
6b3f796e5b LibWeb: Propagate errors from module instantiation 2025-07-19 16:48:01 -04:00
Timothy Flynn
a458a7d35b LibWeb: Do not coerce object IDL types to JS objects
We should bail with a TypeError if the provided value is not a JS object
already.
2025-07-19 16:48:01 -04:00
Timothy Flynn
7b14da14d8 Tests/LibWeb: Import tests for incorrect Wasm instantiations 2025-07-19 16:48:01 -04:00
ayeteadoe
f468f702d5 CMake: Update default BUILD_PRESET arg to Release in WPT.sh
The presets were recently refactored and 'default' was
renamed to 'Release', but keeping it in sync with
any consumer shell scripts was missed.
2025-07-19 21:03:51 +02:00
Andreas Kling
92221f0c57 LibWeb: Apply all animations and transitions before invalidating style
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
This fixes an issue where only the last KeyframeEffect applied to an
element would actually have an effect on the computed properties.

It was particularly noticeable when animating a shorthand property like
border-width, since only one of the border edges would have its width
actually animate.

By deferring the invalidation until all animations have been processed,
we also reduce the amount of work that gets done on pages with many
animations/transitions per element. Discord is very fond of this for
example.
2025-07-19 11:08:46 -04:00
Andrew Kaster
50422eb563 Tests: Add XHTML tests for CDATA, PIs and Comment nodes in the DOM 2025-07-19 14:56:20 +02:00
Andrew Kaster
f9f854b493 LibWeb: Preserve comments in XML documents 2025-07-19 14:56:20 +02:00
Andrew Kaster
9d93d37644 LibWeb: Listen for CDATASections and ProcessingInstructions in XML docs
Using the new hooks in the XML Parser's listener interface, we now
append DOM nodes for CDATASections and ProcessingInstructions
to the document as they are encountered. This commit also fixes where
comment nodes are appended, ensuring they are added to the current node
instead of the document root.
2025-07-19 14:56:20 +02:00
Andrew Kaster
d9976b98b9 LibXML: Add parser hooks for CDATASection and ProcessingInstructions
This allows listeners to be notified when a CDATASection or
ProcessingInstruction is encountered during parsing. The non-listener
path still has the incorrect behavior of silently treating CDATASection
as Text nodes, but this allows listeners to handle them correctly.
2025-07-19 14:56:20 +02:00
Luke Wilde
5a1de8a187 LibWeb/CSP: Implement the child-src directive
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / 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
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
2025-07-19 17:15:21 +12:00
Luke Wilde
c5748437db LibWeb/CSP: Implement the default-src directive 2025-07-19 17:15:21 +12:00
Luke Wilde
25425f63ba LibWeb/CSP: Implement the worker-src directive 2025-07-19 17:15:21 +12:00
Aliaksandr Kalenik
714ff4e3f9 LibWeb: Fix previous style calculation for CSS transitions on pseudo
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / 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
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
...elements. Adds missing pseudo-element type passed into computed
properties getter.

Previously, due to this bug, we were using the element's computed
properties as the previous computed properties for its pseudo-elements.
This caused an excessive number of unintended CSS transitions to run.
The issue was particularly noticeable in Discord's emoji picker, where
each emoji has `::after` pseudo-element. We were incorrectly triggering
transitions on all their properties, resulting in significant
unnecessary work in style computation and animation event dispatching.
2025-07-18 21:19:37 +02:00
Aliaksandr Kalenik
2fc405f1b2 LibWeb: Allow to pass pseudo-element type in computed properties getter
...and setter. We had lots of places where we check if pseudo-element
type is specified and then use `pseudo_element_computed_properties()` or
`computed_properties()`. This change moves these checks from caller side
to the getter and setter.
2025-07-18 21:19:37 +02:00
Jelle Raaijmakers
86dc3ce001 AK: Add dbgln_dump() macro
This turns:

  dbgln_dump(some_expression() + 1);

Into:

  dbgln("some_expression() + 1: {}", (some_expression() + 1));
2025-07-18 14:40:00 -04:00
Timothy Flynn
9582895759 AK+LibJS+LibWeb+LibRegex: Replace AK::Utf16Data with AK::Utf16String 2025-07-18 12:45:38 -04:00
Timothy Flynn
a43cb15e81 LibJS+LibWeb: Replace JS::Utf16String with AK::Utf16String 2025-07-18 12:45:38 -04:00
Timothy Flynn
d40e3af697 AK: Implement UTF-16 string-to-number conversions 2025-07-18 12:45:38 -04:00
Timothy Flynn
6e0290ecaa AK: Define some UTF-16 helper methods
* contains
* escape_html_entities
* replace
* to_ascii_lowercase
* to_ascii_uppercase
* to_ascii_titlecase
* trim
* trim_whitespace
2025-07-18 12:45:38 -04:00
Timothy Flynn
7f069efbc4 AK: Implement a flyweight string for Utf16String
Utf16FlyString more or less works exactly the same as FlyString. It will
store the raw encoded data of the string instance. If the string is a
short ASCII string, Utf16FlyString holds the ShortString bytes; else,
Utf16FlyString holds a pointer to the Utf16StringData.
2025-07-18 12:45:38 -04:00
Timothy Flynn
2803d66d87 AK: Support UTF-16 string formatting
The underlying storage used during string formatting is StringBuilder.
To support UTF-16 strings, this patch allows callers to specify a mode
during StringBuilder construction. The default mode is UTF-8, for which
StringBuilder remains unchanged.

In UTF-16 mode, we treat the StringBuilder's internal ByteBuffer as a
series of u16 code units. Appending a single character will append 2
bytes for that character (cast to a char16_t). Appending a StringView
will transcode the string to UTF-16.

Utf16String also gains the same memory optimization that we added for
String, where we hand-off the underlying buffer to Utf16String to avoid
having to re-allocate.

In the future, we may want to further optimize for ASCII strings. For
example, we could defer committing to the u16-esque storage until we
see a non-ASCII code point.
2025-07-18 12:45:38 -04:00
Timothy Flynn
fe676585f5 AK: Add a UTF-16 string with optimized short- and ASCII-string storage
This is a strictly UTF-16 string with some optimizations for ASCII.

* If created from a short UTF-8 or UTF-16 string that is also ASCII,
  then the string is stored in an inlined byte buffer.

* If created with a long UTF-8 or UTF-16 string that is also ASCII,
  then the string is stored in an outlined char buffer.

* If created with a short or long UTF-8 or UTF-16 string that is not
  ASCII, then the string is stored in an outlined char16 buffer.

We do not store short non-ASCII text in the inlined buffer to avoid
confusion with operations such as `length_in_code_units` and
`code_unit_at`. For example, "😀" would be stored as 4 UTF-8 bytes
in short string form. But we still want `length_in_code_units` to
be 2, and `code_unit_at(0)` to be 0xD83D.
2025-07-18 12:45:38 -04:00
Timothy Flynn
8fbb80fffc AK: Do not fall back to simdutf for UTF-16 ASCII validation
This was a mistake. Consider U+201C (LEFT DOUBLE QUOTATION MARK). This
code point is encoded as the bytes 0x1c 0x20 in UTF-16LE. Both of these
bytes are ASCII if interpreted as UTF-8. But the string itself is most
certainly not ASCII.
2025-07-18 12:45:38 -04:00
Callum Law
4ee8110449 LibWeb: Handle flood-opacity in line with other opacity properties
We now do the proper thing in terms of:
 - Allowing percentages
 - Returning the computed value in getComputedStyle
 - Handling values out of the [0,1] range

Gains us 13 WPT passes in the imported tests.
2025-07-18 11:04:55 -04:00
Callum Law
6f39c30704 LibWeb: Propagate flood-color and flood-opacity to ComputedValues 2025-07-18 11:04:55 -04:00
Timothy Flynn
f6f31fe215 LibWeb: Remove ability to override MessagePort's primary interface
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / 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
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
This hack no longer has any users.
2025-07-18 10:09:02 -04:00
Timothy Flynn
d471b52b0e LibWeb: Assume structured deserialization creates the correct type
Most locations already make this assumption, but we had a few that would
silently ignore data mismatches. Let's just always assume the type is
correct for now. If a bad actor has a hold of our transport socket, it's
probably better to crash WebContent than to continue on with incorrect
data.

In the future, maybe we will want to throw an exception instead.
2025-07-18 10:09:02 -04:00
Timothy Flynn
ed71db45e7 LibWeb: Move array buffer/view serializers above their users
Now that these serializers are internal to StructuredSerialize.cpp,
let's put them above Serializer so they don't have to be forward-
declared and explicitly instantiated.
2025-07-18 10:09:02 -04:00
Timothy Flynn
64abc6101d LibWeb+WebWorker: Use IPC mechanics for structured serialization
Our structured serialization implementation had its own bespoke encoder
and decoder to serialize JS values. It also used a u32 buffer under the
hood, which made using its structures a bit awkward. We had previously
worked around its data structures in transferable streams, which nested
transfers of MessagePort instances. We basically had to add hooks into
the MessagePort to route to the correct transfer receiving steps, and
we could not invoke the correct AOs directly as the spec dictates.

We now use IPC mechanics to encode and decode data. This works because,
although we are encoding JS values, we are only ultimately encoding
primitive and basic AK types. The resulting data structures actually
enforce that we implement transferable streams exactly as the spec is
worded (I had planned to do that in a separate commit, but the fallout
of this patch actually required that change).
2025-07-18 10:09:02 -04:00
Timothy Flynn
7fad8c333d LibWeb: Use forward-declarations of structured serialized types
This reduces the rebuilt targets when touching StructuredSerialize.h
from ~1200 to ~400. The remaining are due to generated IPC headers.
2025-07-18 10:09:02 -04:00
Timothy Flynn
20c6005341 LibWeb: Use TemporaryExecutionContext in structured deserialization
No need to manually prepare / clean up a context. We also previously
would not have done the clean up steps if structured deserialization
threw an exception.
2025-07-18 10:09:02 -04:00
Timothy Flynn
b1cfc96609 LibWeb: Don't check is_object in every serialization branch
Instead of every branch being of the form:

    if (value.is_object() && is<SomeType>(value.as_object()) {
        auto& some_type = static_cast<SomeType&>(value.as_object());
    }

Let's extract the `is_object` check to an outer branch, and use `as_if`
to check the type.

No functional change, but this makes a future change simpler to review.
2025-07-18 10:09:02 -04:00
Timothy Flynn
b204977efb LibJS: Allow creating shared ArrayBuffer objects more easily
This will allow structured deserialization in LibWeb to create shared
buffers without having to go through CreateSharedByteDataBlock. That
will let us pass in the underlying ByteBuffer, rather than having to
allocate a second buffer via CreateSharedByteDataBlock and memcpy the
data into it.
2025-07-18 10:09:02 -04:00
Timothy Flynn
3fb4e769d8 LibJS: Allow assigning an error message after Error object creation
This will be used by structured deserialization in LibWeb.
2025-07-18 10:09:02 -04:00
Timothy Flynn
fd6d868ae2 LibIPC: Add some type aliases and MessageBuffer helpers
To re-use some of these wordy types outside of LibIPC, let's add some
aliases.
2025-07-18 10:09:02 -04:00
Jelle Raaijmakers
8dd259b8d8 LibWeb: Stub CSSCounterStyleRule
Just the interface. Adds 6 new WPT subtest passes.
2025-07-18 11:51:41 +01:00
norbiros
7ad01d28a8 LibWeb/CSS: Add basic registered properties with initial values
Add global registry for registered properties and partial support
for `@property` rule. Enables registering properties with initial
values. Also adds basic retrieval via `var()`.

Note: This is not a complete `@property` implementation.
2025-07-18 11:12:39 +01:00