Commit Graph

12071 Commits

Author SHA1 Message Date
Simon Wülker
a037ef0fc4 xpath: Let the parents of attribute nodes be their owner elements (#39749)
This is different from the rest of the DOM, see
https://www.w3.org/TR/1999/REC-xpath-19991116/#attribute-nodes. Luckily,
this can cleanly be implemented for XPath because we already abstract
over the concrete DOM implementation.

Testing: This change adds a test
Part of #34527

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-10-10 04:06:44 +00:00
Oriol Brufau
613dc1ab0e Stylo: Let Stylesheet::from_bytes() take a Arc<Locked<MediaList>> parameter (#39731)
For `@import` we already had a `Arc<Locked<MediaList>>`, so now we will
no longer pointlessly clone it into a `MediaList` in order to pass it to
`Stylesheet::from_bytes()`, just for it to be wrapped again into an
`Arc<Locked<MediaList>>`.

Testing: Unneeded, no change in behavior

Stylo PR: https://github.com/servo/stylo/pull/251

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2025-10-09 21:21:16 +00:00
Kingsley Yung
67896bd937 script: Migrate generateKey operation to use new normalization (#39733)
Refactoring of the algorithm normalization in #39431 introduces a new
algorithm normalization procedure to replace the existing one, and we
continue the migration here.

In this patch:

- The `SubtleCrypto.generateKey` method is migrated from using existing
`normalize_algorithm_for_generate_key` function to using the new
`normalize_algorithm` function.
- The custom type `KeyGenerationAlgorithm` used by
`normalize_algorithm_for_generate_key` is removed.
- The functions `generate_key_aes` and `generate_key_hmac` are moved to
the sub-module `aes_operation` and `hmac_operation`, respectively.

Testing: Refactoring. Existing WPT tests suffice.
Fixes: Part of #39368

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-10-09 18:45:49 +00:00
Narfinger
423800eec4 Script: Lazily transform the DOMString into Rust String instead of immediately. (#39509)
This implements LazyDOMString (from now on DOMString) as outlined in
https://github.com/servo/servo/issues/39479.
Constructing from a *mut JSString we keep the in a
RootedTraceableBox<Heap<*mut JSString>> and transform
the string into a rust string if necessary via the `make_rust_string`
method.
Methods used in script are implemented on this string. Currently we
transform the string at all times.
But in the future more efficient implementations are possible.

We implement the safety critical sections in a separate module
DOMStringInner which allows simple constructors, `make_rust_string` and
the `bytes` method.
This method returns the new type `EncodedBytes` which contains the
reference to the underlying string in either format.

Testing: WPT tests still seem to work, so this should test this
functionality.

---------

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
2025-10-09 18:18:03 +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
Andrei Volykhin
7d811f1d2a html: Support selecting <media> element source from children (#39717)
Follow the HTML implemetation and support selection of the 'media'
element loading source from 'source' children elements with validation
processing over their 'media/src/type' attributes.

See https://html.spec.whatwg.org/multipage/#concept-media-load-algorithm

To handle loading with multiple 'source' children was introduced source
children pointer to track the remaining unprocessed 'source' elements
after the resource selection algorithm was invoked.

Testing: Changes in the following tests
with improvements:
-
html/semantics/embedded-content/media-elements/loading-the-media-resource/*
- webgl/tests/conformance/textures/misc/texture-video-transparent.html

with regressions (after enabled 'source' type attribute validation):
- content-security-policy/media-src/media-src*
- mixed-content/gen/top\*audio|video-tag*
- resource-timing/initiator-type/*

Fixes: https://github.com/servo/servo/issues/21481
Fixes: https://github.com/servo/servo/issues/34127

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-10-09 17:56:11 +00:00
Mukilan Thiyagarajan
dddf50c242 script: optimize Element::create for uncustomized built-in elements (#39370)
The investigation in #37745 revealed that `Element::create` spends ~39%
of its runtime in `set_custom_element_state`. For uncustomized built-in
elements, this overhead is unnecessary as according to the spec, they
are equivalent to being initialized in the "uncustomized" state.
Although our rust implemention also initializes the elements in
"uncustomized" state, this particular call to `set_custom_element_state`
can't simply be removed as this call also ensures that the element's
DEFINED state is set to 'true', to match the `:defined` selector, based
on the custom element state.

So, introduce a new method that will only set the
`ElementState::DEFINED` flag by manipulating the state directly and call
it from `Element::create` when creating uncustomized, built-ins.

For more information about the peformance improvements, please refer to
[this comment][1].

[1]: https://github.com/servo/servo/issues/37745#issuecomment-3305477287

Testing: There should be no functional change, so this is covered by WPT
suite.

---------

Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
2025-10-09 11:11:17 +00:00
Oriol Brufau
7b60bd7f51 script: Refactor imported stylesheets (#39719)
We were previously using the unsound `StylesheetContents::from_data()`
to create a dummy stylesheet, which we were later replacing with the
actual imported stylesheet once it loaded.

This patch changes that to use `ImportSheet::Pending` instead. But then:
- We need to store the `MediaList` in `StylesheetContextSource`.
Previosuly we stored it in the dummy stylesheet.
- We also need to store an Arc pointer to the `ImportRule`, in order to
update its stylesheet to `ImportSheet::Sheet(stylesheet)` later on.

Testing: Unnecessary, there should be no behavior change
Fixes: #39710

Stylo PR: https://github.com/servo/stylo/pull/250

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2025-10-09 09:38:33 +00:00
Martin Robinson
9808973467 script: Do not root nodes with animating images (#38996)
Now that we do not need to call `Node::dirty` when an image frame
changes, we no longer have to keep a map of rooted nodes. Instead,
expose a new `AnimatingImages` type that also tracks when the set of
animating images is diryt and new image animation update should maybe be
scheduled.

In addition, cancel any ongoing image animations eagerly when they are
removed from the DOM like we do for CSS animations.

Testing: This should not change behavior and thus is covered by existing
WPT tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
2025-10-09 07:28:38 +00:00
Kingsley Yung
be0ae6bed2 script: Migrate encrypt/decrypt operation to use new normalization (#39530)
Refactoring of the algorithm normalization in #39431 introduces a new
algorithm normalization procedure to replace the existing one, and we
continue the migration here.

This patch migrates the `encrypt` and `decrypt` operation from using
existing `normalize_algorithm_for_encrypt_or_decrypt` function to using
the new `normalize_algorithm` function.

The functions

- `SubtleCrypto::encrypt_aes_cbc`,
- `SubtleCrypto::decrypt_aes_cbc`,
- `SubtleCrypto::encrypt_decrypt_aes_ctr`,
- `SubtleCrypto::encrypt_aes_gcm` and
- `SubtleCrypto::decrypt_aes_gcm`

should be moved to the sub-module `aes_operation`, but, they are only
copied to the sub-module without being removed. This is because the
`wrapKey` and `unwrapKey` operation (not yet migrated) depend on them.
When the two operations are also migrated, we can remove them.

Testing: Refactoring. Existing WPT tests are enough.
Fixes: Part of #39368

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-10-09 05:40:31 +00:00
WaterWhisperer
8aa650931f htmlbuttonelement: check if document is fully active in activation behavior (#39661)
check if document is fully active in HTMLButtonElement's activation
behaviour

Testing: ran a [try
build](https://github.com/WaterWhisperer/servo/actions/runs/18343522397)
and it passed successfully
Fixes: #39643

Signed-off-by: WaterWhisperer <waterwhisperer24@qq.com>
2025-10-09 02:15:23 +00:00
Kingsley Yung
3e2d2ba6cc script: Migrate sign/verify operation to use new normalization (#39646)
Refactoring of the algorithm normalization in #39431 introduces a new
algorithm normalization procedure to replace the existing one, and we
continue the migration here.

In this patch:

- The `sign` and `verify` operation is migrated from using existing
`normalize_algorithm_for_sign_or_verify` function to using the new
`normalize_algorithm` function.
- The custom type `SignatureAlgorithm` used by
`normalize_algorithm_for_sign_or_verify` is removed.
- The functions `sign_hmac` and `verify_hmac` are moved to the
sub-module `hmac_operation`.

Testing: Refactoring. Existing WPT tests suffice.
Fixes: Part of #39368

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-10-08 19:26:34 +00:00
Gae24
b270387541 script: Move worker DOM interfaces to script/dom/workers/ (#39718)
Moves code related to the Web Worker spec to a new mod. 

Testing: A successful build is enough
Part of #38901

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
2025-10-08 17:56:05 +00:00
Andrei Volykhin
11938f0921 html: Do not update the image data inside legacy <image> constructor (#39635)
The legacy 'image' constructor (new Image()) doesn't have any step in
specification which require to run `update the image data` algorithm.

See https://html.spec.whatwg.org/multipage/#dom-image

This non-conformant behavior was added in the PR #31269 to follow
https://html.spec.whatwg.org/multipage/#when-to-obtain-images (..
whenever that element is created or has experienced relevant mutations)
to handle the edge case of `decode()` with 'image' without "src" and
"srcset" attributes.

See
html/semantics/embedded-content/the-img-element/decode/image-decode.html#L87

Testing: No changes in test expectations

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-10-08 14:20:42 +00:00
Martin Robinson
89dfb3ee49 libservo: Make FormControl responses completely asynchronous (#39709)
Before responses to `FormControl` requests were handled synchronous in
script (ie they would block the page). This change makes it so that they
are handled asynchronously, with their responses filtering back through
the Constellation. This should fix many WPT tests when run with
WebDriver.

Testing: There are some WebDriver-based test for this, but they do
not quite pass yet. More investigation is required, but this is
necessary to get them to pass.
Fixes: #39652
Fixes: #37013

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Delan Azabani <dazabani@igalia.com>
2025-10-08 09:06:17 +00:00
Gae24
060d8dba66 script: further restrict accepted worker script (#39570)
Follow more closely spec, adding some missing steps.

Testing: should be covered by existing wpt tests

---------

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
2025-10-07 13:51:54 +00:00
Martin Robinson
fbbdce2e59 libservo: Remove MouseButtonAction::Click from the API (#39705)
The embedder should never be responsible for triggering click events, so
this change removes that possibility from the API. In addition,
triggering of click events is simplified by moving the logic to the
`DocumentEventHandler`. This has the benefit of making behavior
consistent between in-process and out-of-process `<iframe>`s. Now click
events are never triggered when the button up and down cross frame
boundaries.

Testing: This should be covered by existing tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-10-07 13:08:20 +00:00
Euclid Ye
bb2f8415ad script: Remove WebdriverTimeout callback (#39704)
After #39682, this callback is no longer necessary. We also remove
`WebDriverJSError::Timeout`.

Testing: No regression in wdspec. For servodriver,
[before](https://github.com/yezhizhen/servo/actions/runs/18300017112).
[after](https://github.com/yezhizhen/servo/actions/runs/18300911442) is
also the same.

---------

Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
2025-10-07 07:23:00 +00:00
Martin Robinson
c98eb40044 script: Allow loading of <iframe srcdoc> with a sandbox attribute (#39686)
Before, `about: srcdoc` was only handled when loading `<iframe>`
contents in the same `ScriptThread` as the parent. This is not always
the case though with sandboxed `<iframe>`s. This change makes it so that
both code paths properly handle `about: srcdoc`.

Testing: This causes around 12 new WPT passes.
Fixes: #36529.
Fixes: #27791.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2025-10-07 06:40:52 +00:00
Martin Robinson
e9151ec744 script: Use CSP sandboxing flags for <iframe> and pass them to child Documents (#39610)
This change makes it so that `<iframe>` sanboxing is equivalent to the
one used for Content Security Policy, which is how the specification is
written. In addition, these sandboxing flags are passed through to
`<iframe>` `Document`s via `LoadData` and stored as
`Document::creation_sandboxing_flag_set`. The flags are used to
calculate the final `Document::active_sandboxing_flag_set` when loading
a `Document`.

This change makes it so that `<iframe>`s actually behave in a sandboxed
way, the same way that `Document`s with CSP configurations do. For
instance, now scripts and popups are blocked by default in `<iframe>`s
with the
`sandbox` attribute.

Testing: This causes many WPT tests to start to pass or to move from
ERROR to TIMEOUT or failing later. Some tests start to fail:
-
`/html/semantics/embedded-content/the-canvas-element/canvas-descendants-focusability-005.html`:
This test uses a combination of `<iframe allow>` and Canvas fallback
content, which we do not support.
-
`/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_other_frame_popup.sub.html`:
This test is now failing because the iframe is sanboxed but in the
ScriptThread now due to `allow-same-origin`. More implementation is
needed to add support for the "one permitted sandbox navigator concept."

Fixes: This is part of #31973.

---------

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2025-10-06 17:23:03 +00:00
Gregory Terzian
5887e1e963 script: implement url matches about:blank (#39645)
Implement
[matches-about:blank](https://html.spec.whatwg.org/multipage/#matches-about:blank),
and uses it to compute the fallback url of a document.

This will also be useful as part of [fixing iframe
loading](https://github.com/servo/servo/issues/31973).

There is one unrelated change to origin.rs, which is the result of an
fmt.

Testing: added unit-tests and the fallback url should be covered by wpt
tests.

---------

Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com>
2025-10-06 16:35:15 +00:00
Tim van der Lippe
6a0f9d1bcb Define conditional_malloc_size_of for all Rc (#39660)
This updates all Rc that were ignored for malloc_size_of to use
conditional_malloc_size_of, unless the type in the Rc itself doesn't
support malloc_size.

Regular expressions used to search for all occurrences:

```
ignore_malloc_size_of = "Rc.*"
ignore_malloc_size_of = "Arc.*"
```

There are a couple left since they have nested Rc, which I don't know
how to fix.

To be able to define these, several new implementations were added to
`malloc_size_of/lib.rs` as well as
`HashMapTracedValues`.

Testing: if it compiles, it's safe

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2025-10-05 15:12:16 +00:00
Martin Robinson
d1cda7076f script: Do not show simple dialogs for Windows that cannot show them and normalize newlines (#39607)
The specification has a list of rules about when [simple dialogs cannot
be shown][u1]. This change implements that part of the specification and
also the bits that specify when to noramlize newlines in their messages.
In addition, it fills in the remaining specification step comments for
these methods.

[u1]: https://html.spec.whatwg.org/multipage/#cannot-show-simple-dialogs

Testing: This causes some CSP tests run via servodriver to start
passing.
Unexpected alert dialogs cause failures in servodriver.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-10-04 08:51:31 +00:00
Martin Robinson
cf5b8592bf script: Skip running layout when only updating images or canvas (#38991)
Add a new super-lightweight layout mode that avoids any layout when
canvas is updated or animated images progress to the next frame. In the
future this can also be used for video elements.

Testing: This is a performance optimization, so shouldn't change any
WPT test results.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
2025-10-03 13:46:03 +00:00
Martin Robinson
949981163a script: Share Epoch between canvas and layout and update the renderer separately (#39627)
Before both canvas updates and layout had their own `Epoch`. This change
makes it so the `Epoch` is shared. This means that display lists might
have non-consecutive `Epoch`s, but will also allow for the `Epoch` in
the renderer to update even when no new display list is produced. This
is important for #38991. In that PR the display list step can be skipped
for canvas-only updates, but the `Epoch` in the renderer must still
advance.

Testing: This shouldn't change the user-observable behavior and is thus
covered
by existing tests. It should prevent flakiness once #38991 lands.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-10-03 07:22:48 +00:00
Tim van der Lippe
9641c56466 Add style as potential preload destination (#39549)
This was missed during the previous implementation and was the reason
that the CSP tests weren't working.

It also updates a test to ensure that audio and video are not preloaded.
No browsers do that and with this fix, the test now passes in Chrome. In
Firefox it still fails as it doesn't implement `.vtt` support.

Part of #35035

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2025-10-03 04:14:31 +00:00
Tim van der Lippe
680a780552 Implement fetchLater (#39547)
Allows fetches to be deferred, only in a secure context. It does not yet
implement quota computation, since we don't have a concept of document
quota yet.

Also update the `fetch/api/idlharness` test to run in a secure context,
since this API is only available there.

Positive Mozilla position:
https://github.com/mozilla/standards-positions/issues/703
Positive WebKit position:
https://github.com/WebKit/standards-positions/issues/85

Closes whatwg/fetch#1858

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2025-10-02 07:51:19 +00:00
Kingsley Yung
19c498af16 script: Migrate digest operation to use new normalization (#39477)
Refactoring of the algorithm normalization in #39431 introduces a new
algorithm normalization procedure to replace the existing one.

This patch migrates the `digest` operation from using existing
`normalize_algorithm_for_digest` function to using the new
`normalize_algorithm` function.

Note that the custom type `DigestAlgorithm` has not yet completely
removed since other operations like `get key length` (not migrated yet)
depend on it. It will be removed when those operations are also
migrated.

A minor bug (missing a step) in `normalize_algorithm` is also fixed.

Testing: Refactoring. Existing WPT tests are enough.
Fixes: Part of #39368

---------

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-10-02 07:50:01 +00:00
Ashwin Naren
1448fd5967 Remove test_mapping.json and python/servo/mutation (#39617)
As per #39585.

>It used to run on our old buildbot CI for a couple years. It was never
migrated, and we should clean it up.

_Originally posted by @jdm in
https://github.com/servo/servo/issues/39585#issuecomment-3351054660_

---------

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-10-02 04:31:54 +00:00
Ashwin Naren
65588cd5df script: Stubs for geolocation interfaces (#39584)
Needed for #39526; stubs out all the necessary interface from
https://www.w3.org/TR/geolocation/.

Testing: WPT

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-10-02 04:17:36 +00:00
Oriol Brufau
df9902e4d0 Upgrade Stylo to 2025-10-01 (#39612)
This continues #39150

Changelog:
- Upstream:
fd700321cc...b98470a5cb
- Servo fixups:
1040a20611...4ba7bdb404

Stylo tracking issue: https://github.com/servo/stylo/issues/247

---------

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2025-10-02 01:23:05 +00:00
atbrakhi
4ea363277e script: Support keyCode, charCode in KeyboardEvent constructor (#39590)
Support `keyCode` and `charCode` fields in KeyboardEventInit for
Speedometer 3.0

Speedometer 3.0 fails because Servo's KeyboardEvent constructor ignores 
keyCode and charCode parameters, hardcoding them to 0. This breaks
frameworks
that check `event.keyCode === 13` for Enter key detection.  This is how
[Speedometer 3.0 dispatches key
events](8d67f28d02/resources/benchmark-runner.mjs (L166))
vs [Speedometer 2.0
triggerEnter](491acc2d64/resources/tests.mjs (L60)).

Speedometer 3.0 uses the modern KeyboardEvent constructor but passes 
[legacy fields like keyCode and
charCode](https://w3c.github.io/uievents/#legacy-dictionary-KeyboardEventInit)
in the init dictionary for backwards
compatibility with older frameworks(for example: backbone.js)

This change uncomments the legacy KeyboardEventInit fields and updates 
the constructor to read them from the init dictionary instead of 
hardcoding to 0.

Testing: No new tests added. 
Fixes: part of https://github.com/servo/servo/issues/16719

Servo running Speedometer3.0 successfully
<img width="1136" height="880" alt="speedometer 3 0"
src="https://github.com/user-attachments/assets/cf5199a5-d88d-4495-ae96-05fa6332b97e"
/>

---------

Signed-off-by: atbrakhi <atbrakhi@igalia.com>
2025-10-01 14:45:33 +00:00
Simon Wülker
e5017b1b50 Move XPath implementation into its own crate (#39546)
XPath (and, in the future, XSLT) is only loosely coupled to `script`. As
`script` is already very large, I'd like to move the xpath parser and
evaluator into a seperate crate. Doing so allows us to iterate on it
more easily, without having to recompile `script`. Abstracting over the
concrete DOM implementation could also allow us to write some more
comprehensive unit tests.

Testing: Covered by existing web platform tests
Part of https://github.com/servo/servo/issues/34527
Fixes https://github.com/servo/servo/issues/39551

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-09-30 19:55:10 +00:00
Andrei Volykhin
6a1a3aea08 html: Allow legacy referrer policies only for <meta> referrer (#39506)
Follow the HTML specification and allow to use legacy referrer policies
(never/default/always/origin-when-crossorigin) only with 'meta'
referrer.

See https://html.spec.whatwg.org/multipage/#meta-referrer (step 5)

While for another HTML elements with 'referrerpolicy' content attribute
(https://html.spec.whatwg.org/multipage/#referrer-policy-attribute)
and for 'Referrer-Policy' HTTP header

(https://w3c.github.io/webappsec-referrer-policy/#referrer-policy-header-dfn)
the referrer policy should be determine from the standard policy tokens
(https://w3c.github.io/webappsec-referrer-policy/#referrer-policy).

So unknown policy values (legacy from meta-referrer) will be ignored
and determine as 'ReferrerPolicy::EmptyString'.

Testing: No changes

Fixes: #36833

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-09-30 16:29:24 +00:00
Martin Robinson
439558133f script: Use conditional_malloc_size_of for Rc types on Window (#39589)
This allows measuring the size of these types conditionally rather than
ignoring them.

Testing: This modifies which things are measured by `MallocSizeOf` which
isn't covered by tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-09-30 16:03:34 +00:00
Simon Wülker
0a1633c52a script: Remove unreachable assertions in xpath parser (#39588)
`relative_path_expr` can only ever return `Expr::Path`. If we make it
return a `PathExpr` then callers can rely on this invariant.

Testing: There's only limited testing for this change due to
https://github.com/servo/servo/issues/39551. But I think that's okay,
since the change is fairly trivial.
Part of https://github.com/servo/servo/issues/34527

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-09-30 13:20:31 +00:00
Martin Robinson
6ffc0cd482 libservo: Add a WebView::take_screenshot() API and use it for reftests (#39583)
This change adds a new API to the `WebView` for capturing screenshots.
This makes it possible to:

 - use the reftest waiting infrastructure via the API
   easily.
 - take more than a single screenshot in one Servo run.
 - take screenshots, but still paint the `WebView` normally prior
   to the moment that the screenshot is ready, instead of preventing
   all non-screenshot-ready paints while taking a screenshot.

In addition, the previous infrastructure, the `wait_for_stable_image`
option is removed completely.

Testing: This change is tested by the passing of the WPT tests,
as they commonly use the screenshot feature.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Delan Azabani <dazabani@igalia.com>
2025-09-30 11:39:47 +00:00
Gae24
5442302f8b script: move testbinding DOM interfaces to script/dom/test (#39585)
Move testbinding interfaces to it's own module, to avoid cluttering dom
folder.

Testing: A successful build is enough
Part of #38901

---------

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
2025-09-30 10:17:09 +00:00
Martin Robinson
6a2a9a6e33 layout: Ensure that the Epoch stored in layout is accurate (#39568)
The first epoch is 0 as that is the one used in the initial transaction,
but the code was setting the first `Epoch` to `Epoch(1)`. This means
that
when layout advanced the epoch, the `Epoch` of the first produced
display list was `Epoch(2)`.

This change makes the value reflected in `current_epoch` actually match
the index of the display list produced. In addition, we always store
this epoch in `PipelineDetails` in the renderer. This will be important
when adding the `WebView::take_screenshot` API.

Testing: This should not change behavior, so is covered by existing
tests which
rely on proper `Epoch` advancement.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-09-30 06:42:58 +00:00
Rocketjumper
91e4188a64 script: Add line number argument to module script compilation functions (#39544)
Script: added ```line_no``` as argument to both
```fetch_inline_module_script()``` & ```compile_module_script()``` to
fix the inline script reporting wrong line issue
([#39415](https://github.com/servo/servo/issues/39415)).

Originally, the function ```compile_module_script()``` hardwires the
value 1 when invoking ```CompileOptionsWrapper::new()```. This is fine
if the script is written in separate JS file, but for inline scripts, it
will cause confusion if the ```<script>``` tag doesn't start from line
#1.

```line_no``` is obtained from ```line_number```, a member variable from ```HTMLScriptElement```. 

Credits to @jdm for actually pointing out which functions to fix.

Testing: Created a WPT test for this change, specifically: ```tests/wpt/tests/html/semantics/scripting-1/the-script-element/module/evaluation-error-5.html```.

Fixes: issue [#39415](https://github.com/servo/servo/issues/39415)

---------

Signed-off-by: RichardTjokroutomo <richard.tjokro2@gmail.com>
Signed-off-by: Rocketjumper <112361665+RichardTjokroutomo@users.noreply.github.com>
Co-authored-by: Josh Matthews <josh@joshmatthews.net>
Co-authored-by: Euclid Ye <yezhizhenjiakang@gmail.com>
2025-09-30 05:42:32 +00:00
Kingsley Yung
34979c8b71 script: Return cached object from CryptoKey.usages getter (#39564)
Create and store a cached object in `CryptoKey` for the `[[usages]]`
internal slot when the key is created or when its `[[usages]]` internal
slot is updated. The getter can then return the cached object as
specified in https://w3c.github.io/webcrypto/#dom-cryptokey-usages,
instead of creating a new object on each call.

Testing: Pass WPT tests that were expected to fail.

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-09-30 03:56:12 +00:00
webbeef
55facf7b15 script: Cache the current favicon on the document (#39575)
This allows us to notify the embedder when navigating back and forth.

Testing: Manual testing following the steps in issue #39529 
Fixes: https://github.com/servo/servo/issues/39529

Signed-off-by: webbeef <me@webbeef.org>
2025-09-30 02:35:49 +00:00
Ashwin Naren
fef56fcc47 Consistently rename storage to webstorage to prevent confusion (#39550)
Add the prefix of "WebStorage" instead of "Storage" for all webstorage
spec related things. For example, a `struct` called `StorageManager`:
this could refer to either webstorage's thread manager or to the backend
for [the storage manager
interface](https://storage.spec.whatwg.org/#storagemanager). webstorage
is the full name of the spec, so I chose to keep that in the names of
files/structs to prevent confusion when storage manager is implemented.

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-09-29 17:13:34 +00:00
Rodion Borovyk
5b1fe60277 script: Empty pending mutation observers when notifying mutation observers (#39456)
Empty the surrounding agent’s pending mutation observers when notifying
mutation observers according to the spec. Also, the code in the method
MutationObserver::queue_a_mutation_record and the corresponding
specification have diverged over the years. These changes bring the code
into conformity with the specification.

Testing: Added a new crash test
Fixes: #39434 #39531

---------

Signed-off-by: Rodion Borovyk <rodion.borovyk@gmail.com>
2025-09-29 14:15:07 +00:00
Narfinger
32b656adf4 More changes to HashMap/HashSet to use fxhash (#39244)
Moved more functions to fxhash. And provide comments about the choices
when necessary.


Testing: Hash functions shouldn't change functionality.

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
2025-09-29 09:51:17 +00:00
Narfinger
389f0d4cc2 Split WindowProxies in script to own struct and allow to get an Rc to it. (#39274)
Split the window_proxies in script thread into its own struct with
appropiate methods. ScriptThread allows to get an Rc to it.
HtmlIFrameElement, Window and WindowProxy now get the Rc on construction
from ScriptThread.


Testing: Just a refactor so should not change any behavior.
Fixes: Addresses part of https://github.com/servo/servo/issues/37969

---------

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
2025-09-29 09:46:49 +00:00
webbeef
47382e0c2c script: display top-level SVG image documents. (#39494)
SVG images served with the image/svg+xml mime type were recognized as
XML documents instead of images, so were not displayed.

Testing: compare the results of `./mach run
https://raw.githubusercontent.com/servo/servo/467821598b59bd84273d91c9d8a33651e10578b8/resources/resource_protocol/servo-color-negative-no-container.svg`

Signed-off-by: webbeef <me@webbeef.org>
2025-09-29 09:16:22 +00:00
Gae24
7a7129edd7 script: when fetching a worker script abort if response status is not ok (#39468)
According to
[spec](https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-classic-worker-script)
we should abort if the response status is not ok.

Testing: Check tests listed inside issue are not intermittent anymore
Fixes: #39413
Fixes: #22991

---------

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
2025-09-29 09:08:12 +00:00
Andrei Volykhin
af74db4e92 html: Count <image> attributes state changes as the relevant mutations (#39483)
Follow the HTML specification and take into account that state changes
of the <image> 'crossorigin' and 'referrerpolicy' content attributes
(not 'crossOrigin' and 'referrerPolicy' IDL attributes) should be
counted as relevant mutations.

See https://html.spec.whatwg.org/multipage/#relevant-mutations

Testing: Improvements in the following tests
- html/dom/reflection-embedded.html
-
html/semantics/embedded-content/the-img-element/relevant-mutations.html

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-09-29 09:00:51 +00:00
Sam
aaa7f83176 crown: Check closure bodies for unrooted types and fix root TransmitBodyPromise* (#39534)
We should also check closure bodies for unrooted expressions. 

Testing: New crown tests
Fixes: #37331
Fixes (partial): #37330

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-09-29 08:57:23 +00:00