Also fixes several issues with code generation when a dom type is part
of a dictionary.
Part of #34866Fixes#39398
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Some WebIDL methods, attributes and dictionary members are named with
Rust keywords such as `type`, `use` and `continue`. Using those
identifiers directly in the generated Rust code would cause compilation
errors.
The code generator already addresses this issue for attributes and
dictionary members by adding a `_` suffix to the conflicting
identifiers, but does not yet apply the same treatment to methods. This
patch extends the handling to methods as well.
Fixes: #39286
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
The signal taken from the requestinit is now passed into
the request object with the relevant steps. I added all
spec comments to this method, as I had trouble figuring
out which steps I had to add.
This required implementing the algorithm to create
dependent signals, which is used in the `any()` method.
So that's now implemented as well.
All of that required the machinery to have dependent and
source signals on an AbortSignal. It uses an IndexSet
as the spec requires it to be an ordered set.
Part of #34866
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
This clarifies the units for scrolling:
- `f32` is used for internal Servo scrolling APIs as that is the unit
used in WebRender.
- `f64` is used for the web-exposed scrolling APIs as that is what the
WebIDL code generator gives us.
Conversions are done consistently at the boundaries of the two APIs.
In addition, web-exposed scrolling methods are refactored a bit to more
closely follow the specification text. In addition, specification text
is added to those methods so that it is clearer that we are following
it.
Testing: This should not change behavior and is thus covered by existing
tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This will complete the type annotation on `codegen.py` so we can safely
remove the ignore from `pyproject` configurataion
---------
Signed-off-by: Jerens Lensun <jerensslensun@gmail.com>
Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
Add type around CG class for code generatio Web IDL in codegen.py
Testing: *Describe how this pull request is tested or why it doesn't
require tests*
Fixes: *Link to an issue this pull requests fixes or remove this line if
there is no issue*
---------
Signed-off-by: Jerens Lensun <jerensslensun@gmail.com>
Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
The method now doesn't need unsafe in its signature because it no longer
accepts unsafe pointers as arguments. We move the unsafe marker to the
method itself.
Testing: I opened the browser and went to google.com; I ran some WPT
(IndexedDB) tests.
Fixes: #38361
---------
Signed-off-by: criskell <96352451+criskell@users.noreply.github.com>
This is an implementation of the `prevent_scroll` feature in the focus
transaction system. It allows to control whether focusing an element
should prevent scrolling or not.
Spec:
https://html.spec.whatwg.org/multipage/interaction.html#dom-focusoptions-preventscroll
Testing: Existing WPT tests
Signed-off-by: abdelrahman1234567 <abdelrahman.hossameldin.awadalla@huawei.com>
This PR focuses on adding type annotations to utility functions,
PropertyDefiner, and its child classes.
---------
Signed-off-by: Jerens Lensun <jerensslensun@gmail.com>
Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
This is a first draft at implementing the required infrastructure for
CookieStore, which requires setting up IPC between script and the
resource thread to allow for async/"in parallel" handling of cookie
changes that have a promise API.
Cookie Store also will need to receive change events when cookies for a
url are changed so the architecture needs to support that.
Expect this PR to be reworked once the architecture becomes more
settled, cookie change events will be implemented in follow up PRs
Testing: WPT tests exist for this API
Part of #37674
---------
Signed-off-by: Sebastian C <sebsebmc@gmail.com>
Adds the `matrixTransform` function for `DOMPointReadOnly`.
Testing: Covered by WPT tests (`css/geometry`)
---------
Signed-off-by: lumiscosity <averyrudelphe@gmail.com>
These changes allow using MallocSizeOf/`#[conditional_malloc_size_of]`
on WebIDL callback values, and then fix a grab bag of places in the
script crate that previously ignored those values. There are also some
commits removing ignored fields that involved Arc/Rc that are not WebIDL
callbacks, since they are now easier to support with the
`#[conditional_malloc_size_of]` attribute.
Testing: Manual testing on about:memory for servo.org.
---------
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This change adds support for variable fonts via the
[`font-variation-settings`](https://developer.mozilla.org/en-US/docs/Web/CSS/font-variation-settings)
property.
There are three areas where we need to set the variation values:
* Webrender (`compositor.rs`), for drawing the glyphs
* Harfbuzz (`shaper.rs`), for most shaping tasks
* PlatformFont (`fonts/platform/`), for horizontal advances and kerning
For now, freetype is the only platform shaper that supports variable
fonts. I can't easily test the fonts with non-freetype shapers. Thats
why variable fonts are behind the `layout_variable_fonts_enabled` pref,
which is disabled by default.
<img width="1250" height="710" alt="image"
src="https://github.com/user-attachments/assets/1aee1407-f3a2-42f6-a106-af0443fcd588"
/>
<details><summary>HTML test file</summary>
```html
<style>
@font-face {
font-family: "Amstelvar VF";
src: url("https://mdn.github.io/shared-assets/fonts/variable-fonts/AmstelvarAlpha-VF.woff2")
format("woff2-variations");
font-weight: 300 900;
font-stretch: 35% 100%;
font-style: normal;
font-display: swap;
}
p {
font:
1.2em "Amstelvar VF",
Georgia,
serif;
font-size: 4rem;
margin: 1rem;
display: inline-block;
}
.p1 {
font-variation-settings: "wght" 300;
}
.p2 {
font-variation-settings: "wght" 625;
}
.p3 {
font-variation-settings: "wght" 900;
}
</style>
<div>
<p class="p1">Weight</p>
<span>(font-variation-settings: "wght" 300)</span>
</div>
<div>
<p class="p2">Weight</p>
<span>(font-variation-settings: "wght" 625)</span>
</div>
<div>
<p class="p3">Weight</p>
<span>(font-variation-settings: "wght" 900)</span>
</div>
</div>
```
</details>
https://github.com/user-attachments/assets/9e21101a-796a-49fe-b82c-8999d8fa9ee1
Testing: Needs decision on whether we want to enable the pref in CI
Works towards https://github.com/servo/servo/issues/37236
Depends on https://github.com/servo/stylo/pull/230
---------
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This is part of introducing the Ruff rule [flake8-annotations
(ANN)](https://docs.astral.sh/ruff/rules/#flake8-annotations-ann) into
the script_bindings folder.
Since `codegen.py` has 10k lines of code, the strategy is to introduce
the rule first while ignoring the `ANN` Ruff rule for `codegen.py`. We
will then gradually add type annotations slice by slice to ensure no new
errors occur outside of `ANN`.
Testing: `./mach test-wpt webidl`
---------
Signed-off-by: Jerens Lensun <jerensslensun@gmail.com>
I had a difficult time figuring out where the relevant steps had to be
added. Therefore, I aggressively commented the spec steps so eventually
I discovered where I should add them.
Part of #36258
---------
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>
These changes add compile-time assertions that:
* any type that implements the Serializable/Transferable trait has a
`[Serializable]` or `[Transferable]` annotation in the interface WebIDL
* any WebIDL interface with the `[Serializable]` or `[Transferable]`
annotation implements the corresponding trait
This is useful because it means that WebIDL definitions will be less
confusing if you're trying to figure out whether Servo supports
serializing/transferring a particular interface type. It also makes
fixing #21715 in the future a little bit easier, because the annotations
will remain up to date.
Testing: compile-time only; no point in writing tests for this since it
involves webidl codegen.
---------
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This is a follow-up to #38532 which simply defaulted to an empty string
as the spec's WebIDL doesn't mark `innerHTML` as `Throws`. However,
since the absence of `Throws` in the spec doesn't imply no-throw, we can
mark this as fallible in our WebIDL. This makes the `ShadowRoot`'s
implementation match `Element`'s `innerHTML`.
Testing: Same as #38532.
Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
This is useful to better isolate `unsafe` code. Once all unsafe calls
are wrapped we can enable the Rust warning. This also explicitly
disables the warning for generated code, which is a much more difficult
task. After this change there are 211 warnings left in
`script_bindings`.
Testing: This should not change behavior and is thus covered by existing
tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
*Describe the changes that this pull request makes here. This will be
the commit message.*
Testing: *Describe how this pull request is tested or why it doesn't
require tests*
Fixes: *Link to an issue this pull requests fixes or remove this line if
there is no issue*
---------
Signed-off-by: Jerens Lensun <jerensslensun@gmail.com>
Instead of running "update the rendering" at every IPC message, only run
it when a timeout has occured in script. In addition, avoid updating the
rendering if a rendering update isn't necessary. This should greatly
reduce the amount of processing that has to happen in script.
Because we are running many fewer calls to "update the rendering" it is
reasonable now to ensure that these always work the same way. In
particular, we always run rAF and update the animation timeline when
updating the ernder
In addition, pull the following things out of reflow:
- Code dealing with informing the Constellation that a Pipeline has
become Idle when waiting for a screenshot.
- Detecting when it is time to fulfill the `document.fonts.ready`
promise.
The latter means that reflow can never cause a garbage collection,
making timing of reflows more consistent and simplifying many callsites
that need to do script queries.
Followup changes will seek to simplify the way that ScriptThread-driven
animation timeouts happen even simpler.
Testing: In general, this should not change testable behavior so much,
though it
does seem to fix one test. The main improvement here should be that
the ScriptThread does less work.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
Gated behind the feature flag `dom_navigator_sendbeacon_enabled` as the
`keep-alive` fetch parameter is crucial for real-life use cases such as
analytics requests.
Part of #4577
Part of #38302
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Introduce type checking with Pyrefly in `components/script_bindings`
This commit adds Pyrefly-based type checking to the
`components/script_bindings` directory. The primary goal is to catch
type inconsistencies early and reduce the likelihood of unexpected
runtime errors.
This change affects the `webidl` component, as these script bindings are
responsible for connecting WebIDL specifications to the Rust codebase.
Testing: `./mach test-wpt webidl`
Fixes: *Link to an issue this pull requests fixes or remove this line if
there is no issue*
---------
Signed-off-by: Jerens Lensun <jerensslensun@gmail.com>
to use the [SpiderMonkey Debugger
API](https://firefox-source-docs.mozilla.org/js/Debugger/), we need to
call it from an internal debugger script that we will supply. this
script must run in the same runtime as the debuggee(s), but in a
separate
[compartment](https://udn.realityripple.com/docs/Mozilla/Projects/SpiderMonkey/Compartments)
([more
details](https://hacks.mozilla.org/2020/03/future-proofing-firefoxs-javascript-debugger-implementation/)).
this patch defines a new DebuggerGlobalScope type and a new debugger
script resource. when creating each script thread, we create a debugger
global, load the debugger script from resources/debugger.js, and run
that script in the global to initialise the Debugger API.
subsequent patches will use the debugger script as an RPC mechanism for
the Debugger API.
Testing: no testable effects yet, but will be used in #37667
Fixes: part of #36027
---------
Signed-off-by: Delan Azabani <dazabani@igalia.com>
Co-authored-by: atbrakhi <atbrakhi@igalia.com>
to use the [SpiderMonkey Debugger
API](https://firefox-source-docs.mozilla.org/js/Debugger/), we need to
call it from an internal debugger script that we will supply. this
script must run in the same runtime as the debuggee(s), but in a
separate
[compartment](https://udn.realityripple.com/docs/Mozilla/Projects/SpiderMonkey/Compartments)
([more
details](https://hacks.mozilla.org/2020/03/future-proofing-firefoxs-javascript-debugger-implementation/)).
when creating two globals in the same runtime, Servo will generally try
to reuse an existing compartment for the second global, and there are
other places in script where we rely on this reuse. but for the debugger
script, we can’t do this.
this patch adds a `use_system_compartment` flag to global object
descriptors, which isolates the global in its own compartment in both
possible directions:
- it forces the global to create a new compartment, preventing the reuse
of any debuggee’s compartment
- it fails the check in select_compartment(), preventing future
debuggees from reusing the global’s compartment
Testing: manually tested working in devtools debugger patch (#37667),
where it will undergo automated tests
---------
Signed-off-by: Delan Azabani <dazabani@igalia.com>
Co-authored-by: atbrakhi <atbrakhi@igalia.com>
Spec:
https://drafts.csswg.org/cssom/#dom-documentorshadowroot-adoptedstylesheets
Implement `DocumentOrShadowDOM.adoptedStylesheet`. Due to
`ObservableArray` being a massive issue on its own, it will be as it was
a `FrozenArray` at first. This approach is similar to how Gecko
implement adopted stylesheet. See
https://phabricator.services.mozilla.com/D144547#change-IXyOzxxFn8sU.
All of the changes will be gated behind a preference
`dom_adoptedstylesheet_enabled`.
Adopted stylesheet is implemented by adding the setter and getter of it.
While the getter works like a normal attribute getter, the setter need
to consider the inner working of document and shadow root StylesheetSet,
specifically the ordering and the invalidations. Particularly for
setter, we will clear all of the adopted stylesheet within the
StylesheetSet and readd them. Possible optimization exist, but the focus
should be directed to implementing `ObservableArray`.
More context about the implementations
https://hackmd.io/vtJAn4UyS_O0Idvk5dCO_w.
Testing: Existing WPT Coverage
Fixes: https://github.com/servo/servo/issues/37561
---------
Signed-off-by: Jo Steven Novaryo <jo.steven.novaryo@huawei.com>
Renames the files to pythonic file names. Also replaces the bespoke
caching function with the functools caching function which is
functionally equivalent.
---------
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
These changes reduce the number of times we need to query layout for the
same information when creating mouse/pointer events.
Testing: No new tests required for maintaining existing behaviour.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
The specification moved around lately with how it defines its reports
and report bodies. They became dictionaries, but are currently missing
some fields [1].
Most tests won't be passing yet, since the `Reporting-Endpoints` header
isn't used yet. In fact, the specification leaves it up to the browser
to figure out when to run this task [2]. I am not sure if there some
background scheduling we can do here.
Confirmed with content-security-policy/reporting-api/
report-to-directive-allowed-in-meta.https.sub.html that the callback is
invoked. The test doesn't pass, since
the `describe_scripted_caller` is empty for HTML elements. Thus the
`source_file` is empty, whereas it should be equivalent to the current
document URL.
Part of #37328
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
[1]: https://github.com/w3c/reporting/issues/286
[2]: https://w3c.github.io/reporting/#report-delivery
Follow the HTML speficication and add missing 'transferToImageBitmap'
method to OffscreenCanvas interface.
https://html.spec.whatwg.org/multipage/#dom-offscreencanvas-transfertoimagebitmap
Testing: Improvements in the following tests
- html/canvas/offscreen/compositing/2d.composite.grid*
- html/canvas/offscreen/fill-and-stroke-styles/2d.gradient*
- html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas*
- html/canvas/offscreen/reset/2d.reset*
- html/canvas/offscreen/text/2d.text*
Fixes (partially): #34111
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
Follow the HTML speficication and add missing 'convertToBlob' method
to OffscreenCanvas interface.
https://html.spec.whatwg.org/multipage/#dom-offscreencanvas-converttoblob
Testing: Improvements in the following tests
-
html/canvas/offscreen/manual/convert-to-blob/offscreencanvas.convert.to.blob*
-
html/canvas/offscreen/manual/wide-gamut-canvas/2d.color.space.p3.convertToBlobp3.canvas.html
Fixes: #24272
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
Set the placeholder canvas element of offscreenCanvas to a weak
reference in transferControlToOffscreen()
Testing: I do not understand how to test it, suggestions appreciated
Fixes: https://github.com/servo/servo/issues/35626
---------
Signed-off-by: Rodion Borovyk <rodion.borovyk@gmail.com>
This PR fixes some mistakes introduced in
https://github.com/servo/servo/pull/37332. Where Binding.conf and
WeakReferenceable trait were used badly
Testing: No test introduces
Fixes: It fixes mistake introduced in the incrementally implementation
of #26488
Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
This argument is always `True`.
Testing: Correct generation of dictionary binding code should be covered
by wpt
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
A document's named getter collects elements with either matching name or
id's (varies per element type) and returns them .
We implement this the following way:
* Create an iterator with elements whose `name` attribute matches
* Create an iterator with elements whose `id` attribute matches
* Concatenate both
The spec then asks us if there is more than one element in the list,
which we implement by checking whether the iterator returns `None` after
we get the first element. However, the same element can appear in both
iterators if it is a `img` element and both it's name and id attribute
match. Therefore, we need to check if there are more elements *which are
not equal to the first one*.
Testing: New web platform tests pass
---------
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>