Commit graph

73126 commits

Author SHA1 Message Date
Callum Law
0595d52be2 LibWeb: Simplify handling of {text,box}-shadow
We know that shadow values are always parsed as a `KeywordStyleValue`
with `Keyword::None` or a `StyleValueList`
2025-12-01 10:16:41 +00:00
Callum Law
4c4fa5c9cd LibWeb: Simplify expansion of background-position shorthand
We know that this is always a `StyleValueList`
2025-12-01 10:16:41 +00:00
Callum Law
40596d5b99 LibWeb: Simplify getting resolved value for animation-duration
We now know that `animation_duration_computed_value` is always a
StyleValueList
2025-12-01 10:16:41 +00:00
Callum Law
e937f5db57 LibWeb: Always parse comma separated value lists as StyleValueList
Previously we would either parse these as `StyleValueList<T>` or `T`
depending on whether or not there was more than one value, this meant we
always had to handle both cases anywhere we used these values.
2025-12-01 10:16:41 +00:00
Callum Law
1a5933cb04 LibWeb: Fail less when multiple mask images are defined
We don't yet support multiple images but we at least continue to use the
first rather than having none
2025-12-01 10:16:41 +00:00
Callum Law
5371862d11 LibWeb: Use correct play state for handling animations on display change
Previously we were doing a couple things wrong:
 - Using the cascaded rather than computed value (so we didn't support
   CSS-wide keywords)
 - Only supporting the case where we had one animation-play-state
2025-12-01 10:16:41 +00:00
Callum Law
1af0364cfc LibWeb: Store last_css_animation_play_state on anim instead of effect
Since it is the animation rather than the effect which has a play state
it makes more sense to store it here
2025-12-01 10:16:41 +00:00
Tete17
6a95506bb1 LibWeb: Update Dom spec now that TrustedTypes integration is merged 2025-12-01 09:54:04 +01:00
Tete17
42284f8006 LibWeb: Modify DomParser parseFromString to accept TrustedHTML
We made the internal changes to accept this new type, but we forgot to
expose it.
2025-12-01 09:54:04 +01:00
Tete17
901afee50b LibWeb: Implement slot validation for HTMLScriptElement
This should be the last section missing in the TrustedType spec.
2025-12-01 09:54:04 +01:00
Tete17
1d1182cad8 LibWeb: Update get_trusted_type_data_for_attribute according to the spec
It now takes into consideration the namespace of the element to decide
if it needs a TrustedType or not.

We also win a few WPT subtests :)
2025-12-01 09:54:04 +01:00
Tete17
d601badd6c LibWeb: Fix east constness 2025-12-01 09:54:04 +01:00
Tete17
7ec9779624 LibWeb: Update links to algorithms
The spec doesn't consider them abstract operations anymore
2025-12-01 09:54:04 +01:00
Rocco Corsi
11dc254d27 LibJS: Add missing internal object string printing for debugging
When testing with JS_BYTECODE_DEBUG macro defined or using the All_Debug
profile, internal objects were not known in Value class to the function
Value::to_string_without_side_effects leading to a VERIFICATION FAILED
when running the test-js or test-web programs.

Internal objects are known in the Value class as cells, and do not have
a dedicated tag to identify them. Internal objects are detected using
is_cell function call, but only after all other types have been
checked as other types of non-internal objects can also be cells.

Both the String and Utf16String version of the function were updated.
2025-11-30 19:22:46 +01:00
Lorenz A
7260159b8f LibWeb: Add loading event to style element 2025-11-30 19:22:02 +01:00
InvalidUsernameException
ce2c4a3417 LibGfx+LibWeb: Fix compile errors in clang-cl from recent header cleanup
The recent commits 28ba610f32 and
70c4ed261f adjusted some include
directives to avoid excessive recompilation when changing some header
files. This has broken compilation with clang-cl on Windows without
getting noticed before the PRs were merged.
2025-11-30 08:45:29 -05:00
Luke Wilde
0eceee0a05 LibJS: Replace Array.fromAsync with a native JavaScript implementation
This allows us to use the bytecode implementation of await, which
correctly suspends execution contexts and handles completion
injections.

This gains us 4 test262 tests around mutating Array.fromAsync's
iterable whilst it's suspended as well.

This is also one step towards removing spin_until, which the
non-bytecode implementation of await uses.

```
Duration:
     -5.98s

Summary:
    Diff Tests:
        +4 ✅    -4 ❌

Diff Tests:
    [...]/Array/fromAsync/asyncitems-array-add-to-singleton.js ❌ -> ✅
    [...]/Array/fromAsync/asyncitems-array-add.js              ❌ -> ✅
    [...]/Array/fromAsync/asyncitems-array-mutate.js           ❌ -> ✅
    [...]/Array/fromAsync/asyncitems-array-remove.js           ❌ -> ✅
```
2025-11-30 11:54:54 +01:00
Luke Wilde
a63b0cfaba LibJS: Introduce NativeJavaScriptBackedFunction
This hosts the ability to compile and run JavaScript to implement
native functions. This is particularly useful for any native function
that is not a normal function, for example async functions such as
Array.fromAsync, which require yielding.

These functions are not allowed to observe anything from outside their
environment. Any global identifiers will instead be assumed to be a
reference to an abstract operation or a constant. The generator will
inject the appropriate bytecode if the name of the global identifier
matches a known name. Anything else will cause a code generation error.
2025-11-30 11:54:54 +01:00
Luke Wilde
899c6ebffc LibJS: Make stored realm in NativeFunction non-null
We now always have a realm for NativeFunction, which allows removing an
old hack in internal_call and internal_construct.
2025-11-30 11:54:54 +01:00
Luke Wilde
354888640d LibJS/Bytecode: Make compilation use SharedFunctionInstanceData instead
All the data we need for compilation is in SharedFunctionInstanceData,
so we shouldn't depend on ECMAScriptFunctionObject.

Allows NativeJavaScriptBackedFunction to compile bytecode.
2025-11-30 11:54:54 +01:00
Luke Wilde
2d15326f5d LibJS: Moved SharedFunctionInstanceData into separate files
This will allow it to be reused by NativeJavaScriptBackedFunction.
2025-11-30 11:54:54 +01:00
Tim Ledbetter
166c8b116f LibJS: Avoid cast to out-of-range value in MathObject::abs() fast path 2025-11-30 11:54:02 +01:00
Andreas Kling
2d6bc21a33 LibJS: Show label names & targets in bytecode instruction serialization 2025-11-30 11:53:56 +01:00
Andreas Kling
702977373c LibJS: Some Bytecode.def fixes
- Add missing @nothrow to a bunch of instructions.
- Rename fields that were colliding between base and derived class.
2025-11-30 11:53:56 +01:00
Andreas Kling
2d76e21cfd LibJS: Don't use GC::Root unnecessarily in Error stack traces
This was causing a fair bit of root registration churn on pages that
throw lots of errors.

Since there's no need for these pointers to float around freely, we can
just visit them during the mark phase as usual.
2025-11-30 11:53:56 +01:00
Sam Atkins
6ca69d9e26 LibWeb/Layout: Spec-comment Table "algorithm for processing rows"
Some of this is rearranged for clarity, but it's mostly the exact same
code. Steps 3, 10, 11, and 15 are new, but don't have any effect until
we implement downward-growing cells.
2025-11-30 11:48:14 +01:00
Sam Atkins
2af63149ec LibWeb/HTML: Resolve/reject apiMethodTracker before dispatching events
Corresponds to:
93634aed57

The current live spec has been rearranged since this went in, so that
these steps are no longer located here. But that's a much larger change
that I don't want to implement right now. See here:
e09d10202d

While I was at it, I also made use of extract_error_information() to
populate the ErrorEvent.
2025-11-30 11:47:10 +01:00
Sam Atkins
c1e4024eca LibWeb/HTML: Split out "abort a NavigateEvent" method
I missed where this change happened in the spec. The second half of
abort_the_ongoing_navigation() becomes a separate method, which is
slightly rearranged. I've placed this in Navigation instead of
NavigateEvent because of how many steps poke at the Navigation's
internals.

The text here includes the amendments I made in
https://github.com/whatwg/html/pull/11967 to correct a variable name.

A bonus is that we now actually populate the ErrorEvent instead of
leaving it blank.
2025-11-30 11:47:10 +01:00
Sam Atkins
218e646e72 LibWeb/HTML: Extract ErrorInformation struct into its own files
This is used from a few different places in the spec.
2025-11-30 11:47:10 +01:00
Andreas Kling
c1c24e8fd6 LibJS: Use non-copying GetUint8ArrayBytes() in Uint8Array.toBase64()
If the ArrayBuffer we're looking at is non-shared, we can simply get a
view onto the underlying bytes and pass that to the Base64 encoder.
2025-11-29 09:39:43 -05:00
Andreas Kling
124b4fc06a LibJS: Limit the length of strings we put in the VM string cache
For excessively long strings, we often end up spending a ton of time
hashing and comparing them, and it basically ruins the value of the
cache as optimization.

This commit puts a cap (256) on the length of strings we put into the
cache. The number is arbitrary and there may be value in tuning it.
2025-11-29 09:39:43 -05:00
Andreas Kling
b6ef80ff36 LibJS: Avoid options object allocation in fromBase64() and toBase64()
When no options (or undefined) are passed into these APIs, the spec has
us synthesize a temporary "options object" to read the options from.

We don't actually need these objects, so let's sidestep the allocation
if we can (and just use the default values in that case).
2025-11-29 09:39:43 -05:00
Andreas Kling
b2761b5640 LibJS: Avoid redundant ByteBuffer in Uint8Array.fromBase64()
Since we already have a ByteBuffer from decoding the Base64 data, we can
pass that when creating a new ArrayBuffer.

This avoids a buffer allocation + memory clear + memory copy.
2025-11-29 09:39:43 -05:00
Andreas Kling
c9c98a150d AK: Avoid temporary Vector<u8> when encoding Base64
Instead, decode directly into an uninitialized StringData object.
This avoids the redundant vector allocation + memory copy.
2025-11-29 09:39:43 -05:00
Timothy Flynn
2453f0bc04 LibHTTP+LibWeb: Use LibHTTP's cache implementation in LibWeb
There are a couple of remaining RFC 9111 methods in LibWeb's Fetch, but
these are currently directly tied to the way we store GC-allocated HTTP
response objects. So de-coupling that is left as a future exercise.
2025-11-29 08:35:02 -05:00
Timothy Flynn
21bbbacd07 LibHTTP+RequestServer: Move the HTTP cache implementation to LibHTTP
We currently have two ongoing implementations of RFC 9111, HTTP caching.
In order to consolidate these, this patch moves the implementation from
RequestServer to LibHTTP for re-use within LibWeb.
2025-11-29 08:35:02 -05:00
InvalidUsernameException
1f8a42c367 LibGfx: Add a test for bitmap export
The verified pixel output in this test just reflects currently observed
behavior, I have not verified that all cases output the correct data wrt
what the spec expects.
2025-11-28 18:32:48 +01:00
InvalidUsernameException
a81e407c44 LibWeb: Do not crash when converting a bitmap to RGB888
This makes it so that we can visit satellite and hybrid view on
maps.apple.com. Previously this would crash from a bounds check due to
us asking Skia to write 32bpp RGBx8888 data into a buffer sized for
24bpp RGB888.
2025-11-28 18:32:48 +01:00
InvalidUsernameException
9e60dc57b4 LibGfx: Add FIXME about potentially incorrect alpha handling 2025-11-28 18:32:48 +01:00
InvalidUsernameException
6847185d9a LibGfx: Mask alpha values when setting pixels on non-alpha bitmaps
This is not technically necessary, presumably the bitmap type does not
offer any guarantees about what values are stored in the alpha component
for non-alpha pixel formats.

But the previous behavior meant that `set_pixel()` would produce
different values in the alpha component depending on whether the bitmap
format was RGBx or BGRx (i.e. `color.alpha()` vs. 0x00), which can be a
bit confusing.
2025-11-28 18:32:48 +01:00
InvalidUsernameException
88c4814de6 LibGfx+LibWeb: Extract bitmap-to-buffer conversion into LibGfx
This factors the conversion logic to be independent from WebGL code,
allowing us to write unit tests for it that can run in CI (since WebGL
can't run in CI).
2025-11-28 18:32:48 +01:00
InvalidUsernameException
fa181c2be8 LibGfx: Do not over-promise what type gets returned 2025-11-28 18:32:48 +01:00
InvalidUsernameException
7c315ef67f Everywhere: Unify naming of RGBA-like colors
The `Bitmap` type was referring to to its internal pixel format by a
name that represents the order of the color components as they are layed
out in memory. Contrary, the `Color` type was using a naming that where
the name represents the order of the components from most to least
significant byte when viewed as a unsigned 32bit integer. This is
confusing as you have to keep remembering which mental model to use
depending on which code you work with.

To unify the two, the naming of RGBA-like colors in the `Color` type has
been adjusted to match the one from the Bitmap type. This seems to be
generally in line with how web APIs think about these types:
* `ImageData.pixelFormat` can be `rgba-8unorm` backed by a
  `Uint8ClamedArray`, but there is no pixel format backed by a 32bit
  unsigned type.
* WebGL can use format `RGBA` with type `UNSIGNED_BYTE`, but there is no
  such format with type `UNSIGNED_INT`.

Additionally, it appears that other browsers and browser-adjacent
libraries also think similarly about these types:
* Firefox:
  https://github.com/mozilla-firefox/firefox/blob/main/gfx/2d/Types.h
* WebKit:
  https://github.com/WebKit/WebKit/blob/main/Source/WebCore/platform/graphics/PixelFormat.h
* Skia:
  https://chromium.googlesource.com/skia/+/refs/heads/main/include/core/SkColorType.h

This has the not so nice side effect that APIs that interact with these
types through 32bit unsigned integers now have the component order
inverted due to little-endian byte order. E.g. specifying a color as hex
constant needs to be done as `0xAABBGGRR` if it is to be treated as
RGBA8888.

We could alleviate this by providing endian-independent APIs to callers.
But I suspect long-term we might want to think differently about bitmap
data anyway, e.g. to better support HDR in the future. However, such
changes would be more involved than just unifying the naming as done
here. So I considered that out of scope for now.
2025-11-28 18:32:48 +01:00
InvalidUsernameException
07f61f2cec LibGfx: Remove redundant enum
With the templatized overload of set_pixel() gone, there is no reason to
have two separate enums anymore.
2025-11-28 18:32:48 +01:00
InvalidUsernameException
645052b87e LibGfx: Remove some unused function overloads 2025-11-28 18:32:48 +01:00
InvalidUsernameException
28ba610f32 Everywhere: Avoid large rebuilds when editing (Immutable)Bitmap headers
This reduces the number of recompiled files as follow:
- Bitmap.h: 1309 -> 101
- ImmutableBitmap.h: 1218 -> 75
2025-11-28 18:32:48 +01:00
InvalidUsernameException
40f089a043 LibGfx: Sort source files alphabetically 2025-11-28 18:32:48 +01:00
Callum Law
63538c8a75 LibWeb: Prefer transitioned property values over important
CSS transitions have a higher precedence in the cascade than important
properties
2025-11-28 16:15:49 +00:00
Callum Law
9afb523be3 LibWeb: Remove unnecessary parse_list_of_time_values function
We can achieve the same thing by using
`parse_simple_comma_separated_value_list`
2025-11-28 16:15:49 +00:00
Callum Law
b0ab94c00c LibWeb: Allow multiple values for transition-behavior 2025-11-28 16:15:49 +00:00