Commit Graph

30 Commits

Author SHA1 Message Date
Narfinger
a908081352 chore: Remove some clippy complains for 1.95 (#44276)
This removes some complains that clippy will have in 1.95.
As this is mostly just match guards, it doesn't update MSRV.

Testing: This is equivalent exchanges, so current WPT would find
anything.

---------

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
2026-04-17 19:55:17 +00:00
Simon Wülker
0fef52f10c script: Remove layout helper traits (#44092)
Servo has lots of `LayoutXYZHelper` traits that are used to define
additional methods on `LayoutDom<XYZ>`. We can replace them with `impl
LayoutDom<XYZ>` blocks, reducing the number of LoC and making it easier
to add or modify methods.

Testing: These should be covered by existing tests

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2026-04-10 18:31:10 +00:00
Simon Wülker
695b8ee913 script: Claim blob before loading <video> poster frame (#44035)
Refer to https://github.com/servo/servo/pull/43746 for a description of
the problem. This change ensures that video posters can be loaded from
blob URLs, even if the URL is revoked right after.

Testing: This change adds a test

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2026-04-08 17:03:56 +00:00
Simon Wülker
e73c010bb1 Force callers to claim blob url before making a fetch request (#43746)
`blob` URLs have a implicit blob URL entry attached, which stores the
data contained in the blob. The specification requires this entry to be
resolved as the URL is parsed. We only resolve it inside `net` when
loading the URL. That causes problems if the blob entry has been revoked
in the meantime - see https://github.com/servo/servo/issues/25226.

Ideally we would want to resolve blobs at parse-time as required. But
because `ServoUrl` is such a fundamental type, I've not managed to do
this change without having to touch hundreds of files at once.

Thus, we now require passing a `UrlWithBlobClaim` instead of a
`ServoUrl` when `fetch`-ing. This type proves that the caller has
acquired the blob beforehand.

As a temporary escape hatch, I've added
`UrlWithBlobClaim::from_url_without_having_claimed_blob`. That method
logs a warning if its used unsafely. This method is currently used in
most places to keep this change small. Only workers now acquire the blob
beforehand.

Testing: A new test starts to pass
Part of https://github.com/servo/servo/issues/43326
Part of https://github.com/servo/servo/issues/25226

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
Co-authored-by: Josh Matthews <josh@joshmatthews.net>
2026-04-06 14:21:55 +00:00
Tim van der Lippe
a1c8896eda script: Pass &mut JSContext to reflect_node_with_proto (#43952)
A lot (and I mean, really a lot) depends on these constructors.
Therefore, this is the one spaghetti ball that I could extract and
convert all `can_gc` to `cx`. There are some new introductions of
`temp_cx` in the callbacks of the servo parser, but we already had some
in other callbacks.

Part of #40600

Testing: It compiles

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2026-04-05 18:07:30 +00:00
Tim van der Lippe
f340042c1d script: Pass &mut JSContext to FetchResponseListener::process_response_chunk (#43657)
Fixes #42841

Testing: It compiles

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2026-03-26 18:05:24 +00:00
Tim van der Lippe
8f699b1f17 script: Pass &mut JSContext to submit_timing_data (#43479)
Part of #40600

Testing: It compiles

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2026-03-20 15:31:46 +00:00
Tim van der Lippe
3d4cfa4718 net: Remove process_request_eof (#43477)
This is no longer present in the spec. Instead, the
`process_request_body` is the new way. These two
methods were called right after each other and there was only 1
implementation in `htmlvideoelement`. That implementation is now moved
to `process_request_body` and hence we can remove the unnecessary
method.

Testing: It compiles

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2026-03-20 10:51:33 +00:00
Javier Olaechea
eea60b8eb1 script: Pass &mut JSContext to FetchResponseListener::process_response (#43259)
Add the cx parameter to `fn process_response` in the
`FetchResponseListener` trait and the traits that that interface change
requires. Chose to add it as the first parameter, following the same
order that `FetchResponseListener::process_response_eof` uses.

Testing: Checked that servo builds locally as well as `./mach fmt` and
`./mach test-tidy`. I don't think more tests are needed as we are not
introducing new functionality
Fixes: #42840

---------

Signed-off-by: Javier Olaechea <pirata@gmail.com>
2026-03-19 06:22:00 +00:00
Tim van der Lippe
479a9b6be3 script: Pass &mut JSContext to attribute_mutated (#43383)
It pushes the `temp_cx` 1 level up to `element.rs` where the calling
chain begins. Other than that this was purely a mechanical change where
I used regexes to replace all patterns with the new ones.

Part of #42812

Testing: It compiles

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2026-03-18 11:03:54 +00:00
Shubham Gupta
89a4a4e24c script: Correct data type of poster in HTMLVideoElement.webidl (#43341)
Correct data type of poster in `HTMLVideoElement` interface
Successful compilation is enough to verify the change.

Testing:  `tests/wpt/meta/html/dom/reflection-embedded.html`

---------

Signed-off-by: Shubham Gupta <shubham.gupta@chromium.org>
2026-03-17 10:04:30 +00:00
Sam
3e2f14c455 script: Pass down &mut JSContext in servoparser and event loop. (#42635)
I only wanted to get `&mut JSContext` in microtask chunk and checkpoint,
but this in turn needed `&mut JSContext` in servoparser, which then
caused need for even more changes in script.

I tried to limit the size by putting some `temp_cx` in:
- drops of `LoadBlocker`, `GenericAutoEntryScript`
- methods of `VirtualMethods`
- methods of `FetchResponseListener`

Testing: Just refactor, but should be covered by WPT tests.
Part of #40600

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2026-02-25 07:14:23 +00:00
Sam
9f1e5d084e script: Pass &mut JSContext in FetchResponseListener::process_response_eof (#42729)
`process_response_eof` is the only method that needs cx at least right
now. This PR removes one temp_cx and introduces one, removing that one
will is hard (needs VirtualMethods and a lot of work)

Testing: Just refactor
Part of #40600

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2026-02-20 16:03:21 +00:00
Laurent Belmonte
0dc28296e0 script: Some failed requests should record resource timing entries (#41804)
Some failed requests should record resource timing entries

Testing: ./mach test-wpt
tests/wpt/tests/resource-timing/entries-for-network-errors.sub.https.html
Fixes: https://github.com/servo/servo/issues/41667

---------

Signed-off-by: bellau <laurent.belmonte@gmail.com>
2026-01-14 13:20:12 +00:00
WaterWhisperer
2a759ed6de Replace allow(crown::unrooted_must_root) with expect(crown::unrooted_must_root) (#41815)
Testing: `./mach build -d --use-crown` with no warnings
Fixes: #41761

Signed-off-by: WaterWhisperer <waterwhisperer24@qq.com>
2026-01-10 08:05:49 +00:00
Tim van der Lippe
e2d62531f5 script: Consolidate global initialization for fetch requests (#41663)
Rather than having each callside specifying the relevant
information from the GlobalScope, do this via a trait instead.
This would have saved us quite a bit of test debugging
since we would often forget to set relevant information
from the global context for a request.

Now, in the future when we need additional information from
the globalscope for a request, we only need to update this
method to make that happen.

Previously it would also sometimes use `document`, but
calling the relevant information on either `document` or
`globalscope` doesn't matter, since the `globalscope`
defers to the value from the `document` anyways.

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2026-01-07 13:22:03 +00:00
Tim van der Lippe
d44c38998c net: Keep track of size of keep-alive records (#41457)
These keep-alive records live on the `CoreResourceManager` since the vec
of records must be modified by the fetch thread. The script thread
sometimes
requires this information as well, which is why it can send a message to
obtain the total size.

The keep-alive records must be tracked per global. That's why all code
needs
to specify the `pipeline_id`. Requests optionally have this field, which
is why
the code expects it to be present. The relevant information is added to
the
navigator request to ensure it can compute it.

Fixes #41230

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2026-01-05 18:22:58 +00:00
Tim van der Lippe
de27dc69e5 Implement pending preload responses with futures (#40059)
This implements waiting for pending preloads, where the preload request
is still fetching the result when the second "real" request is started.
It is
implemented by storing responses in the `SharedPreloadedResources`
which is communicated via `PreloadId` send to the `CoreResourceManager`.

Part of #35035

---------

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
Co-authored-by: Josh Matthews <josh@joshmatthews.net>
2026-01-04 12:22:54 +00:00
Tim van der Lippe
d8bf293828 script: Remove Drop implementation of FetchCanceller (#41384)
Instead, we now explicitly call `.terminate()` and introduce relevant
methods to FetchCanceller.

Follow-up from review in #41345

---------

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Signed-off-by: Tim van der Lippe <TimvdLippe@users.noreply.github.com>
Co-authored-by: Josh Matthews <josh@joshmatthews.net>
2025-12-19 08:31:09 +00:00
Tim van der Lippe
3ac02bc6ac script: Mark fetch-later requests as keep-alive (#41345)
This implements the required plumbing for the keep-alive flag on
requests. The flag already exists on the request object, but now also
exists on the builder itself.

The flag is then passed into a canceller. While we could make canceller
optional, in many cases it isn't and would require a whole lot more
changes. To follow the spec more closely, opted to put the keep_alive
flag on the canceller as well.

Note that this doesn't pass any extra fetch-later tests since we are not
correctly unloading iframe documents. That will be fixed in a follow-up
PR.

Part of #41230

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2025-12-18 19:49:13 +00:00
Andrei Volykhin
155dc71a65 script: Fire the video resize event in the expected order (#40940)
Queuing a media element task given the media element to fire an event
named `resize` at the media element shoud be done:
- upon the initial `metadata` event from the media engine

https://html.spec.whatwg.org/multipage/#loading-the-media-resource:event-media-resize
- whenever the video dimensions are changed (readyState is not
`HAVE_NOTHING`)

https://html.spec.whatwg.org/multipage/#the-video-element:event-media-resize

See https://html.spec.whatwg.org/multipage/#event-media-resize

Testing: Added new test to confirm `resize` event ordering
-
html/semantics/embedded-content/media-elements/event_order_durationchange_resize_loadedmetadata.html

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-12-01 08:17:35 +00:00
Martin Robinson
bfde51c0db script: Have FetchResponseListener::process_response_eof consume the listener (#40556)
The goal of this change is to prevent having to copy so much data out of
listeners when a fetch completes, which will be particularly important
for off-the-main thread parsing of CSS (see #22478). This change has
pros and cons:

Pros:
- This makes the design of the `FetchResponseListener` a great deal
simpler.
They no longer individually store a dummy `ResourceFetchTiming` that is
   only replaced right before `process_response_eof`.
 - The creation of the `Arc<Mutex<FetchResponseListener>>` in the
   `NetworkListener` is abstracted away from clients and now they just
   pass the `FetchResponseListener` to the fetch methods in the global.

Cons:
 - Now each `FetchResponseListener` must explicitly call `submit_timing`
   instead of having the `NetworkListener` do it. This is arguably a bit
   easier to follow in the code.
 - Since the internal data of the `NetworkListener` is now an
   `Arc<Mutex<Option<FetchResponseListener>>>`, when the fetching code
   needs to share state with the `NetworkListener` it either needs to
   share an `Option` or some sort of internal state. In one case I've
   stored the `Option` and in another case, I've stored a new inner
   shared value.

Testing: This should not change observable behavior and is thus covered
by existing tests.
Fixes: #22550

---------

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-11-11 22:30:40 +00:00
Josh Matthews
cc1552e8a7 Suppress debug representations of network response bodies (#38789)
Adds a wrapper type for vectors that can contain large response bodies
to prevent flooding debug logs with the contents of those bodies.

Testing: Can't test debug log output.
Fixes: #37769

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
2025-11-08 19:49:17 +00:00
Martin Robinson
8f6edca4dd net: Simplify FetchResponseListener and move it to script (#40461)
`FetchReponseListener` has traditionally lived in `net` even though it
is only used in `script` currently. Because of the two way dependency,
it has also use a lot of templating to implement something pretty basic
(call methods on a trait object).

This change moves the trait to `script` and removes several levels of
templating, making the code quite a bit shorter and easier to
understand.

This change is preparation for fixing #22550 and implementing
off-the-main-thread CSS parsing.

Testing: This should not change any behavior so is covered by existing
tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-11-06 14:44:01 +00:00
Martin Robinson
bdcae320fd net: Use callbacks instead of IPC channels in the ImageCache API (#40453)
Previously, the `ImageCache` would inform consumers of changes to image
availability by messaging an IPC channel. This isn't great, because it
requires serialization and deserialization. Nowadays, `ImageCache`s are
always owned by the same `Global` that uses them. This change replaces
the IPC channel with callback that implements `Send`.

For the case of normal HTML document images, the results are still sent
over the pre-existing Crossbeam channel that was connected via an IPC
route. A followup change might eliminate that channel entirely.

Testing: This should not change observable behavior so is covered by
existing tests.
Fixes: #24338.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
2025-11-06 12:52:40 +00:00
Martin Robinson
f08460cded script: Handle broken image icon in HTMLImageElement (#40429)
Instead of having the `ImageCache` return the broken image icon for
failed loads, have `HTMLImageElement` explicitly request it. This means
that the image is loaded on demand (reducing the usage of resources) and
also simplifying the interface of the `ImageCache` greatly.

In addition, the display of the broken image icon is improved, more
closely matching other browsers. A test for this display (which was
falsely passing before) is updated to reflect the new display of the
broken image icon.

Testing: There is a Servo-specific test for this change. Some WPT tests
start to fail as well. Before these were not properly loading the broken
image icon so they were failing before, just in a hidden way.

---------

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
2025-11-06 09:36:21 +00:00
Simon Wülker
c4ae451612 Turn all commented links before functions into doccomments (#40331)
Servo has a lot of comments like this:
```rust
// https://example-spec.com/#do-the-thing
fn do_the_thing() {}
```
and I keep turning these into doc comments whenever I'm working close to
one of them. Doing so allows me to hover over a function call in an IDE
and open its specification without having to jump to the function
definition first. This change fixes all of these comments at once.

This was done using `find components -name '*.rs' -exec perl -i -0777
-pe 's|^([ \t]*)// (https?://.*)\n\1(fn )|\1/// <$2>\n\1$3|mg' {} +`.

Note that these comments should be doc comments even within trait `impl`
blocks, because rustdoc will use them as fallback documentation when the
method definition on the trait does not have documentation.

Testing: Comments only, no testing required
Preparation for https://github.com/servo/servo/pull/39552

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-11-01 05:32:45 +00:00
WaterWhisperer
32c0c41d11 script: Move performance DOM interfaces to script/dom/performance/ (#40262)
Moves interfaces defined by the performance spec to the
`script/dom/performance/` module from `script/dom/`.

Testing: Just a refactor shouldn't need any testing
Fixes: Partially #38901

Signed-off-by: WaterWhisperer <waterwhisperer24@qq.com>
2025-10-29 11:41:52 +00:00
Andrei Volykhin
ef9f16027b html: Add missing 'width' and 'height' reflected IDL dimension attributes (#39606)
The HTML specification defines the 'width' and 'height' attributes as
dimension attributes for the embedded content and images (img, iframe,
embed, object, video, source, input with image type)
https://html.spec.whatwg.org/multipage/#dimension-attributes and for the
tables (table, col, colgroup, thead, tbody, tfoot, tr, td, th) even
these attributes are marked as obsolete.

And UA are expected to use these 'width' and 'height' attributes as
style presentational hints for the rendering.

The embedded content and images:
https://html.spec.whatwg.org/multipage/#dimRendering

The tables:
https://html.spec.whatwg.org/multipage/#tables-2:the-table-element-4

Added missing 'width' and/or 'height' reflected IDL attributes:
- conformant 'unsigned long' IDL attributes for the 'img, source, video'
(with new macro 'make_dimension_uint*)
- obsolete 'DOMString' IDL attributes for the 'td, th, col, colgroup'

Moved the `fn attribute_affects_presentational_hints()` from Element to
specific HTML and SVG elements with attributes which affects
presentational hints for rendering.

Testing: Improvements in the following tests
- html/dom/idlharness.https.html
- html/dom/reflection-embedded.html
- html/dom/reflection-tabular.html
-
html/rendering/replaced-elements/attributes-for-embedded-content-and-images/picture-aspect-ratio.html

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-10-09 18:03:47 +00:00
Ashwin Naren
c92cd9e624 script: Move HTML DOM interfaces to script/dom/html/ (#39046)
See #38901.

Testing: Refactor
Fixes: Partially #38901

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-08-31 01:00:09 +00:00