Commit graph

795 commits

Author SHA1 Message Date
Shannon Booth
cdb249e058 LibWeb/HTML: Set a fetch client for javascript URL navigations
There is an open spec issue for this, and I'm certainly not sure
what the client should be here, but using the source snapshot
from the global from reading the spec issue seems like a reasonable
enough client for now.

This can be reproduced by performing a javascript URL navigation
with any CSP policy set. For simplicity, simply edit an existing
testcase to add such a policy.

Fixes: #4853
2025-05-23 16:39:13 +02:00
Luke Wilde
e364443e60 LibWeb: Support Content-Security-Policy http-equiv state on meta element 2025-05-23 16:39:13 +02:00
Callum Law
279913a223 LibWeb: Implement the translate attribute 2025-05-23 14:34:06 +02:00
Sam Atkins
00617884a6 LibWeb/CSS: Correct our scan media-feature
Despite what the spec suggests, modern displays are not progressive, and
WPT expects `@media (scan: progressive)` to fail. So, return `none`
here to accurately represent that.

I've left a FIXME in case we can detect the display type from the OS
somehow in the future.

Gets us 4 WPT subtest passes.
2025-05-23 10:17:58 +01:00
Sam Atkins
72f50217b0 LibWeb/CSS: Implement device-aspect-ratio media feature
Gets us 8 WPT passes, and prevents a regression in the following commit.
2025-05-23 10:17:58 +01:00
Timothy Flynn
8b787020a2 LibWeb: Delay the document load event while re-fetching <object> images
We are required to delay the load event while any fetch is ongoing. We
currently have a very hacky re-fetch for images to go through the shared
resource request infrastructure. We must delay the load event during
this re-fetch.

This becomes an issue in an upcoming commit to import the acid2 test.
2025-05-22 17:44:40 -04:00
Timothy Flynn
1bc7a52587 LibWeb: Keep delaying the load event on concurrent <object> tasks
If we queue the <object> representation task multiple times in a row, we
would end up clearing the delayer after the first task completed. We
must continue delaying the load event until the last task completes.

This becomes an issue in an upcoming commit to import the acid2 test.
2025-05-22 17:44:40 -04:00
Gingeh
71222df4c4 LibWeb: Update button activation behaviour to match spec
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, 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
See: https://github.com/whatwg/html/pull/11248
See: https://github.com/whatwg/html/pull/11325
2025-05-22 07:55:34 +01:00
Gingeh
f1eaecc630 LibWeb: Escape "<" and ">" when serializing attribute values
See https://github.com/whatwg/html/pull/6362
2025-05-22 07:55:34 +01:00
Gingeh
fbc56f74bd LibWeb: Move popover invoker reset later
See https://github.com/whatwg/html/pull/11304
2025-05-22 07:55:34 +01:00
Timothy Flynn
9f3526b080 LibWeb: Handle non-OK network responses in <object> elements
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, 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 previously only testing for network errors, which includes e.g.
DNS resolution and connection errors. It does not include e.g. HTTP 404
responses, which is exercised by Acid 2.
2025-05-21 12:13:20 -06:00
Noah
85842c1739 LibWeb: Stub out several methods for ElementInternals
This begins implementation on form-associated custom elements.
This fixes a few WPT tests which I'm importing.

Co-authored-by: Sam Atkins <sam@ladybird.org>
2025-05-21 15:28:10 +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
Timothy Flynn
95fc0a8070 LibWeb: Implement TransformStream transfer 2025-05-21 06:54:44 -04:00
Timothy Flynn
cca08ad833 LibWeb: Implement WritableStream transfer 2025-05-21 06:54:44 -04:00
Timothy Flynn
312db85a84 LibWeb: Implement ReadableStream transfer 2025-05-21 06:54:44 -04:00
Timothy Flynn
ee9d860ba2 LibWeb: Allow creating a MessagePort with a different primary interface
This is needed to transfer streams, which use message ports as the means
of transport.
2025-05-21 06:54:44 -04:00
Timothy Flynn
36da270dbe LibIPC+LibWeb: Flush MessagePort messages before closing
The spec isn't super clear on what disentagling a MessagePort means. But
we are required to send all pending messages before closing the port.

This is a bit tricky because the transport socket performs writes on a
background thread. From the main thread, where the disentanglement will
occur, we don't really know the state of the write thread. So what we do
here is stop the background thread then flush all remaining data from
the main thread.
2025-05-21 06:54:44 -04:00
Timothy Flynn
356727f294 LibWeb: Provide missing includes to StructuredSerializeTypes.h 2025-05-21 06:54:44 -04:00
Andreas Kling
1a055fcb24 LibWeb: Mark canvas element for relayout when width or height changes
While width and height are presentational hints on canvas, they actually
map to the CSS aspect-ratio attribute, not to CSS width and height.
For this reason, we actually need to manually mark for relayout here.

Also import a WPT test that was flaky before this change.
2025-05-19 13:58:05 +02:00
Shannon Booth
14d5c638eb LibWeb/HTML: Use find flattened slots in assignedElements/assignedNodes
This is very awkward, and should be improved, but this improves
our support for slots :^)
2025-05-19 23:26:02 +12:00
Andrew Kaster
4d039fc3d4 LibWeb+WebWorker: Create SharedWorkerGlobalScope for Shared Workers
Also push the onconnect event for the initial connection.

This still doesn't properly handle sending an onconnect event to a
pre-existing SharedWorkerGlobalScope with the same name for the same
origin, but it does give us a lot of WPT passes in the SharedWorker
category.
2025-05-18 17:50:05 -06:00
Andrew Kaster
4af0daf3eb LibWeb: Check actual WorkerGlobalScope subclass to set top level origin
Checking against DedicatedWorkerHost was probably a typo.
2025-05-18 17:50:05 -06:00
Andrew Kaster
62592c19fe LibWeb: Reorganize EmbedderPolicy to shrink the size by 8 bytes 2025-05-18 17:50:05 -06:00
Andrew Kaster
b10a98b0cb LibWeb: Move name attribute to WorkerGlobalScope from subclasses
Also refactor the other properties of WorkerGlobalScope to match the
spec better.
2025-05-18 17:50:05 -06:00
Sam Atkins
eec4365542 LibWeb/CSS: Extract SerializationMode into its own header
Prep for using this to serialize dimension types, and perhaps other
things in the future.
2025-05-17 07:53:24 +01:00
Jelle Raaijmakers
1c77b42a44 LibWeb: Add two FIXMEs about input events' missing .data value
For both `<input>` and `<textarea>` elements, we actually need to
provide the input events with the strings that were added to them.
2025-05-17 00:29:19 +02:00
Jelle Raaijmakers
ac46ec0b2e LibWeb: Start integrating the editing API with user keyboard input
This reworks EventHandler so text insertion, backspace, delete and
return actions are now handled by the Editing API. This was the whole
point of the execCommand spec, to provide an implementation of both
editing commands and the expected editing behavior on user input.

Responsibility of firing the `input` event is moved from EventHandler to
the Editing API, which also gets rid of duplicate events whenever
dealing with `<input>` or `<textarea>` events.

The `beforeinput` event still needs to be fired by `EventHandler`
however, since that is never fired by `execCommand()`.
2025-05-17 00:29:19 +02:00
Tim Ledbetter
2903defcfc Revert "LibJS+LibWeb: Return Vector<PropertyKey> from…
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, 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
internal_own_property_keys"

This reverts commit 5ee810f772.
2025-05-16 06:33:09 +01:00
Sam Atkins
3f18331594 LibWeb/HTML: Do not allow named window targeting with noopener
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, 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
Corresponds to dfdafb4b29

We fail the test for this, but we actually do create the separate popup
windows correctly (when popups aren't blocked!) but the test checks
`window.name` which we incorrectly return the empty string for.
https://wpt.live/html/browsers/windows/auxiliary-browsing-contexts/named-lookup-noopener.html
2025-05-16 10:21:09 +12:00
Sam Atkins
08419a6d8f LibWeb/HTML: Correct show_popover() invocations
Corresponds to 47f854c66e
2025-05-16 10:21:09 +12:00
Sam Atkins
2efad4c941 LibWeb/HTML: Fire load event for non-string javascript: URLs
Corresponds to 8abe559982

The relevant test doesn't pass, so we're probably missing some other
part of this mechanism:
https://wpt.live/html/semantics/embedded-content/the-embed-element/embed-javascript-url.html
2025-05-16 10:21:09 +12:00
Aliaksandr Kalenik
5ee810f772 LibJS+LibWeb: Return Vector<PropertyKey> from internal_own_property_keys
By doing that we avoid lots of `PropertyKey` -> `Value` -> `PropertyKey`
transforms, which are quite expensive because of underlying
`FlyString` -> `PrimitiveString` -> `FlyString` conversions.

10% improvement on MicroBench/object-keys.js
2025-05-15 14:12:18 -04:00
Timothy Flynn
7280ed6312 Meta: Enforce newlines around namespaces
This has come up several times during code review, so let's just enforce
it using a new clang-format 20 option.
2025-05-14 02:01:59 -06:00
mikiubo
89e0896cd7 LibWeb: Implement XML Char validation for Text node serialization
Some checks are pending
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, 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
With this fix, the second test in domparsing/innerhtml-01.xhtml passes.
2025-05-14 18:18:08 +12:00
Glenn Skrzypczak
5c578b6057 LibWeb/HTML: Implement report_validity
Some checks are pending
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, 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 implements the previously stubbed out `report_validity` method.

The specification is not very clear on how to exactly report the
validity. For now, we bring the first visible invalid control into
view and focus it. In the future, however, it would make sense to
support more complex scenarios and be more aligned with the other
implementations.
2025-05-14 09:39:12 +12:00
Aliaksandr Kalenik
bb53485dea LibJS+LibWeb: Add fast path for builtin iterators in iterator_step()
We already have fast path for built-in iterators that skips `next()`
lookup and iteration result object allocation applied for `for..of` and
`for..in` loops. This change extends it to `iterator_step()` to cover
`Array.from()`, `[...arr]` and many other cases.

Makes following function go 2.35x faster on my computer:
```js
(function f() {
  let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
  for (let i = 0; i < 1000000; i++) {
    let [a, ...rest] = arr;
  }
})();
```
2025-05-13 15:14:25 +03:00
Daniel Bertalan
a2167f126d Everywhere: Fix trivial -Wunnecessary-virtual-specifier instances
- `Threading::Thread` is not polymorphic, there is no need for a virtual
  destructor.
- `HTMLAnchorElement::has_download_preference` isn't overridden by
  anything.

This warning was introduced in llvm/llvm-project#131188.
2025-05-12 11:40:45 -06:00
Mikkel Krautz
c48a78e37f LibWeb: Fix copyright headers with inconsistent > characters 2025-05-12 11:21:04 -06:00
InvalidUsernameException
029bcf13fd Libweb: Invalidate layout for the value-attribute of li-elements 2025-05-11 01:14:31 +02:00
InvalidUsernameException
370098514a LibWeb: Invalidate layout for ol-attributes that affect it 2025-05-11 01:14:31 +02:00
Andreas Kling
263b125782 LibWeb: Let HTMLTokenizer walk over code points instead of UTF-8
Instead of using UTF-8 iterators to traverse the HTMLTokenizer input
stream one code point at a time, we now do a one-shot conversion up
front from the input encoding to a Vector<u32> of Unicode code points.

This simplifies the tokenizer logic somewhat, and ends up being faster
as well, so win-win.

1.02x speedup on Speedometer 2.1
2025-05-11 01:13:20 +02:00
Timothy Flynn
30e8f3f1ad LibWeb: Update the <details> layout tree when it is opened/closed
Otherwise, the arrow painted next to the <details> element does not
update.

Using a screenshot test here because apparently the direction of the
arrow has no effect on the layout or paint trees.
2025-05-09 21:37:14 +02:00
Andreas Kling
f61df9d34c LibWeb: Don't throw away UA shadow trees willy-nilly
We were unnecessarily discarding the shadow trees of various elements
when they were removed or detached from the DOM.

This especially caused a *lot* of churn when creating input elements via
setting .innerHTML on something. We ended up building each input
element's shadow tree 3 times instead of 1.

The original issue that we were trying to solve by discarding shadow
trees appears to have been solved elsewhere, and nothing else seems to
break by just allowing them to remain in place.

1.05x speedup on Speedometer's TodoMVC-jQuery.
2025-05-09 12:49:04 -04:00
Kenneth Myhra
6941b63890 LibWeb: Add {,de}serialization steps for ImageData 2025-05-09 02:12:01 +12:00
Kenneth Myhra
5b4644d198 LibWeb: Use WebIDL types for IDL exposed attributes 2025-05-09 02:12:01 +12:00
Sam Atkins
a8529629e2 LibWeb/HTML: Update "is script closable" to current spec
Corresponds to d7fc63a84a
and 7a48703e77
2025-05-08 10:39:34 +01:00
Francesco Gazzetta
5610f5a865 LibWeb/HTML: Add missing include to CanvasRenderingContext2D.cpp
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, 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
Fixes linking of CanvasRenderingContext2D on some systems:

    [2959/3075] Linking CXX shared library lib/liblagom-web.so.0.0.0
    FAILED: lib/liblagom-web.so.0.0.0
    : && /nix/store/f0m6caffiykyvsjim9376a3hx2yj2ghj-gcc-wrapper-14.2.1.20250322/bin/g++ -fPIC -O3 -DNDEBUG  -fstack-protector-strong -Wl,-z,defs -Wl,--no-undefined -Wl,--no-allow-shlib-undefined -Wl,--dependency-file=Lagom/Libraries/LibWeb/CMakeFiles/LibWeb.dir/link.d -shared -Wl,-soname,liblagom-web.so.0 -o lib/liblagom-web.so.0.0.0 @CMakeFiles/LibWeb.rsp && :
    /nix/store/hzw38c3f7s0w200cgk9645z53al7k8lw-binutils-2.44/bin/ld: Lagom/Libraries/LibWeb/CMakeFiles/LibWeb.dir/HTML/CanvasRenderingContext2D.cpp.o: in function `Web::HTML::CanvasRenderingContext2D::context_attributes_from_options(JS::VM&, JS::Value) [clone .localalias]':
    CanvasRenderingContext2D.cpp:(.text+0x355a): undefined reference to `JS::Value::to_boolean() const'
    /nix/store/hzw38c3f7s0w200cgk9645z53al7k8lw-binutils-2.44/bin/ld: CanvasRenderingContext2D.cpp:(.text+0x38e6): undefined reference to `JS::Value::to_boolean() const'
    /nix/store/hzw38c3f7s0w200cgk9645z53al7k8lw-binutils-2.44/bin/ld: CanvasRenderingContext2D.cpp:(.text+0x3d67): undefined reference to `JS::Value::to_boolean() const'
    collect2: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.

Co-authored-by: Timothy Flynn <trflynn89@pm.me>
2025-05-07 16:53:09 -04:00
Andreas Kling
183c847c80 LibJS: Cache PutById to setters in the prototype chain
Some checks are pending
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, 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 is *extremely* common on the web, but barely shows up at all in
JavaScript benchmarks.

A typical example is setting Element.innerHTML on a HTMLDivElement.
HTMLDivElement doesn't have innerHTML, so it has to travel up the
prototype chain until it finds it.

Before this change, we didn't cache this at all, so we had to travel
the prototype chain every time a setter like this was used.

We now use the same mechanism we already had for GetBydId and cache
PutById setter accesses in the prototype chain as well.

1.74x speedup on MicroBench/setter-in-prototype-chain.js
2025-05-05 15:21:43 +02:00
Jelle Raaijmakers
71665fa504 LibWeb: Scale font size by 1.15 for line-height: normal
Browsers such as Chrome and Firefox apply an arbitrary scale to the
current font size if `normal` is used for `line-height`. Firefox uses
1.2 while Chrome uses 1.15. Let's go with the latter for now, it's
relatively easy to change if we ever want to go back on that decision.

This also requires updating the expectations for a lot of layout tests.
The upside of this is that it's a bit easier to compare our layout
results to other browsers', especially Chrome.
2025-05-05 13:15:56 +02:00