Commit graph

10197 commits

Author SHA1 Message Date
minghuaw
5b507dc871
script: Update name validation for attribute, element, and doctype (#37747)
A recent update in the spec (https://github.com/whatwg/dom/pull/1079)
introduced new rules for name validation of attribute, element, and
doctype. This PR implements the new name validation rules in
`components/script/dom/bindings/domname.rs`. The old XML name validation
rules are not fully removed because there remains a few usage of it in
`ProcessingInstructions` and `xpath`.

Testing: Covered by WPT tests
Fixes: #37746

---------

Signed-off-by: minghuaw <michael.wu1107@gmail.com>
Signed-off-by: Minghua Wu <michael.wu1107@gmail.com>
Co-authored-by: Xiaocheng Hu <xiaochengh.work@gmail.com>
2025-07-11 02:45:52 +00:00
Ashwin Naren
6ad57a343e
[IndexedDB] Key ranges implementation (#37684)
Improves the implementation of keys to a point where key ranges can be
implemented as well.

Due to me making branching mistakes I'll have to cherry-pick out the
first commit (it's from #37682)

---------

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-07-10 18:33:23 +00:00
Tim van der Lippe
70c57c6136
Add support for Reporting-Endpoints (#37965)
Does not yet handle failures of endpoints, which requires us to update
metadata. I don't see that metadata being used anywhere, so I am not
sure if there is WPT coverage for it.

Part of #37238

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2025-07-09 19:07:29 +00:00
Steven Novaryo
378c4648e4
script: Use an implemented pseudo-element to fortype=color ::color-swatch (#37427)
Implement internal pseudo element, which would be resolved as a
"Implemented Pseudo Element" within style computation. This is an
concrete element that would has a primary style after the style
computation, but could match and style resolved like an pseudo element.
Therefore, it would have a different behavior compared to how does
`pseudo`s that `ServoLayoutNode` had. Where they would not have a
concrete element behind it. Note that, due to the nature of these pseudo
elements residing inside a UA widget, these pseudo elements would
therefore not be accessible in JavaScript by default.

This kind of element is required in order to implement the [form control
pseudo element](https://drafts.csswg.org/css-forms-1/#pseudo-elements)
like `::placeholder`, `::color-swatch`, `::field-text`, etc.
 
See [this docs](https://hackmd.io/@ChaKweTiau/BJ3zRdLQlg) for more
details of the implementation.

Then, the implemented pseudo element is utilized to implement style
matching for input `type=text`.

Servo's side of: https://github.com/servo/stylo/pull/212

Testing: No WPT regression.

---------

Signed-off-by: stevennovaryo <steven.novaryo@gmail.com>
2025-07-09 15:36:58 +00:00
Andrei Volykhin
26f4da8249
script: Propagate a pending JS exception on structured cloning (#37964)
During the object (de)serialization steps on structured cloning
https://html.spec.whatwg.org/multipage/#safe-passing-of-structured-data
it is possible to throw a JS exception.

`self.postMessage({ get whatever() { throw customError } }));`

Require to propagate a pending JS exception and not throw the default
"DataCloneError" DOM exception.

Testing: Improvements in the following tests
- html/infrastructure/safe-passing-of-structured-data/*
- html/webappapis/structured-clone/structured-clone.any.js*
- wasm/serialization/arraybuffer/transfer.window.js
- webmessaging/without-ports/026.html
- workers/semantics/structured-clone/dedicated.html

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-07-09 14:47:55 +00:00
Ngo Iok Ui (Wu Yu Wei)
34c31ee418
WebGL2: support TexImage3D (#37718)
Add TexImage3D method to WebGL2RenderingContext

Testing: conformance2 should pass. Also it should get
http://webglsamples.org/WebGL2Samples/#texture_2d_array and
http://webglsamples.org/WebGL2Samples/#texture_3d running.
Fixes: #26511

Now Servo can run texture_2d_array and texture_3d samples!

![圖片](https://github.com/user-attachments/assets/41b87563-08b8-4db3-b503-12f3a61dbed7)

![圖片](https://github.com/user-attachments/assets/3c62a4de-35ea-488d-b2e5-00e3aed52090)

And it can now run three.js too!

![圖片](https://github.com/user-attachments/assets/d880aa92-a154-4895-aa06-b7919d1fc869)

---------

Signed-off-by: Wu Yu Wei <yuweiwu@pm.me>
2025-07-09 14:22:03 +00:00
Andrei Volykhin
a5b02047f9
script: Allow to throw a custom exception on structured cloning (#37948)
The structured cloning with transfer list
https://html.spec.whatwg.org/multipage/#structuredserializewithtransfer
throws a "DataCloneError" DOM expection by default if
serialization/transferral
is not possible, but a platform object can throw a custom excepton on
its serialization/transfer steps.

One example is OffscreenCanvas, which can throw
an "InvalidStateError" exception if the context mode is not none on
transfer steps.

https://html.spec.whatwg.org/multipage/#the-offscreencanvas-interface:transfer-steps

Testing: Improvements in the following tests
-
html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.transferrable*

Fixes: #37919

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-07-09 11:43:09 +00:00
sagudev
e64bc6d282
script: join compositor_requested_update_the_rendering into should_trigger_script_thread_animation_tick (#37889)
This will help us make "update the rendering" a proper task.

Testing: Existing WPT tests.

try run: https://github.com/sagudev/servo/actions/runs/16085256131

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-07-08 15:26:32 +00:00
Andrei Volykhin
4054f9a5a0
canvas: Make OffscreenCanvas transferable (without placeholder) (#37872)
Follow the specification and make OffscreenCanvas objects are
transferable,
but not in case if there are a weak reference to placeholder canvas
element.
To handle it properly need to implement dedicated frame
provider/dispatcher
between canvas element (script thread) and offscreen canvas (dedicated
worker thread).

https://html.spec.whatwg.org/multipage/#the-offscreencanvas-interface:transferable-objects

Testing: Improvements in the following tests
-
html/canvas/element/drawing-images-to-the-canvas/2d.drawImage.detachedcanvas.html
-
html/canvas/offscreen/manual/convert-to-blob/offscreencanvas.convert.to.blob*
-
html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.transfer*
-
html/infrastructure/safe-passing-of-structured-data/transfer-errors.window.js

Part of #24276

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-07-08 14:47:29 +00:00
Tim van der Lippe
fcb2a4cd95
Implement initial version of ReportingObserver (#37905)
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
2025-07-07 10:43:30 +00:00
Abdelrahman Hossam
3d4868592a
Differentiate console message behavior based on target OS (#37912)
Printing using log macro for Android and OhOS, while retaining original
stderr behavior for other platforms.

Fixes: #37877

Signed-off-by: abdelrahman1234567 <boudyalex321@gmail.com>
2025-07-07 09:14:12 +00:00
sagudev
48cf50309f
script: Also update canvas contents when laying out right after / during long parsing (#37899)
Before #37703 we were actually doing update rendering of canvases/images
as part of `allow_layout_if_necessary` so let's keep doing that until we
fix this properly as this will be much more involved and we want usable
canvases in the mean time.

Testing: Manual testing + WPT tests
Fixes: #37891

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-07-05 18:09:22 +00:00
Usman Yahaya Baba
2ad5b24225
Send WillNavigate earlier during navigation startup (#37778)
The will-navigate message tells the devtools client to expect a
navigation for a browsing context. This makes the network monitor clear
any previous entries and show the requests for the new page that is
loaded. In order to support this correctly, we need to send the
navigation notification from the constellation instead of the script
thread, otherwise we silently ignore navigations triggered by the
browser URL bar.




Testing: Ran servo in devtools mode , now the requests appear for new
loaded page
Fixes: https://github.com/servo/servo/issues/37334

---------

Signed-off-by: Uthman Yahaya Baba <uthmanyahayababa@gmail.com>
2025-07-05 11:35:37 +00:00
sagudev
e1a891ea96
canvas: Use snapshot in canvas backends (#37863)
This removes assumption about pixel format from backend abstraction to
actual backend implementation. This is important for vello.

Testing: WPT tests

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-07-04 20:22:20 +00:00
Andrei Volykhin
9bd8d4f026
canvas: Add OffscreenCanvas 'transferToImageBitmap' method (#37880)
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>
2025-07-04 16:25:36 +00:00
Fuguo
fe7aa91235
compositor|script: Update script's active_touch_points when hit tests on compositor fail (#37779)
[RootCause]:Tochdown executes normally, but touchup fails during hittest
and does not send a touchup event to the script, causing the script to
save an incorrect number of active_touch_points. The application
receives an incorrect event.touches.length, causing a logic error and
preventing the carousel from sliding.
[Solution]:
When hit test on compositor fails, we also need to send the
EmbedderToConstellationMessage::ForwardInputEvent message to
constellation. In the script's handle_touch_event, if it exits early, we
also need to update active_touch_points.

Testing: 
Fixes: #37763

---------

Signed-off-by: kongbai1996 <1782765876@qq.com>
2025-07-04 09:57:24 +00:00
Jan Varga
934b3341d7
storage: Isolate sessionStorage per top-level browsing context and copy sessionStorage when creating a new auxiliary browsing context (#37803)
This pull request introduces changes to the storage subsystem to:
- Isolate sessionStorage per top-level browsing context (WebViewId), in
  addition to origin.
- Copy sessionStorage when creating a new auxiliary browsing context
without
  noopener, as required by the corresponding spec
 
These changes bring Servo closer to spec compliance, matching expected
browser
behavior.

Testing: This work affects observable behavior. As a result, some
previously
failing WPT tests now pass. No new tests are added, since the behavior
is
already covered by existing web-platform-tests.

Fixes: #21291

---------

Signed-off-by: Jan Varga <jan.varga@gmail.com>
2025-07-04 09:15:12 +00:00
Simon Wülker
13eeb29878
Don't explicitly handle dirty roots that are shadow roots (#37862)
Dirty roots are never shadow roots, since we use the flat tree for
invalidation. The flat tree does not contain shadow roots.

Reverts https://github.com/servo/servo/pull/35132. When that patch was
submitted we used the DOM tree for invalidation, so it was possible to
encounter shadow roots.

Testing: Covered by
`shadow-dom/untriaged/events/event-dispatch/test-003.html`

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-07-04 07:11:04 +00:00
Simon Wülker
a6b27c5078
Don't increment node revision twice when attaching shadow root to element (#37865)
`Node::dirty` already increments the version. `Node::rev_version`
traverses all ancestors, so it can end up being fairly expensive.

Testing: I'm not sure about WPT coverage but I think this change is
trivial enough to merge without tests.

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-07-04 07:10:06 +00:00
Andrei Volykhin
6ba54e4d79
canvas: Add OffscreenCanvas 'convertToBlob' method (#37786)
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>
2025-07-04 06:58:12 +00:00
sagudev
a631b42e60
pixels: Ensure expected formats when accesing bytes of snapshot (#37767)
I introduced snapshot in #36119 to pack raw bytes and metadata together,
now we take the next step and require for user to always specify what
kind of byte data they want when calling `as_bytes` or `to_vec`
(basically joining transform and data). There are also valid usages when
one might require just one property of bytes (textures can generally
handle both RGBA and BGRA). There are also valid usages of using just
raw bytes (when cropping). This PR tries to make such usages more
obvious.

This will make it easier to fix stuff around 2d canvas (we do not want
to assume any bytes properties in abstraction).

Testing: Code is covered by WPT tests.

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2025-07-03 15:02:41 +00:00
Narfinger
ca47cc2fa3
Add a basic caching mechanism for ImageKeys. (#37369)
This creates a new method in shared/compositing/lib to generate image
keys that are send over the webview. This does not immediately return
the keys but goes over the constellation to receive the keys from the
IOCompositor. To make this more efficient, we now cache the keys in
image_cache in a simple FIFO order. The old blocking method stays intact
for now but got renamed to make the blocking clear.
The blocking calls that are left are in:
- `components/canvas/canvas_data.rs`
- `components/script/dom/htmlmediaelement.rs`

Testing: WPT tests should cover this as this doesn't change any
functionality.
Fixes: Was mentioned in
https://github.com/servo/servo/issues/37161#issuecomment-2915750051 and
part of https://github.com/servo/servo/issues/37086

---------

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com>
Co-authored-by: gterzian <2792687+gterzian@users.noreply.github.com>
2025-07-03 13:16:43 +00:00
Martin Robinson
6dafeb7a59
layout: Add a first pass at incremental box tree construction (#37751)
This change:

- Adds a new type of LayoutDamage that signifies that a box needs its
  children recollected, because one or more of them need to be rebuilt.
- During restyle damage propagation, propagate this new damage upward in
  the tree. Then box tree construction should be able to preserve any
  still-valid box tree nodes from box slots.
- During BlockLevelBox job finalization, if a box slot is valid and
  there is not LayoutDamage to the element, use the old box slot,
  ensuring that its fragment cache is invalidated.

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

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: coding-joedow <ibluegalaxy_taoj@163.com>
2025-07-03 08:13:20 +00:00
Oriol Brufau
da364f7a61
script: Remove the quirk of flooring rowSpan by 1 (#37831)
Only Firefox has this quirk, Chrome and Safari don't. So it's simpler to
just remove it.

Testing: tested by WPT

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2025-07-02 12:16:28 +00:00
Oriol Brufau
95d9d3a412
script: Only enforce rowSpan >= 1 in actual quirks mode (#37820)
We were also enforcing that in limited-quirks mode, but no other browser
does that. In fact, Blink and WebKit don't have this quirk at all, so we
should consider removing it too, but for now restrict it to quirks mode
like Firefox.

Testing: adding new tests
Part of #37813

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2025-07-02 09:52:00 +00:00
Andrei Volykhin
4cbadde144
htmlimageelement: Reject decode promises on the current request mutation (#37828)
Follow the HTML specification and reject the pending image decode
promises
on any current request mutation.
https://html.spec.whatwg.org/multipage/#updating-the-image-data (step
18)
https://html.spec.whatwg.org/multipage/#dom-img-decode (step 3)

Fulfill and reject image decode promises by queueing
a global tasks on the DOM manipulation task source.

Testing: Improvements in the following tests
- html/semantics/embedded-content/the-img-element/decode/*

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-07-02 09:29:47 +00:00
sagudev
944713ddd0
canvas: use Transform2D instead of Transform3D when possible (#37759)
While this makes our implementation deviate slightly from the
specification, this clarifies an invariant with the code itself. This
helps to resolve some confusion as seen in
https://github.com/servo/servo/issues/37695#issuecomment-3013823350.

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

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-07-02 08:44:56 +00:00
Simon Wülker
e2ad9c14c6
deps: Bump html5ever and friends to version 0.35.0 (#37736)
Companion PR for https://github.com/servo/html5ever/pull/637.

Testing: Covered by existing web platform tests

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-07-02 08:44:39 +00:00
Andrei Volykhin
d0579256bb
canvas: Unify retrieving image data from the HTMLImageElement (#37809)
Currently, HTMLImageElement uses as an image source
(ImageBitmapSource, CanvasImageSource, TexImageSource)
in various canvas2D/WebGL operations, and there is a small
inconsistency in how we get the image data of the 'img' element:
usability checking and retrieving the image data from the image cache.

To simplify and avoid state inconsistency between the window's image
cache and the 'img' element, let's retrieve the image data (as a raster)
from the HTMLImageElement itself.

Testing: No expected changes in testing results, except the
'drawimage_svg_image_with_foreign_object_does_not_taint.html'
which is 'false' passed because drawing of the non supported vector
image
is silently skip instead of throwing the 'InvalidState' exception
anymore.

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-07-02 08:13:30 +00:00
Rodion Borovyk
60c10d710d
Set the placeholder canvas element of offscreenCanvas to a weak reference in transferControlToOffscreen() (#37764)
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>
2025-06-30 13:30:58 +00:00
Euclid Ye
78cd770697
Codegen: Fix typo in doc (#37777)
Fix typo.
Testing: No.

Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
2025-06-29 11:13:50 +00:00
Tim van der Lippe
e1c037815c
Fix skipping CSP checks for styles when cloning nodes (#37465)
Cloned nodes were re-parsing already-parsed style attributes. As such,
they were also checking CSP, which shouldn't happen as the original node
already was checked for it.

Testing: The existing WPT test now mostly passes. It had two cases which
were passing in no browsers.
Fixes: Part of #4577

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2025-06-28 17:31:03 +00:00
Martin Robinson
5e44582277
script: Clean up Window::force_reflow a little (#37725)
- Move some of the image handling code to a separate function.
 - Move reflow event debugging into layout itself and use the `Debug`
   implementation to print the event.
 - A few other small cleanups

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

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2025-06-27 12:27:15 +00:00
Martin Robinson
8e2ef5c248
layout: Do not require restyle information when not restyling (#37722)
This reduces the amount of work necessary when running layout, by making
restyle information optional in the `ReflowRequest`. When restyling
isn't
necessary, the option is `None`.

Testing: This shouldn't change any observable behavior and thus is
covered
by existing WPT tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2025-06-27 08:08:29 +00:00
Simon Wülker
cbb0407ae6
Determine the initial state for fragment parsing using the scripting flag of the context element (#37704)
When parsing a html fragment, the initial parser state depends on
whether or not scripting is enabled. So far we've used the scripting
flag of the parser, but that is wrong - the parser's scripting flag is
always false, because the fragment document has no browsing context.
Instead we should use the scripting flag of the context element.

Testing: A new web platform test passes

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-06-26 20:40:13 +00:00
sagudev
4dded465a4
compositor: only UpdateImages that accepts SmallVec and add helpers for single image (#37730)
Before we only offered helper to add single image (no update or delete)
that got special IPC message, now we simplify this by offering all ops
helpers for dealing with single image (that happens most of the time),
that simply uses `update_images` under the hood. We also optimize for
this use case by using `SmallVec<[ImageUpdate; 1]>` to avoid alloc.

Testing: Just refactor, but code is covered by WPT tests

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-06-26 14:57:15 +00:00
Andrei Volykhin
3c16db2642
canvas: Add CanvasPattern 'setTranform(transform)' method (#37731)
Follow the HTML canvas specification and add missing
'setTransform(transform)' method to CanvasPattern interface.
https://html.spec.whatwg.org/multipage/#dom-canvaspattern-settransform

Testing: Improvements in the tests
- html/canvas/element/fill-and-stroke-styles/2d.pattern.transform*
- html/canvas/offscreen/fill-and-stroke-styles/2d.pattern.transform*

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-06-26 14:38:30 +00:00
Martin Robinson
3e1cdacd07
script|layout: Do not force restyle when doing script queries (#37677)
Instead of doing a restyle whenever layout is requested, only do one if
script believes that the `Document` has changed in a way that needs a
restyle. In addition, track the different reasons this might be the
case. This will be used later to provide better debugging output.

In layout, when a restyle isn't requested, provide:
 - an early return if layout is up-to-date enough for the reflow goal.
 - skipping restyle and reflow if it isn't necessary.

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

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2025-06-26 08:02:15 +00:00
Martin Robinson
f745bad37d
script: Consolidate step 22 of per-Document rendering update (#37703)
The parts of step 22 were a bit scattered throughout the codebase, so
this
change moves them all to a single method which does three things:

1. Update all animating images
2. Flush all dirty canvases (2D, WebGL, and WebGPU)
3. Calls reflow on the `Document`

Testing: This shouldn't change behavior in any major way so it should
be covered by existing WPT tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-06-26 06:11:03 +00:00
sagudev
6f53d422b0
Make ImageData more spec compliant (#37620)
I updated webidl, and all changes that bring, currently we still not
support float16array (there is no support in FF either). Most notable
change is refactored new_*/Constructors methods, that should now handle
HeapBufferSource more properly (with less unsafe).

Testing: Existing WPT tests
try run: https://github.com/sagudev/servo/actions/runs/15806083404
Fixes: #37618 (although not tested)

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-06-25 16:48:58 +00:00
Andrei Volykhin
59b99de90a
canvas: Add CanvasTransform 'setTransform(transform)' method (#37692)
Follow the HTML canvas specification and add missing
'setTransform(transform)' method to CanvasTransform interface.

https://html.spec.whatwg.org/multipage/#dom-context-2d-settransform-matrix

The third-party WebIDL doesn't support different extended attributes
on different overloads of methods, so 'Throws' attribute was added
to another 'setTransform(...)' method.
https://bugzilla.mozilla.org/show_bug.cgi?id=1020975

Testing: Improvements in the tests
- css/geometry/DOMMatrix*
-
html/canvas/element/transformations/2d.transformation.setTransform.multiple.html
-
html/canvas/offscreen/transformations/2d.transformation.setTransform.multiple

New failing tests due to disabled 'paint worklet' feature
- css/css-paint-api/setTransform-00*.https.html

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-06-25 16:11:54 +00:00
Narfinger
64259de1f7
script: Do not run garbage collection when shutting down a Pipeline (#37691)
Removes a GC cleanup step on exit pipeline that took half a second at
the end
of the Speedmometer benchmark. As layout and script are now run serially
this
does not seem to be needed anymore. See also the very short discussion
on Zulip:
[#performance > GC in
handle_exit_pipeline](https://servo.zulipchat.com/#narrow/channel/416779-performance/topic/GC.20in.20handle_exit_pipeline/with/525697861).

Testing: Tested with Speedometer and the WPT tests should still work.

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
2025-06-25 15:13:54 +00:00
Martin Robinson
a66a257b38
script: Properly root nodes with animating images (#37689)
This change fixes an issue and makes a few more minor improvements to
the `ImageAnimationState`:

1. Image rooting and unrooted now happens in one step from
   `Window::update_animations_post_reflow`.
2. The `node_to_animating_image_map` is now stored as a shared `RwLock`
   so that it doesn't need to be taken and then replaced in the
`ImageAnimationState` during reflow. This should prevent a hypothetical
issue
   where image animations are restarted during empty reflows.
3. General naming and idiomatic Rust usage improvements.

Testing: This doesn't really have any obvious behavioral changes,
because all
reflows currently trigger a restyle. It becomes a serious problem with
#37677
and this change fixes the failing test there.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-06-25 13:52:11 +00:00
Martin Robinson
0346a62214
script: Pass more information to the MouseEvent constructor (#37672)
- Instead of eagerly computing `pageX` and `pageY`, collect the offset
  from the content's initial containing block in the compositor and pass
  that information through to `MouseEvent`. This prevents a layout flush
  that was happening when eagerly trying to fetch `Document` scroll
  offsets.
- Pass keyboard modifiers properly to `MouseEvent`.
- Now all this information is stored and passed as `Point2D` (typed) and
  `Modifiers` which greatly reduces the amount of arguments that need to
  be passed around.

Testing: It is difficult to test input events as they require WebDriver
which
isn't completely working yet. I have manually run Speedometer 2.1 and I
have
verified that this fixes the regression from #37601.
Fixes: #37601.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-06-25 12:29:27 +00:00
Jonathan Schwender
50cf01cf3d
script: const initialize LIVE_REFERENCES (#37688)
With Rust 1.85 it is possible to const initialize Hashmaps if the hash
algorithm does not rely on a random seed.

Testing: No functional changes, covered by existing tests

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
2025-06-25 11:27:56 +00:00
Jonathan Schwender
922d4b83de
Use FnvHashmap for LiveDOMReferences (#37673)
These maps are keyed on pointers, so using FnvHashMap should be faster
and we don't need the collision resistance properties of the default
hasher.

These maps showed up as hot when profiling the testcase from
https://github.com/servo/servo/issues/37223#issuecomment-3000705438.
Switching the hashing algorithm reduces the time spent hashing, but
overall that is still only a fractional part of the testcase.

Testing: Functionality unchanged. Overall the performance change is to
small to show up in any of our automated performance tests. When
comparing the perf profile of the above linked testcase, one should see
a reduction of time spent hashing (inverse call stack)

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
2025-06-25 06:47:20 +00:00
Simon Wülker
2dc62c504f
Implement declarative shadow root support for async HTML parser (#37443)
Implements the
[`TreeSink::attach_declarative_shadow`](https://docs.rs/html5ever/latest/html5ever/interface/trait.TreeSink.html#method.attach_declarative_shadow)
method for the async html parser.

Try run with the async html parser:
https://github.com/simonwuelker/servo/actions/runs/15634240606/job/44046871826.
(There are far fewer failures than in the initial try run from
https://github.com/servo/servo/issues/37418)

Testing: We don't run tests with the async html parser
Part of https://github.com/servo/servo/issues/37418

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-06-24 12:45:50 +00:00
Andrei Volykhin
9487f66eaa
webgl: Ignore pixel storage parameters for ImageBitmap source (#37635)
Follow the WebGL specification and ignore the values of UNPACK_FLIP_Y,
UNPACK_PREMULTIPLY_ALPHA, and UNPACK_COLORSPACE_CONVERSION
if the TexImageSource is an ImageBitmap.
https://registry.khronos.org/webgl/specs/latest/1.0/#6.10

Testing: There are no dedicated test results changes without the PR
#37634
which unblocks new testing scenarios with premultiplied ImageBitmap from
Blob/Canvas/Image sources.

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-06-24 11:15:50 +00:00
Tim van der Lippe
fc20d8b2e1
Move CSP code into one entrypoint (#37604)
This refactoring moves various CSP-related methods away from GlobalScope
and Document into a dedicated entrypoint. It also reduces the amount of
imports of the CSP crate, so that types are consolidated into this one
entrypoint. That way, we control how CSP code interacts with the script
crate.

For reviewing purposes, I split up the refactoring into separate
distinct commits that all move 1 method(group) into the new file.

Testing: no change in behavior, only a build improvement + code cleanup

---------

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Signed-off-by: Tim van der Lippe <TimvdLippe@users.noreply.github.com>
2025-06-24 08:50:30 +00:00
Narfinger
208d4c620a
Allow console commands to appear in log files (#37631)
This enables console.* commands in javascript to be forwarded to the
logger and not just stdout.
The domain for this will be `script::dom::console` which seems
appropate.

Testing: Logs do not have any tests.

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
2025-06-23 18:42:36 +00:00