Commit Graph

10764 Commits

Author SHA1 Message Date
Tim van der Lippe
8e0c2d5750 Implement WindowOrWorkerGlobalScope::reportError (#40654)
This web API is alternative API to `throw e`, which is why we can reuse
a lot of the existing machinery.

The one testcase that isn't passing yet is because it reports an empty
`TypeError`. The current logic in `ErrorInfo` only retrieves the message
data, but doesn't include the type of the exception. For that, we need
to use `(*report)._base.errorNumber` and map that back to the original
type codes. However, deferring that to a follow-up as that requires some
more work in mozjs.

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2025-11-16 09:30:16 +00:00
Ashwin Naren
79d96153ca Fix indexeddb intermitency (#40648)
Fixes a major source of intermittency in IndexedDB: the dispatching of
the complete event. This ensures that all requests are processed before
it is fired.

Fixes: #39162
Fixes: #39221
... and likely many more.

---------

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-11-16 05:51:49 +00:00
Sam
fa12f7a5e5 script: Add cx_no_gc/cx/realm codegen option and demostrate them (#40582)
Companion to https://github.com/servo/mozjs/pull/650

We added 3 new options to bindings.conf, each more powerful then the
previous one, so one should use the least powerful as possible to keep
things flexible:
1 `cx_no_gc` prepends argument `&JSContext`, which allows creating NoGC
tokens and using functions that do not trigger GC.
2. `cx` prepends argument `&mut JSContext`, which allows everything that
previous one allows, but it also allows calling GC triggering functions.
3. `realm` prepends argument `&mut CurrentRealm`, which can be deref_mut
to `&mut JSContext` (so it can do everything that previous can), but it
also ensures that there is current entered realm, which can be used for
creation of InRealm.

next steps: #40600 

reviewable per commit

Testing: It's just refactoring
try run: https://github.com/sagudev/servo/actions/runs/19287700927

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-11-16 04:53:54 +00:00
Sam
2a03c78498 canvas: Clear bitmap without transform (#38286)
We only need to clear the viewport and with wrong transform this will
not do.

Testing: Existing WPT tests

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-11-15 18:35:31 +00:00
Simon Wülker
1d16f6526d script: Don't rely on Attr nodes when communicating with layout (#40657)
When script is looking up an attribute for layout then it only needs to
care about the attribute value. The `Attr` node itself is not required.
If we want to lazily construct attribute nodes in the future
(https://github.com/servo/servo/issues/36697) then we should use `Attr`
as little as possible.

This also ends up simplifying the code by accident.

Testing: No behaviour change intended, regressions are covered by
existing tests.
Part of https://github.com/servo/servo/issues/36697

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-11-15 17:59:57 +00:00
Kingsley Yung
1ec01cc25d script: Housekeeping WebIDL dictionaries of WebCrypto API (#40652)
Housekeeping of WebIDL dictionaries of WebCrypto API, including:

- Add/Fix spec links in `SubtleCrypto.webidl` and `CryptoKey.webidl`.
- Sort dictionaries in `subtlecrypto.webidl` based on the spec.
- Sort the `subtle` structs in `subtlecrypto.rs`, based on the spec.
- Reduce unneeded visibility of those `subtle` structs.

Testing: No behavioral change. Existing tests suffice.

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-11-15 10:17:19 +00:00
Kingsley Yung
33443d21aa script: Use hkdf crate for HKDF in WebCrypto (#40650)
We currently use the crate `aws-lc-rs` for HKDF in the WebCrypto API.
When generating output bytes from the output of HKDF-Expand operation
(OKM, Output Key Material), it enforces the requested output length must
match the length of key type (see error condition of `Okm::fill` at
https://docs.rs/aws-lc-rs/1.14.1/aws_lc_rs/hkdf/struct.Okm.html#method.fill).
However, according to the WebCrypto API specification, user should be
allowed to choose the output length
(https://w3c.github.io/webcrypto/#hkdf-operations-derive-bits). The
restriction from `aws-lc-rs` causes several HKDF-related WPT tests to
fail.

This patch switches to use a more flexible crate `hkdf`
(https://crates.io/crates/hkdf) for implementing HKDF in our WebCrypto
API, and allowing variable length output. This helps to make those
HKDF-related WPT tests pass.

Testing: Pass some WPT tests that were expected to fail.

---------

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-11-15 09:19:11 +00:00
Martin Robinson
d9b183f39b script: Add support for parsing CSS in parallel (#40639)
This change is a rework of #22478, originally authored by @vimpunk.

It adds parsing of CSS in parallel with the main script thread. The
big idea here is that when the transfer of stylesheet bytes is
finished, the actual parsing is pushed to a worker thread from the Stylo
thread pool. This also applies for subsequent loads triggered by
`@import` statements.

The design is quite similar to the previous PR with a few significant
changes:

 - Error handling works properly. The `CSSErrorReporter` is a crossbeam
   `Sender` and a `PipelineId` so it can be trivially cloned and sent to
   the worker thread.
 - Generation checking is done both before and after parsing, in order
   to both remove the race condition and avoid extra work when the
   generations do not match.
- The design is reworked a bit to avoid code duplication, dropping added
   lines from 345 to 160.
 - Now that `process_response_eof` gives up ownership to the
   `FetchResponseListener`, this change avoids all extra copies.

Testing: This shouldn't change observable behavior, so is covered
by existing tests.
Fixes: #20721
Closes: #22478

---------

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: mandreyel <mandreyel@protonmail.com>
2025-11-15 09:10:27 +00:00
WaterWhisperer
28a8918ebd script: Remove unnecessary Trusted wrapper in RemovableDomEventListener (#40649)
Replace `Trusted<EventTarget>` with `Dom<EventTarget>` and add the
appropriate crown attribute.

Testing: `./mach build --use-crown` succeed and no difference in
behaviour when running `./mach test-wpt tests/wpt/tests/dom/abort`
Fixes: #40631

Signed-off-by: WaterWhisperer <waterwhisperer24@qq.com>
2025-11-15 08:27:34 +00:00
Andrei Volykhin
ac0da57bc1 html: Handle new DurationChanged event by <media> (#40644)
A new event `PlayerEvent::DurationChanged` has been added to the media
engine to simplify handling changes in the duration of a media stream
(sometimes the duration could be inaccurate or even determined by the
media engine with significant delay after the initial metadata was
ready).

This new event eliminates the need to check conditions for two
consecutive `MetadataUpdated` events (the initial metadata and the
metadata with the changed duration) during the loading phase.

servo-media:
- Add new `PlayerEvent::DurationChanged` event
(https://github.com/servo/media/pull/461)

Testing: No expected changes in test results

Fixes: https://github.com/servo/servo/issues/40626

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-11-14 15:14:13 +00:00
Tim van der Lippe
c782da762b Implement protocol handler web API's behind flag (#40616)
This implements the web-facing API's behind a flag, where we further
design the embedding API in a
follow-up PR.

It passes all relevant WPT tests, since the HTML
specification leaves it up to user agents to
determine when to process these protocol handlers.

It also uses `once_cell` to lazily construct the
regex, which is what the CSP crate also uses for
its regexes [1].

Part of #40615

[1]:
db8f2e97fe/src/lib.rs (L1550-L1569)

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2025-11-14 12:53:33 +00:00
Kingsley Yung
3d56aaa484 script: Flatten nested match arms in NormalizedAlgorithm (#40643)
This patch flattens nested match arms in `NormalizedAlgorithm` to
simplify our code. Moreover, primarily matching the algorithm names,
instead of matching the enum variant types, makes more sense, since some
algorithms share the same enum variant type.

Testing: Refactoring. Existing tests suffice.

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-11-14 10:33:32 +00:00
WaterWhisperer
e4b7962854 script: Fix MutationObserver to use Dom instead of DomRoot (#40608)
converts MutationObserver's record_queue and node_list, as well as
RegisteredObserver's observer field, to use Dom<T> instead.

Testing: `./mach build --use-crown` pass locally
Fixes #40602

Signed-off-by: WaterWhisperer <waterwhisperer24@qq.com>
2025-11-13 19:14:30 +00:00
Simon Wülker
a1269e809d Replace calls to ".filter_map()" followed by ".next()" with ".find_map()" (#40612)
The two are semantically equivalent, but `find_map` is more concise.

Testing: Covered by existing tests

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-11-13 14:53:57 +00:00
Andrei Volykhin
c19641e3fe html: Add <media> current and official playback positions (#40609)
Follow the HTML specification and split the previous `playback position`
to `current playback position` (a time on the media timeline) and
`official playbac position` (an approximation of the current playback
position that is kept stable while scripts are running) which must be
set to `the current playback position` any time the user agent provides
a stable state.

See https://html.spec.whatwg.org/multipage/#current-playback-position
See https://html.spec.whatwg.org/multipage/#official-playback-position

Note that at this point, there are no difference between the `current`
and `official` playback positions (as the time on the media timeline),
except the `seek` case.

Testing: Improvements in the following tests
-
html/semantics/embedded-content/media-elements/seeking/seek-to-max-value.htm
-
html/semantics/embedded-content/media-elements/seeking/seek-to-negative-time.htm

Fixes: https://github.com/servo/servo/issues/34496

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-11-13 11:42:41 +00:00
Taym Haddadi
4658fc333a Add AbortSignal garbage collection (#40508)
Add AbortSignal garbage collection

Testing: all AbortSignal should pass.

Fixes: #40481

---------

Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
2025-11-13 10:58:55 +00:00
WaterWhisperer
d57d422924 script: servoparser line number pass to CSP (#40597)
takes over the initial work from @zazabap in PR #38675 (Thanks
@zazabap!)

Testing: 
`./mach test-wpt
content-security-policy/securitypolicyviolation/blockeduri-inline.html`
`./mach test-wpt
/css/CSS2/abspos/abspos-containing-block-initial-001.xht`
Fixes #38167  
Closes #38675

Signed-off-by: WaterWhisperer <waterwhisperer24@qq.com>
Co-authored-by: zazabap <sweynan@icloud.com>
2025-11-13 09:48:17 +00:00
Kingsley Yung
b235a35a7c script: Correctly parse spki and pkcs8 of ECDH (#40605)
We parse the `parameter` field of the `algorithm` AlgorithmIdentifier
field of `spki` and `pkcs8` of ECDH keys as an object identifier.
However, according to WebCrypto API specification, we should parse it as
an `ECParameters` ASN.1 type defined in [RFC5480].

```plaintext
ECParameters ::= CHOICE {
  namedCurve         OBJECT IDENTIFIER
  -- implicitCurve   NULL
  -- specifiedCurve  SpecifiedECDomain
}
```

Although our current implementation works fine since `ECParameters` is
defined as a `CHOICE` type with an object identifier as the only option,
it is technically incorrect. This patch fixes this mistake.

Testing: No behavioral change. Existing tests suffice.

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-11-13 09:17:47 +00:00
Andrei Volykhin
6bb012b76b html: Add <media> internal ended_playback method (#40603)
Following the HTML specification, a new internal method,
`ended_playback`, has been added to differentiate it from the `ended`
attribute:
- `ended_playback`: playback has ended for the `forward/backward`
directions
- `ended` attribute: playback has ended for the `forward` direction

See https://html.spec.whatwg.org/multipage/#ended-playback

Added descriptions for the steps of the `Play`, `Pause`,
`internal_play_steps` (new), `internal_pause_steps`,
`notify_about_playing`, `change_ready_state` methods.

Testing: No expected changes in test results.

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-11-13 08:32:52 +00:00
Andrei Volykhin
59526928af html: Remove canGC argument from <media> internal seek method (#40587)
The `seek` method isn't explicitly exposed in the API, but is called
from various places (`currentTime`, `fastSeek`, by the `media metadata`
event) and doesn't itself create new DOM objects, so the `canGC`
argument can be omitted.

It was previously required because calling the `Seekable` method creates
a new `TimeRanges` object, but it will now be replaced by the internal
`seekable` method to avoid interaction with the JavaScript engine (and
potential garbage collector).

The `earlyest possible position` method has been changed to match the
specification and use `seekable` instead of `played`. See
https://html.spec.whatwg.org/multipage/#earliest-possible-position

Testing: No expected changes in tests

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-11-12 18:44:15 +00:00
Martin Robinson
0a1061d8d7 script: Use ScriptEventLoopSender for Runtime event loop callbacks (#40590)
Instead of using a task source for SpiderMonkey runtime callbacks, use a
`ScriptEventLoopSender`. Task sources are associated with a particular
Pipeline, but the runtime callback is run indepenently of any particular
Pipeline and could theoretically happen when no Pipeline exists at all.
This reduces the dependency of the `ScriptThread` on the existence of
the first Pipeline.

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

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-11-12 18:16:59 +00:00
Andrei Volykhin
4d938368cb bump(deps): bump servo-media from 5b788a9 to 8aca9f7 (#40563)
Updated the `PlayerEvent::PositionChanged/SeekDone` events to support
precise position timestamps (u64 -> f64).
    
Also set precise time value (seconds with fractional part) for the
HTMLMediaElement `duration` from media metadata to sync with
`PlayerEvent` changes.

servo-media:
- Pass precise position timestamp within PlayerEvent
(https://github.com/servo/media/pull/460)

Testing: No expected changes in test results

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-11-12 15:43:34 +00:00
Martin Robinson
ab0f818583 script: Consolidate more logic into ScriptThread::spawn_pipeline (#40586)
Have more of the code follow the same path calling
`ScriptThread::spawn_pipeline`. Somewhat tricky was that the `origin` of
the new Pipeline was being determined in several different places, but
all in a consistent way for different types of page loads. This change
makes it is so that the origin is always determined in the same place.

This change is preparation for splitting out the creation of a new
`ScriptThread` and the spawning of its first pipeline.

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

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-11-12 15:37:25 +00:00
Kingsley Yung
2f5f40222c script: Implement sign operation of ECDSA (#40591)
Finish adding ECDSA support to WebCrypto API. This patch implements sign
operation of ECDSA, using ECDSA implementation from the crates `ecdsa`
for the operation, `p256`, `p384`, `p521`, and `elliptic_curve` for the
key, and `sha1`, `sha2` and `digest` for digesting messages.

Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of #39060

---------

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-11-12 12:33:51 +00:00
Simon Wülker
5ecf09d76a xpath: Fix implementation for preceding::/following:: axes (#40588)
`preceding::` needs to yield all preceding nodes, excluding ancestors.
`following::` needs to yield all following nodes, excluding descendants.

Both `Node::preceding_nodes` and `Node::following_nodes` (which we're
currently using) don't quite match these requirements, so we have to
engineer some xpath-specific iterators.

Testing: New tests start to pass

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-11-12 10:40:36 +00:00
Rod Borovyk
a79d7d700d script: Introduce HtmlSerialize to support extensible node serialization (#40568)
XML and HTML serialization routines relied on a single, shared
implementation of the `markup5ever::Serialize` trait for the DOM Node
type.

These changes introduce the HtmlSerialize type to make it possible to
support XML serialization and fix other issues.

Testing: It does not change any behavior and it builds.
Fixes: #40552

---------

Signed-off-by: Rodion Borovyk <rodion.borovyk@gmail.com>
2025-11-12 10:05:46 +00:00
austinwillis
5896cfd936 script: Add message to HierarchyRequestError (#40366)
Adds an optional error message to HierarchyRequestError

Testing: refactor
Fixes: one item in #39053

---------

Signed-off-by: Austin Willis <austinwillis8@gmail.com>
2025-11-12 07:34:47 +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
Simon Wülker
c23a9594ca script: Choose correct document for xpath queries (#40564)
The result of an xpath query can depend on whether or not the document
is a HTMLDocument. We should always use the document that
`document.evaluate` was called on. Instead, we were using the document
of the relevant window. This makes a difference when a script creates a
document and calls `document.evaluate` on that.

Testing: New tests start to pass

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-11-11 15:45:34 +00:00
Martin Robinson
1e4feeaa0d script: Add context-based context menu options (#40501)
Add context menu options for images, links, and editable text areas. In
addition add the ability to show menu options that are disabled. This
also improves the visual style of the context menu in egui as part of
supporting disabled options.

Testing: This has been manually tested, but we could we should be able
to
easily add unit tests when enriching the API with information about the
active element under context menus.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Rakhi Sharma <atbrakhi@igalia.com>
2025-11-11 11:03:41 +00:00
Oriol Brufau
cb906a6219 script: Pass the right base URI to inline sheets (#40554)
HTMLStyleElement was creating stylesheets using the URI of the document,
ignoring `<base>`.

To avoid having to create the UrlExtraData twice (or clone it), this
inlines the `stylesheetcontents_create_callback`.

Testing: 2 WPT are now passing
Fixes: #40550

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2025-11-11 09:59:22 +00:00
Kingsley Yung
a094a0bbbc script: Implement verify operation of ECDSA (#40557)
Continue on adding ECDSA support to WebCrypto API. This patch implements
verify operation of ECDSA, using ECDSA implementation from the crates
`ecdsa` for the operation, `p256`, `p384`, `p521`, and `elliptic_curve`
for the key, and `sha1`, `sha2` and `digest` for digesting messages.

Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of #39060

---------

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-11-11 09:51:26 +00:00
Kingsley Yung
447569a0d7 script: Implement generate key operation of ECDSA (#40553)
Continue on adding ECDSA support to WebCrypto API. This patch implements
generate key operation of ECDSA, using ECDSA implementation from the
crates `p256`, `p384`, `p521` and `elliptic_curve`.

Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of #39060

---------

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-11-11 05:44:03 +00:00
Oriol Brufau
1d0a8b05fb Upgrade Stylo to 2025-11-01 (#40522)
This continues #39612

Changelog:
- Upstream:
b98470a5cb...d71fd89b78
- Servo fixups:
4714bab122...7481d7f7af

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

---------

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2025-11-11 02:59:38 +00:00
webbeef
29bfb3a7b1 script: improve cookie processing of control characters (#40544)
This implements character set restrictions both for the DOM API and when
getting cookies from http/ws headers. This is a local workaround for
https://github.com/rwf2/cookie-rs/issues/243

We still fail some tests because hyper errors out when parsing headers
with %x1 characters.

This patch also makes a minor change to
'ServoCookie::from_cookie_string()' to avoid some string cloning when
possible.

Testing: wpt tests expectations are updated

Signed-off-by: webbeef <me@webbeef.org>
2025-11-11 00:23:03 +00:00
Narfinger
d8c46f0b15 script_bindings: Small USVString cleanup (#40537)
Some methods for USVString were not needed as they could lead to
inefficient usage
(like in CookieStoreMethod) it is better to remove them. Fixed two
methods that take the String
directly instead of copying it.

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>

Testing: No testing necessary as the functionality stays the same.

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
2025-11-10 13:45:56 +00:00
Kingsley Yung
b2e21af948 script: Implement export key operation of ECDSA (#40536)
Continue on adding ECDSA support to WebCrypto API. This patch implements
export key operation of ECDSA, using ECDSA implementation from the
crates `p256`, `p384`, `p521` and `elliptic_curve`.

Testing:
- Pass some WPT tests that were expected to fail.
- The new FAIL expectations are added to
`wrapKey_unwrapKey.https.any.js.ini`, which require the
not-yet-implemented sign/verify operations of ECDSA and RSA-OAEP. These
tests were skipped by WPT when the export key operation of ECDSA had not
been implemented at the time.

Fixes: Part of #39060

---------

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-11-10 12:11:42 +00:00
Andrei Volykhin
de26bfc43a html: Add description for steps of legacy <audio> constructor (#40535)
Add missing description for steps of legacy <audio> constructor with a
small refactoring, avoiding unnecessary `upcast` from `HTMLAudioElement`
to `Element`.

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

Testing: No expected changes in tests (added steps description).

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-11-10 11:48:55 +00:00
Martin Robinson
b334c9470b constellation: Reuse InitialScriptState and InitialPipelineState in UnprivilegedPipelineContent (#40529)
`UnprivilegedPipelineContent` contains all of the data necessary to
create a new `ScriptThread` with an initial `Pipeline` in a new
process. This change reuses the `InitialScriptState` and
`InitialPipelineState` structs inside `UnprivilegedPipelineContent` and
renames it to `NewScriptEventLoopProcessInfo` to clarify what it does.

In addition, `InitialScriptState` also repeated much of the data of
`NewPipelineInfo`, which is now deduplicated and passed separately to
the `ScriptThreadFactory`.

The overall goal here is to make `ScriptThread` and `Pipeline` creation
separate. A `ScriptThread` contains many `Pipeline`s which come and go,
so it should not depend on a single creation `Pipeline`. This is the
first step toward doing that.

Some inputs to `ScriptThreadFactory` differ based on whether the new
`ScriptThread` is created in a new process or not. This change makes it
so that these input are passed as extra arguments.

Finally these changes have revealed a couple members of data structures
that aren't used. These have been removed.

Testing: This is just a refactor and shouldn't change behavior so is
covered by existing tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-11-10 11:41:59 +00:00
Andrei Volykhin
9efe79065e dom: Add the attribute mutation reason (#40527)
For some specific cases (one of them see below) where are requirement to
identify the reason of the attribute mutation (by whom/why it was
changed - by cloning, parser or directly), so the following `reason`
parameter was added to `AttributeMutation::Set` option.

Note that for the HTMLMediaElement the internal `muted` state should be
set to true when the element is created and the element has a `muted`
content attribute specified (should be done once on the first attribute
mutation caused by parser or cloning).

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

Testing: Improvements in the following tests
-
html/semantics/embedded-content/media-elements/user-interface/muted.html

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-11-10 10:09:03 +00:00
Kingsley Yung
885b404da6 script: Implement import key operation of ECDSA (#40523)
Start adding ECDSA support to WebCrypto API. This patch implements
import key operation of ECDSA, using ECDSA implementation from the
crates `p256`, `p384`, `p521` and `elliptic_curve`.

Testing:
- Pass some WPT tests that were expected to fail.
- Remaining failed tests in `ec_importKey.https.any.js.ini` require the
not-yet-implemented export key operation of ECDSA.
- The new FAIL expectations are added to `ecdsa.https.any.js.ini`, which
require the not-yet-implemented sign/verify operations of ECDSA. These
tests were skipped by WPT because the import key operation had not been
implemented at the time.

Fixes: Part of #39060

---------

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-11-10 07:32:34 +00:00
Taym Haddadi
28dd9f9749 Implement read looping using a read request following the spec (#39510)
Implement read looping using a read request following the spec.

Testing:  current wpt test should pass.
Fixes: #39482

---------

Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
2025-11-09 22:05:12 +00:00
Sam
b73b908dbd script: Start preparation to use safer JSContext (#40465)
This PR is companion to https://github.com/servo/mozjs/pull/638,
currently it only make stuff compile. In follwups we will start
passing/using safer JSContext down everywhere.

Testing: Not needed as it's just refactorings.
try run:
https://github.com/sagudev/servo/actions/runs/19196312972/job/54879090390

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-11-09 05:17:26 +00:00
Excitable Snowball
a5c3cc3b4e script: Use InputEvent for input events (#39989)
Use `InputEvent` for text input and set appropriate values for the
`composed`, `data`, `isComposing`, and `inputType` attributes. Use a
placeholder for `dataTransfer` attribute and `getTargetRanges` function,
as they are only applicable to contenteditable, which isn't implemented.

Testing: I added two tests under `tests/wpt/mozilla/tests/input-events`
based on the similarly named ones for contenteditable under
`tests/wpt/tests/input-events`.
Fixes: https://github.com/servo/servo/issues/36398

---------

Signed-off-by: Excitable Snowball <excitablesnowball@gmail.com>
2025-11-08 23:04:03 +00:00
Andrei Volykhin
c67ef13d7c html: Render media controls without ready state precondition (#40456)
Follow the specification and allow to render media controls (expose a
user interface to the user) without any HTMLMediaElement `readyState`
precondition.

The media controls be shown for the following examples without specified
media source (e.g. without `src` attribute).
```
<audio controls></audio>
<video controls>/<video>
```

See https://html.spec.whatwg.org/multipage/media.html#user-interface

For media controls UI don't define root `div` element's style `width`
property from the video natural size (`videoWidth/Height` IDL attributes
which return `0` if `readyState` is `HAVE_NOTHING`).

When the `media` element is adopted between different documents need
adopt the media controls id, so media controls UI
will keep access to the whilelist of media controls identifiers via
`document.servoGetMediaControls(id)` API.

Testing: Improvements in the following tests
-
html/rendering/replaced-elements/embedded-content-rendering-rules/audio-controls-00*
-
html/semantics/the-button-element/command-and-commandfor/on-audio-behavior.tentative.html
-
html/semantics/the-button-element/command-and-commandfor/on-audio-invalid-behavior.tentative.html
Note that `Invoker Commands` API is not yet supported so these `command
and commandfor` tests should fail, but due to previous bug with delayed
media controls shown up. The invoker `onClick` function send actions
with mouse events
(move/up/down) to the test driver at the position of the button element
(via getBoundingClientRect), but before test driver
will handle these actions the mediadata is received and media controls
are shown up with "play" button at this position.
So the media control "play" button is clicked instead of the button, and
it triggers media element `pause` state change.
  See https://open-ui.org/components/invokers.explainer/

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-11-08 19:57:59 +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
99daf8c644 script: Wrap remaining unsafe code and enable unsafe_op_in_unsafe_fn (#40499)
This is last step toward enabling the default rustc
`unsafe_op_in_unsafe_fn` warning for the script crate. It wraps the
remaining unsafe code in `unsafe {}` and removes the line disabling this
warning from `script`'s `Cargo.toml`. In addition, two variables are
renamed from `v` to something slightly more descriptive.

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

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-11-08 14:27:35 +00:00
Martin Robinson
dfc9819b38 script: Rename ScriptThreadMessage::AttachLayout to ScriptThreadMessage::SpawnPipeline (#40491)
The thing that this message does is to spawn a pipeline in a
`ScriptThread`. I believe that the `AttachLayout` name is a relic of a
different time. The corresponding procedure in the `Constellation` is
already called `Pipeline::spawn`.

Testing: This is just a rename, so existing tests should cover this
change.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-11-08 11:16:58 +00:00
atbrakhi
ad8c81d634 servoshell: Implement context menu in servoshell (#40434)
This PR adds context menu support with clickable menu items in the
Minibrowser. The menu appears on right click and supports basic
navigation actions (Back, Forward, Reload).


Testing: We already have tests for ContextMenu in WebView API test.

Signed-off-by: atbrakhi <atbrakhi@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2025-11-08 11:11:09 +00:00
Kingsley Yung
11ad3af0ca script: Implement derive bits operation of X25519 (#40497)
Finish adding X25519 support to WebCrypto API. This patch implements
derive bits operation of X25519, using X25519 implementation from the
crate `x25519-dalek`.

Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of #39060

---------

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-11-08 07:29:21 +00:00