Commit graph

983 commits

Author SHA1 Message Date
Sam Atkins
08bf9d39de LibWeb/CSS: Add String->ValueType conversion function
And also move this out of PropertyID.h because it's a separate thing.

I considered generating this but there's really not much to it.
2025-07-16 14:47:45 +01:00
Sam Atkins
0c66adfa1a LibWeb/CSS: Check Enums.json for what type names are enums
The hard-coded list here is fragile. We can just look at the Enums file
to see what our actual enum names are, instead.
2025-07-16 14:47:45 +01:00
Callum Law
05e2e398bd LibWeb: Add method to get logical property group for PropertyID 2025-07-16 11:16:49 +01:00
Callum Law
9ed85ddd63 LibWeb: Mark relevant properties as "positional-value-list-shorthands"
Some shorthand properties work differently to normal in that mapping of
provided values to longhands isn't necessarily 1-to-1 and depends on the
number of values provided, for example `margin`, `border-width`, `gap`,
etc.

These properties have distinct behaviors in how they are parsed and
serialized, having them marked allows us to implement theses behaviors
in a generic way.

No functionality changes.
2025-07-15 14:26:02 +01:00
Luke Wilde
d08d6b08d3 LibWeb: Use enum for serialization and reimplement interface exposure
Our currently implementation of structured serialization has a design
flaw, where if the serialized/transferred type was not used in the
destination realm, it would not be seen as exposed and thus we would
not re-create the type on the other side.

This is very common, for example, transferring a MessagePort to a just
inserted iframe, or the just inserted iframe transferring a MessagePort
to it's parent. This is what Google reCAPTCHA does.

This flaw occurred due to relying on lazily populated HashMaps of
constructors, namespaces and interfaces. This commit changes it so that
per-type "is exposed" implementations are generated.

Since it no longer relies on interface name strings, this commit
changes serializable types to indicate their type with an enum,
in line with how transferrable types indicate their type.

This makes Google reCAPTCHA work on https://www.google.com/recaptcha/api2/demo
It currently doesn't work on non-Google origins due to a separate
same-origin policy bug.
2025-07-15 09:20:02 -04:00
Luke Wilde
cb1c388ee3 Generators/Interfaces: Refactor separate interface Vectors into a struct 2025-07-15 09:20:02 -04:00
Shannon Booth
9054ff29f0 LibWeb/CSS: Parse the ::slotted pseudo-element 2025-07-15 13:54:17 +01:00
Ryan Liptak
6da1dfa8f2 LibWeb/HTML: Improve data structure of named character reference data
Introduces a few ad-hoc modifications to the DAFSA aimed to increase
performance while keeping the data size small.

- The 'first layer' of nodes is extracted out and replaced with a lookup
  table. This turns the search for the first character from O(n) to O
  (1), and doesn't increase the data size because all first characters
  in the set of named character references have the
  values 'a'-'z'/'A'-'Z', so a lookup array of exactly 52 elements can
  be used. The lookup table stores the cumulative "number" fields that
  would be calculated by a linear scan that matches a given node, thus
  allowing the unique index to be built-up as normal with a O(1) search
  instead of a linear scan.
- The 'second layer' of nodes is also extracted out and searches of the
  second layer are done using a bit field of 52 bits (the set bits of
  the bit field depend on the first character's value), where each set
  bit corresponds to one of 'a'-'z'/'A'-'Z' (similar to the first
  layer, the second layer can only contain ASCII alphabetic
  characters). The bit field is then re-used (along with an offset) to
  get the index into the array of second layer nodes. This technique
  ultimately allows for storing the minimum number of nodes in the
  second layer, and therefore only increasing the size of the data by
  the size of the 'first to second layer link' info which is 52 * 8 =
  416 bytes.
- After the second layer, the rest of the data is stored using a
  mostly-normal DAFSA, but there are still a few differences:
   - The "number" field is cumulative, in the same way that the
     first/second layer store a cumulative "number" field. This cuts
     down slightly on the amount of work done during the search of a
     list of children, and we can get away with it because the
     cumulative "number" fields of the remaining nodes in the DAFSA
     (after the first and second layer nodes were extracted out) happens
     to require few enough bits that we can store the cumulative version
     while staying under our 32-bit budget.
   - Instead of storing a 'last sibling' flag to denote the end of a
     list of children, the length of each node's list of children is
     stored. Again, this is mostly done just because there are enough
     bits available to do so while keeping the DAFSA node within 32
     bits.
   - Note: Together, these modifications open up the possibility of
     using a binary search instead of a linear search over the
     children, but due to the consistently small lengths of the lists
     of children in the remaining DAFSA, a linear search actually seems
     to be the better option.

The new data size is 24,724 bytes, up from 24,412 bytes (+312, -104 from
the 52 first layer nodes going from 4-bytes to 2-bytes, and +416 from
the addition of the 'first to second layer link' data).

In terms of raw matching speed (outside the context of the tokenizer),
this provides about a 1.72x speedup.

In very named-character-reference-heavy tokenizer benchmarks, this
provides about a 1.05x speedup (the effect of named character reference
matching speed is diluted when benchmarking the tokenizer).

Additionally, fixes the size of the named character reference data when
targeting Windows.
2025-07-14 09:43:08 +02:00
Callum Law
7cc718f1c1 LibWeb: Avoid vector creation getting {short,long}hands for CSS property
The `shorthands_for_longhand`, `longhands_for_shorthand`, and
`expanded_longhands_for_shorthand` methods can be pretty hot in
profiles where we serialize a lot of CSS properties.

By returning a const reference to a static vector instead of allocating
and returning a new vector every time we can avoid a decent amount of
work.

Overall runtime for the particularly serialization heavy
wpt.live/css/cssom/cssom-getPropertyValue-common-checks.html
decreased by ~20% comparing before and after this change.
2025-07-14 09:08:55 +02:00
Sam Atkins
1ff1093a24 LibWeb: Define a PropertyIDOrCustomPropertyName type
We often want to identify a property, but if we have a PropertyID we
don't want to have to convert it to a string to then convert it back
again. However, custom properties don't have a useful PropertyID. So,
here's a type with a verbose name.
2025-07-09 16:44:20 +01:00
Sam Atkins
69d4811ef7 LibWeb: Generate logical property mappings
To support this, how we declare logical property aliases has changed.
Instead of `logical-alias-for` being a list of properties, it's now an
object with a `group` and `mapping`. The group is the name of a logical
property group in LogicalPropertyGroups.json. The mapping is which
side/dimension/corner this property is. Hopefully it's self-explanatory
enough.

The generated code is very much a copy of what was previously in
`StyleComputer::map_logical_alias_to_physical_property_id()`, so there
should be no behaviour change.
2025-07-08 11:45:15 -06:00
Jelle Raaijmakers
ead0a2c78a Everywhere: Rename serenity_main to ladybird_main
No functional changes.
2025-07-08 09:17:16 -04:00
Sam Atkins
e63d81b36e LibWeb: Add CustomStateSet IDL type 2025-07-04 18:10:28 +01:00
Sam Atkins
bc94431b99 IDLGenerators: Add a callback for when a setlike's set is modified
For simplicity, this requires that the setlike Foo class has a
`void on_set_modified_from_js(Badge<Bindings::FooPrototype>)` method.

This will be called after the set is modified from a generated `add()`,
`delete()`, or `clear()` method.
2025-07-04 18:10:28 +01:00
Sam Atkins
be21d952b1 IDLGenerators: Generate impl_from() for types that have setlike
Found by this interface, which has nothing else in it:

```
[Exposed=Window]
interface CustomStateSet {
  setlike<DOMString>;
};
```
2025-07-04 18:10:28 +01:00
Sam Atkins
efcbec250f IDLGenerators: Support string types in setlike 2025-07-04 18:10:28 +01:00
Sam Atkins
0f859fd126 IDLGenerators: Remove redundant function forward declaration 2025-07-04 18:10:28 +01:00
Sam Atkins
9e1bbe7edd IDLGenerators: Correct the parameter type check for setlike methods 2025-07-04 18:10:28 +01:00
Sam Atkins
f2dd66e039 IDLGenerators: Remove unused numeric_type definition 2025-07-04 18:10:28 +01:00
Tim Ledbetter
cb4a5eca2e Meta: Add formatter to PropertyID code generator 2025-07-03 21:17:16 +01:00
Tim Ledbetter
c0390f759c LibWeb: Parse the border-image-repeat property 2025-07-03 10:19:44 +01:00
Tim Ledbetter
98e63e3dd5 LibWeb: Parse the border-image-outset property 2025-07-03 10:19:44 +01:00
Tim Ledbetter
245905b833 LibWeb: Parse the border-image-slice property 2025-07-03 10:19:44 +01:00
Tim Ledbetter
70c2621634 LibWeb: Parse the border-image-source property 2025-07-03 10:19:44 +01:00
Luke Wilde
e85b809f8d LibWeb+Meta: Move WebGL rendering context implementations in tree
This copies the latest generated code in tree and then removes code
generation for the WebGL rendering contexts. This is because it didn't
add much value, and we can maintain the generated output instead of
both that and the generator itself.
2025-07-02 19:00:49 +02:00
Luke Wilde
454bf0b7cd LibWeb/WebGL: Use robust versions of API calls provided by ANGLE
The primary purpose of these is to add bounds checking to older OpenGL
API calls that take arbitrarily sized buffers, but don't know the size
of the buffer and thus rely on the application being certain the buffer
is large enough.

Since these API calls are exposed to arbitrary JS which can make
arbitrarily sized buffers, it is not safe to use the non-robust
variants, as we cannot know the size of the buffer ahead of time, nor
the amount of data required by the API call.

The robust variants provided by ANGLE adds a buffer size parameter,
where it'll calculate the amount of data it needs for that API call
for us and return an error if it's bigger than the given buffer size.

Credit to https://github.com/s41nt0l3xus for finding this during a CTF
and providing a write up that exploits this.
See: 92efbaed6c/gpnctf-2025/WebGL-bird
2025-06-30 11:54:23 -06:00
Bastiaan van der Plaat
1a7932601a IDLGenerators: Fix Exposed extended attribute codegen 2025-06-30 11:39:16 -06:00
Bastiaan van der Plaat
da620d6ccf LibIDL+LibWeb: Move parse_exposure_set from code generator to LibIDL 2025-06-30 11:39:16 -06:00
ayeteadoe
dbba6c0df9 LibWeb: Enable in Windows CI 2025-06-30 10:50:36 -06:00
Totto16
f1a096d6e4 LibWeb: Add OffscreenCanvas to IDL types
Add OffscreenCanvas to TexImageSource and CanvasImageSource.
Implement all the necessary features to make it work in all cases where
these types are used.
2025-06-30 09:46:21 -06:00
Totto16
2ad3ce5d37 LibWeb: Implement basics for OffscreenCanvas
This implements the basic interface, classes and functions for
OffscreenCanvas. Many are still stubbed out and have many FIXMEs in
them, but it is a basic skeleton.
2025-06-30 09:46:21 -06:00
Callum Law
f336667771 LibWeb: Don't carry quirks across to logical aliases 2025-06-23 15:19:07 +01:00
Callum Law
cfc8d3031b LibWeb: Map logical aliases at cascade time
Previously we would incorrectly map these in
`CSSStyleProperties::convert_declarations_to_specified_order`, aside
from being too early (as it meant we didn't maintain them as distinct
from their physical counterparts in CSSStyleProperties), this meant
that we didn't yet have the required context to map them correctly.

We now map them as part of the cascade process. To compute the mapping
context we do a cascade without mapping, and extract the relevant
properties (writing-direction and direction).
2025-06-23 15:19:07 +01:00
Jelle Raaijmakers
22bda8e5e2 LibWeb: Stub Geolocation API
Some checks are pending
CI / macOS, arm64, Sanitizer_CI, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers_CI, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, Clang (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-06-21 10:00:29 +02:00
Jelle Raaijmakers
8f3fe0c39e LibWeb: Support nullable attributes in generated toJSON()
Any optional or nullable attribute will end up in an `if/else` branch
when we collect the attribute values, and this is inherently
incompatibly with an `auto {attr}_wrapped = ...` expression. Define the
variable as an `JS::Value` before generating the wrap statement so we
can properly support `toJSON()` for an attribute like:

  readonly attribute double? altitude;
2025-06-21 10:00:29 +02:00
Sam Atkins
dfce9974b5 LibWeb: Remove GeneratedPseudoElement enum
This doesn't currently provide any value over just using PseudoElement,
and makes it harder to work with PseudoElement in other places.
2025-06-19 12:35:31 +01:00
Callum Law
d31a58a7d6 LibWeb: Add support for the 'all' CSS property
The "longhands" array is populated in the code generator to avoid the
overhead of manually maintaining the list in Properties.json

There is one subtest that still fails in
'cssstyledeclaration-csstext-all-shorthand', this is related to
us not maintaining the relative order of CSS declarations for custom vs
non-custom properties.
2025-06-12 15:25:35 +01:00
Callum Law
048a0c9106 LibWeb: Support nested shorthands when serializing CSS declaration 2025-06-09 10:43:50 +01:00
Aliaksandr Kalenik
7efdd1c1ec LibWeb: Stub CacheStorage interface
With this change we can again open login form https://discord.com/login
instead of failing in js because `caches.open()` is not defined.
2025-06-05 23:02:21 +02:00
Callum Law
50cce72ab9 LibWeb: Implement text-wrap CSS property
This resolves an issue introduced in 94f5a51 with the
tab-size-text-wrap test
2025-06-04 12:48:36 +01:00
Callum Law
9ba74316d2 LibWeb: Implement text-wrap-style CSS property 2025-06-04 12:48:36 +01:00
Callum Law
ed65d5b342 LibWeb: Serialize CSS declarations as shorthands where applicable
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macOS, macos-15, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, Linux, blacksmith-16vcpu-ubuntu-2404, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, Linux, blacksmith-16vcpu-ubuntu-2404, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, Linux, blacksmith-16vcpu-ubuntu-2404, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macOS, macOS-universal2, macos-15) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, Linux, Linux-x86_64, blacksmith-8vcpu-ubuntu-2404) (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
When serializing CSS declarations we now support combining multiple
properties into a single shorthand property in some cases.

This comes with a healthy dose of FIXMEs, including work to be done
around supporting:
 - Nested shorthands (e.g. background, border, etc)
 - Shorthands which aren't represented by the ShorthandStyleValue type
 - Subproperties pending substitution

This gains us a bunch of new test passes, both for WPT and in-tree
2025-05-29 12:04:28 +02:00
Callum Law
9480b1fc5c LibWeb: Parse and propagate white-space-trim CSS property 2025-05-29 12:04:28 +02:00
Callum Law
50bdd2cb85 LibWeb: Parse and propagate text-wrap-mode CSS property 2025-05-29 12:04:28 +02:00
Callum Law
ea30356fba LibWeb: Parse and propagate white-space-collapse CSS property 2025-05-29 12:04:28 +02:00
Sam Atkins
fb975cc156 LibWeb/CSS: Correct how we evaluate boolean media-features
The spec has a general rule for this, which is roughly that "If it's not
a falsey value, it's true". However, a couple of media-features are
always false, apparently breaking this rule. To handle that, we have an
array of false keywords in the JSON, instead of a single keyword. For
those always-false media-features, we can enter all their values into
this array.

Gets us 2 more WPT subtest passes.
2025-05-23 10:17:58 +01:00
Shannon Booth
579730d861 LibWeb: Prefer using equals_ignoring_ascii_case
Which has an optmization if both size of the string being passed
through are FlyStrings, which actually ends up being the case
in some places during selector matching comparing attribute names.
Instead of maintaining more overloads of
Infra::is_ascii_case_insensitive_match, switch
everything over to equals_ignoring_ascii_case instead.
2025-05-21 13:45:02 +01:00
Sam Atkins
6e45d8ba6c LibWeb/CSS: Set enum sizes for PropertyID and Keyword
The effect of this is hard to measure, but reducing them from 4 bytes
each to 2 bytes can't hurt. :^)
2025-05-20 10:14:21 +12:00
Sam Atkins
3add623f22 LibWeb/CSS: Use underlying_type_for_enum() for Enums.json generator
Replacing the duplicate implementation.
2025-05-20 10:14:21 +12:00
Sam Atkins
c4bcbff59a LibWeb/CSS: Set enum sizes for media query types
This reduces `MediaFeature` from 112 to 104 bytes.
2025-05-20 10:14:21 +12:00