Commit graph

70909 commits

Author SHA1 Message Date
Ali Mohammad Pur
cadc3f85a6 Tests: Run all Vector tests for FastLastAccess::Yes too 2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
8af095f797 LibWasm: Make Wasm::Validator::Stack hold a Vector instead of inheriting 2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
b97ad99014 LibWasm: Remove unnecessary C-style casts
Or replace them with static-cast when necessary.
2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
1ef536194d LibWeb/WebAssembly: Avoid scanning all externs when resolving references
This was very hot on a profile of ruffle.
2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
33cd5ae08c LibWasm: Fuse some very common instruction combos into specialised ops
Largely combinations of i32.const and local.get.
This shaves off at most single-digit% number of instructions from
dispatch, which translates to at most ~10% reduced dispatch time.

Across most benchmarks, this gains around ~5% perf increase.
2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
0e5ecef848 LibWasm: Try really hard to avoid touching the value stack
This commit adds a register allocator, with 8 available "register"
slots.
In testing with various random blobs, this moves anywhere from 30% to
74% of value accesses into predefined slots, and is about a ~20% perf
increase end-to-end.

To actually make this usable, a few structural changes were also made:
- we no longer do one instruction per interpret call
- trapping is an (unlikely) exit condition
- the label and frame stacks are replaced with linked lists with a huge
  node cache size, as we only need to touch the last element and
  push/pop is very frequent.
2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
998454028c LibWasm+wasm: Remove the debug interpreter
This is largely unused (only in wasm.cpp)
A future reimplementation can bring it back as a separate interpreter
class that embeds the current bytecode interpreter.
2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
4e2845847b LibJS: Add a fast-path to <Int32>.to_uint8()
This was showing up in a profile as hot.
2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
e47fceed38 AK: Optionally keep track of the last slot in Vector
last() and take_last() are extremely common ops when the vector is used
like a stack.
2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
2cd4b4e28d AK: Skip vcalls to Stream::read_value and read_until_filled in LEB128
...for the first byte.
This function only really needs to read a single byte at that point, so
read_until_filled() is useless and read_value<u8> is functionally
equivalent to just a read.

This showed up hot in a wasm parse benchmark.
2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
931b554f68 LibWasm: Give some inline capacity to the frame and label stacks
The average wasm function rarely goes over these bounds for the labels
(32 nested control structures), and 8 frames is just enough to clear
most initialization code/start section without allocating anything.
2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
bf4c436ef3 AK: Add some higher-level operations to DoublyLinkedList<T>
This also adds a node cache as allocation/deallocation was showing up in
my profiles; disabled by default to keep the old behaviour.
2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
dc67f0ad4e LibWasm: Hold on to the stack depth for expressions in the validator
This allows preallocating the value stack when pushing frames, avoiding
repeated reallocs and copies.
2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
3f77aa8521 LibWasm: Try to avoid vcalls on very busy stream read functions
This was a bottleneck when parsing, in general.
2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
834fb0be36 AK: Make some Stream::read* functions available inline
These are quite bottlenecky in wasm, the next commit will try to make
use of this by calling them directly instead of doing a vcall, and
having them inlineable helps the compiler a bit.
2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
bd7c188b86 LibWasm: Avoid memory copy in read_value<T>() if possible
If the address is already aligned properly, just read a T from it;
otherwise copy it to a local aligned array. This was a bottleneck on
memory-heavy benchmarks.
2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
5c6f223f48 LibWasm: Avoid repeated shrinkage of value stack 2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
0f13952f30 AK: Simplify some stream reading logic
These do the same thing in a less convoluted way. NFC.
2025-08-08 12:54:06 +02:00
Callum Law
e260ba54e0 LibWeb: Propagate NaN in CSS clamp function
Gains us 10 WPT tests.
2025-08-08 11:43:49 +01:00
Callum Law
4ba54a7a1c LibWeb: Handle NaN and Infinite values in CSS round function
Gains us 10 WPT tests
2025-08-08 11:43:49 +01:00
Callum Law
376b992f0e LibWeb: Handle NaN within CSS min and max functions
Gains us 10 WPT tests
2025-08-08 11:43:49 +01:00
Callum Law
9e1ace28a6 LibWeb: Import WPT tests related to handling non-finite values in calcs 2025-08-08 11:43:49 +01:00
Kenneth Myhra
1b350596fb LibWeb: Align Fetching chapter's "To fetch" with latest spec changes 2025-08-08 11:12:53 +01:00
Kenneth Myhra
593ee1ae0a LibWeb: Implement AO populate request from client 2025-08-08 11:12:53 +01:00
Kenneth Myhra
70cafc558e LibWeb: Replace request's "window" with "traversable for user prompts"
User prompts are not tied to specific Windows or the client's Window.
They are tied to a traversable navigable (browser tab).
2025-08-08 11:12:53 +01:00
Kenneth Myhra
681e4e5d01 LibWeb: Define stream variable before using it
This is an editoral change from the fetch spec. Since we already defined
the stream before it being used this only re-numbers the spec steps.

It also corrects a minor typo ('followings' to 'following') which was
corrected in the same editoral spec change.
2025-08-08 11:12:53 +01:00
Callum Law
a1037e28d6 LibWeb: Improve support for CalculatedStyleValue in scale
Some checks are pending
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / macOS, arm64, Sanitizer, 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
- Properly serialize CalculatedStyleValue components
- Allow CSV to be the 'Z' component in interpolated value

Gains us 52 WPT tests
2025-08-08 09:45:00 +01:00
Callum Law
39fdcbc526 LibWeb: Improve support for CalculatedStyleValue in translate
- Omit calcs that are resolved to `0px` from the serialized value
- Allow CSV to be the 'Z' component in interpolated value.
- Allow calcs with mixed percentages in the first two arguments.

To achieve the third item above the concept of a "special" value parsing
context has been added - this will also be useful for instance for
different arguments of color functions having different contexts.

Gains us 23 WPT tests
2025-08-08 09:45:00 +01:00
Callum Law
18d65b014f LibWeb: Add formatter for Web::CSS::ValueType
Currently unused but I found it useful for debugging
2025-08-08 09:45:00 +01:00
Callum Law
9bfd46ce31 LibWeb: Add formatter for Web::CSS::CSSStyleValue::Type
Currently unused but I found it useful for debugging
2025-08-08 09:45:00 +01:00
Callum Law
56b6987fd0 LibWeb: Use a macro for repetitive code in CSSStyleValue.{h,cpp}
This reduces the number of places we need to touch when creating a new
type
2025-08-08 09:45:00 +01:00
Edwin Hoksberg
ef9a3a2327 LibWeb: Import serial idl harness wpt tests 2025-08-08 10:23:17 +02:00
Edwin Hoksberg
1be31c103f LibWeb: Stub WebSerial API 2025-08-08 10:23:17 +02:00
Andreas Kling
34ec33d71c LibWeb: Don't treat SVG "use clone" removals as "use source" removals
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
We were failing to discriminate between DOM removals happening to SVG
elements cloned as part of an SVG use element instantiation.

When a "use source" element is removed, all clones of that source must
be updated to reflect the change. But when a "use clone" element is
removed, that's fine.

This was causing the surprising disappearance of use element subtrees,
seen for example on https://cal.com/
2025-08-07 22:15:36 +02:00
Andreas Kling
42802b0785 LibWeb: SVG use element shadow roots should be closed, not open
This goes against the spec but matches all other browser engines.
2025-08-07 22:15:36 +02:00
Andreas Kling
1402c143a9 LibWeb: Add Internals.getShadowRoot(element)
This lets you access closed shadow roots from JavaScript, even though
they're not normally accessible to JavaScript. This can be used to poke
into UA shadow roots in tests.
2025-08-07 22:15:36 +02:00
Luke Wilde
59162342e6 LibWeb: Set LinkProcessingOptions' cryptographic_nonce_metadata
Fixes external CSS being blocked on https://beatsaver.com/, where they
have a `style-src` directive set to `'self' 'nonce-[value]'`

Relates to #5643, but does not make the website load.
2025-08-07 19:26:57 +02:00
Luke Wilde
1d57df6e26 LibWeb/CSP: Implement the sandbox directive 2025-08-07 19:24:39 +02:00
Luke Wilde
40bb50ac60 LibWeb: Parse and propagate the iframe sandbox attribute 2025-08-07 19:24:39 +02:00
Luke Wilde
a5e2fd2e12 LibWeb/CSP: Implement the webrtc directive 2025-08-07 19:24:39 +02:00
Luke Wilde
855e17529c LibWeb/CSP: Implement the report-to directive
This doesn't do anything by itself, the report a violation algorithm
will handle this directive itself.
2025-08-07 19:24:39 +02:00
Luke Wilde
ed0230bb93 LibWeb/CSP: Implement the report-uri directive
This doesn't do anything by itself, the report a violation algorithm
will handle this directive itself.
2025-08-07 19:24:39 +02:00
Jelle Raaijmakers
85ad99b98a LibWeb: Implement <feMerge> SVG filter
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-08-07 16:41:12 +02:00
Jelle Raaijmakers
1377dba7af LibWeb: Implement <feOffset> SVG filter 2025-08-07 16:41:12 +02:00
Sam Atkins
89b59cb5c3 LibWeb/CSS: Implement env() as an arbitrary substitution function
Technically, env() should not be an ASF. (😱) This is why some tests
still fail - env() as specced is expected to have its syntax checked
fully at parse-time, whereas ASFs are not properly syntax-checked until
later. However, I think this approach was worth doing for a few reasons:

- env() behaves like an ASF otherwise. (It is replaced with a set of
  arbitrary component-values that are not known until computed-value
  time.)
- env() was defined before the ASF concept existed, so I strongly
  suspect it will be updated in the future to match that definition,
  with a couple of adjustments. (eg, env() is allowed in some extra
  places compared to var() and attr().)
- This was much quicker and easier to implement (under 3 hours in total)
  compared to the greater amount of work to implement a whole separate
  system just for env().
- Most of these tests are marked tentative, and the spec definition of
  env() is still somewhat in flux, so failing some is not a huge deal.

If in the future I turn out to be wrong on this, we can convert it to
its own special thing.
2025-08-07 16:38:29 +02:00
Sam Atkins
22e00451b9 LibWeb/DOM: Add ability to query Document for environment variables
Currently this returns them in ComponentValue form, as that's what's
needed by env().
2025-08-07 16:38:29 +02:00
Sam Atkins
7b30c94fcf LibWeb+CodeGenerators: Generate EnvironmentVariable enum and functions 2025-08-07 16:38:29 +02:00
Sam Atkins
b03e829a49 Tests: Import WPT tests for CSS env() 2025-08-07 16:38:29 +02:00
Sam Atkins
5808eff1f4 LibWeb/CSS: Hyphenate request-url-modifier names
Corresponds to e1bf92d49a

Also update our imported WPT tests.
2025-08-07 13:38:25 +01:00
Sam Atkins
24f4356c3f LibWeb/CSS: Specify behavior for OOB CSSStyleDeclaration::item()
Corresponds to 56ed462ccd

We already did the right thing.
2025-08-07 14:29:17 +02:00