Commit graph

849 commits

Author SHA1 Message Date
Rosemary Ajayi
52a74287fc
clippy: Fix a few problems in components/scripts (#31959)
* fixed various clippy warnings

* fixed various clippy warnings
2024-04-01 05:34:48 +00:00
Azhar Ismagulova
92d9081366
fix: remove unused imports in components/script (#31943) 2024-03-29 18:15:13 +00:00
Oluwatobi Sofela
4a68243f65
clippy: Fix needless_lifetimes warnings (#31933) 2024-03-29 11:59:07 +00:00
Oluwatobi Sofela
a8976ff00a
clippy: Fix option_as_ref_deref warnings (#31936) 2024-03-29 11:52:45 +00:00
Oluwatobi Sofela
7349ce5b6a
clippy: Fix manual_map warnings (#31922) 2024-03-28 15:58:36 +00:00
Azhar Ismagulova
f183170786
clippy: Fix all errors in components/script (#31911)
* clippy: Fix errors in components/script/dom

* clippy: fixed remaining errors in components/script
2024-03-28 09:03:18 +00:00
Oluwatobi Sofela
b71de92569
clippy: Fix single_match warnings (#31876) 2024-03-26 14:01:10 +00:00
Aarya Khandelwal
f7669b5238
fixes dereferencing on an immutable reference (#31864) 2024-03-26 08:37:44 +00:00
Aarya Khandelwal
bd39e03eeb
changed match to 'matches!' (#31850) 2024-03-25 11:28:12 +00:00
Oluwatobi Sofela
3c05b58221
clippy: Fix explicit_auto_deref warnings in components/script (#31837)
* clippy: Fix explicit auto-deref warnings

* clippy: Fix explicit auto-deref warnings

* refactor: Tidy up code

* refactor: Fix method not found errors
2024-03-23 11:29:20 +00:00
Delan Azabani
8882507ad0
Rework “visible” to “throttled” in constellation + script + compositor (#31816) 2024-03-22 06:06:28 +00:00
Aarya Khandelwal
9b26dca141
Fixed the .clone() warnings. (#31819) 2024-03-22 05:41:17 +00:00
Oluwatobi Sofela
2789e98876
clippy: Fix redundant field names warnings (#31793) 2024-03-20 23:05:29 +00:00
Oluwatobi Sofela
15bf32a4e6
clippy: Fix unneeded return statement warnings (#31776) 2024-03-20 14:11:40 +00:00
Oluwatobi Sofela
02a0cdd6fa
clippy: Fix dereferenced warnings (#31770) 2024-03-20 08:07:22 +00:00
Rosemary Ajayi
865f6e621f
clippy: Fix clippy Problems in components/scripts (#31759)
* revert cargo

* revert cargo

* fic clippy problems
2024-03-19 22:22:37 +00:00
Richard Dushime
01ca220f83
clippy: Fix many warnings in components/script (#31717)
* Fix Several clippy warnings

* Fix Build errors

* Fix Unused import

* Fix requested changes

* Fix rustfmt

* Minor fixes

---------

Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2024-03-19 16:05:56 +00:00
Martin Robinson
9c0561536d
script: Do not run layout in a thread (#31346)
* script: Do not run layout in a thread

Instead of spawning a thread for layout that almost always runs
synchronously with script, simply run layout in the script thread.

This is a resurrection of #28708, taking just the bits that remove the
layout thread. It's a complex change and thus is just a first step
toward cleaning up the interface between script and layout. Messages are
still passed from script to layout via a `process()` method and script
proxies some messages to layout from other threads as well.

Big changes:

1. Layout is created in the script thread on Document load, thus every
   live document is guaranteed to have a layout. This isn't completely
   hidden in the interface, but we can safely `unwrap()` on a Document's
   layout.
2. Layout configuration is abstracted away into a LayoutConfig struct
   and the LayoutFactory is a struct passed around by the Constellation.
   This is to avoid having to monomorphize the entire script thread
   for each layout.
3. Instead of having the Constellation block on the layout thread to
   figure out the current epoch and whether there are pending web fonts
   loading, updates are sent synchronously to the Constellation when
   rendering to a screenshot. This practically only used by the WPT.

A couple tests start to fail, which is probably inevitable since removing
the layout thread has introduced timing changes in "exit after load" and
screenshot behavior.

Co-authored-by: Josh Matthews <josh@joshmatthews.net>

* Update test expectations

* Fix some issues found during review

* Clarify some comments

* Address review comments

---------

Co-authored-by: Josh Matthews <josh@joshmatthews.net>
2024-02-23 08:14:10 +00:00
Daniel Adams
c999d4546c
Implement non-XR Gamepad discovery and input (#31200)
* Create embedder event to send to constellation

* Handle gamepad message in constellation, send to script thread

* Handle GamepadEvent in script thread and dispatch event to document

* Add missing Clones, fix event

* Add gamepad task source

* Adjust GamepadIndex type, remove unused imports

* Add internal getter for gamepads list

* Update gamepad new methods

* Handle gamepad connect and disconnect events

* Proto will be none, no need for HandleObject

* Initialize buttons and axes to standard mapping

* Adjust update type index types

* Update GamepadButton update function

* Adjust Gamepad mapping comments to match spec, add update logic

* Amend comment

* Update button and axis inputs on Updated event

* Add GilRs as gamepad backend in servoshell

* Add spec links, queue gamepad updates on task source

* ./mach fmt

* Fix comment length

* Split out button init, update spec comments

* Move gamepad event handling from document to global

* Map and normalize axes/button values

* Use std::time for gamepad timestamp

* Adjust gamepad handling in event loop

* Move button press/touch check into map+normalize function

- Small change but is more in line with spec

* ./mach fmt

* Update comment spec links and warning messages

* Doc comments -> regular comments

* Add window event handlers for gamepad connect/disconnect

* Adjust gamepad disconnect behavior

* Add missing TODO's, adjust gamepad/gamepadbutton list methods and formatting

* Update button handling from gilrs, add comments

* Enable gamepad pref during WPT tests and update expectations

* Update WPT expectations in meta-legacy-layout
2024-02-17 18:42:31 +00:00
Martin Robinson
5c1723c983
rustdoc: Fix many rustdoc errors (#31147)
This fixes many rustdoc errors that occur due to raw URLs in rustdoc
comments as well as unescaped Rust code that should be in backticks.
2024-01-22 13:13:48 +00:00
Auguste Baum
9654363c18
script: Start replacing time with std::time and chrono (#30639)
* Replace `time` with `chrono` in `script/animation_timeline`

Signed-off-by: Auguste Baum <auguste.apple@gmail.com>

* Replace `time` with `std::time` in `script/script_thread.rs`

Signed-off-by: Auguste Baum <auguste.apple@gmail.com>

* Replace `time` with `std::time` and `chrono` in `script/script_thread.rs`

Signed-off-by: Auguste Baum <auguste.apple@gmail.com>

* Replace `time` with `std::time` in `script/script_runtime.rs`

Signed-off-by: Auguste Baum <auguste.apple@gmail.com>

* Replace `time` with `std::time` in `script/script_runtime.rs`

Signed-off-by: Auguste Baum <auguste.apple@gmail.com>

* Replace `time` with `std::time` in `script/dom/workerglobalscope.rs`

Signed-off-by: Auguste Baum <auguste.apple@gmail.com>

* Replace `time` with `chrono` in `script/dom/workerglobalscope.rs`

Signed-off-by: Auguste Baum <auguste.apple@gmail.com>

* Replace `time` with `std::time` in `script/dom/htmlmedialelement.rs`

Signed-off-by: Auguste Baum <auguste.apple@gmail.com>

* Replace `time` with `std::time` in `script/dom/htmlmedialelement.rs`

Signed-off-by: Auguste Baum <auguste.apple@gmail.com>

* Replace `time` with `std::time` in `script/dom/globalscope.rs`

Signed-off-by: Auguste Baum <auguste.apple@gmail.com>

* Replace `time` with `chrono` in `script/dom/globalscope.rs`

Signed-off-by: Auguste Baum <auguste.apple@gmail.com>

* Replace `time` with `std::time` in `script/dom/htmlformelement.rs`

Signed-off-by: Auguste Baum <auguste.apple@gmail.com>

* Replace `time` with `std::time` in `script/dom/htmlformelement.rs`

Signed-off-by: Auguste Baum <auguste.apple@gmail.com>

* Increase precision of animation timeline

* Some fixes

Use Instant a bit more and stop using chrono. Do not transition
`navigation_start_precise` to Instant yet as we need to coordinate this
across all crates.

---------

Signed-off-by: Auguste Baum <auguste.apple@gmail.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2024-01-16 12:23:18 +00:00
Samson
604979e367
Replace script_plugins with a clippy like rustc driver (named crown) (#30508)
* Remove script_plugins

* Use crown instead of script_plugins

* crown_is_not_used

* Use crown in command base

* bootstrap crown

* tidy happy

* disable sccache

* Bring crown in tree

* Install crown from tree

* fix windows ci

* fix warning

* fix mac

libscript_plugins.dylib is not available anymore

* Update components/script/lib.rs

Co-authored-by: Martin Robinson <mrobinson@igalia.com>

* Update for nightly-2023-03-18

Mostly just based off https://github.com/servo/servo/pull/30630

* Always install crown

it's slow only when there is new version

* Run crown test with `mach test-unit`

* Small fixups; better trace_in_no_trace tests

* Better doc

* crown in config.toml

* Fix tidy for real

* no sccache on rustc_wrapper

* document rustc overrides

* fixup of compiletest

* Make a few minor comment adjustments

* Fix a typo in python/servo/platform/base.py

Co-authored-by: Samson <16504129+sagudev@users.noreply.github.com>

* Proper test types

* Ignore tidy on crown/tests

---------

Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2023-12-01 15:50:52 +00:00
Delan Azabani
098e6a1580
constellation: clean up logging of pipelines and browsing contexts (#30657)
* constellation: clean up logging of pipelines and browsing contexts

* bring back sentence case; remove commented code

* fix more typos and wordings
2023-11-14 04:53:31 +00:00
Samson
bd9c17234c
fix handle_wgpu_msg crash (#30479)
* Enter realm before handle_wgpu_msg

fix https://github.com/servo/servo/issues/30419

* Update expectations
2023-10-03 15:16:42 +00:00
Samson
aad2dccc9c
Strict import formatting (grouping and granularity) (#30325)
* strict imports formatting

* Reformat all imports
2023-09-11 19:16:54 +00:00
Samson
711dbbd4af
remove extern crate (#30311)
* remove extern crate

* Update components/script_plugins/lib.rs

Co-authored-by: Martin Robinson <mrobinson@igalia.com>

---------

Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2023-09-08 12:11:31 +00:00
Delan Azabani
c3c6c95a9b
constellation: crash to a new “sad tab” error page (#30290)
* constellation: crash to a new “sad tab” page

* check in resources/crash.html

* use a separate enum variant instead of keying on reason

* fmt + tidy

* rename Resource::Crash to Resource::CrashHTML

* clean up crash page and add details (reason + backtrace)

* avoid repeating crash errors in script::script_thread warn log

* make new LoadData init more idiomatic

* clarify comments and new fields

* fix doc comment style
2023-09-06 09:52:37 +00:00
Oriol Brufau
8a7fe40249
Remove unused import EventLoopWaker (#30110)
Seems a remnant from #30101
2023-08-17 05:15:52 +00:00
Atbrakhi
8255e8e318
Remove EventLoopWaker from Constellation (#30101)
* remove event_loop_waker that is always None

* remove None event_loop_waker form InitialScriptState

* fix formatting

* remove None event_loop_waker from ScriptThread

* remove None EventLoopWaker from Window

* remove None and use of wake_after_send in webgl code
2023-08-15 18:02:02 +00:00
Samson
450f8193a5
Use mozjs tracing infrastructure (#29918)
* Update mozjs

64711ec2e6 also fixes https://github.com/servo/servo/issues/30043

* Move to mozjs Traceable and introduce CustomTraceable
2023-08-10 21:46:06 +00:00
Samson
9514f670d1
No tracing of nop traceable fields (#29926)
* Add `no_trace` option to JSTraceable derive

* NoTrace wrapper

* Port some types to no_trace schematics

* Fixing my unsafe mistakes (not tracing traceables)

* Add docs & safety guards for no_trace

Safety guards (trait shenanigans) guarantees safety usage of `no_trace`

* Port canvas_traits to no_trace

* Port servo_media to no_trace

* Port net_traits to no_trace

* Port style to no_trace

* Port webgpu to no_trace

* Port script_traits to no_trace

* Port canvas_traits, devtools_traits, embedder_traits, profile_traits to no_trace

* unrooted_must_root lint in seperate file

* Add trace_in_no_trace_lint as script_plugin

* Composable types in must_not_have_traceable

* Introduced HashMapTracedValues wrapper

* `HashMap<NoTrace<K>,V>`->`HashMapTracedValues<K,V>`

* Port rest of servo's types to no_trace

* Port html5ever, euclid, mime and http to no_trace

* Port remaining externals to no_trace

* Port webxr and Arc<Mutex<_>>

* Fix spelling in notrace doc
2023-08-04 10:17:43 +00:00
Josh Matthews
dcf02caf81 Enter realms when creating special same-origin iframes. 2023-05-20 18:32:08 -04:00
Josh Matthews
02a280dbe1 Enter realms when processing pre-sequential events. 2023-05-20 17:14:45 -04:00
Josh Matthews
864e072d5c Enter realms more consistently during the script event loop. 2023-05-20 14:30:22 -04:00
Josh Matthews
f79e1e327d Make GlobalScope.get_cx a static method. 2023-05-20 11:05:09 -04:00
bors-servo
a8f7c45811
Auto merge of #29693 - mrobinson:cleanup-options, r=mukilan
Clean up how command-line options are passed around

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #29678
- [x] These changes do not require tests because they do not change behavior.
2023-05-03 10:44:48 +02:00
Martin Robinson
17e3f34e65 Fix flakiness in animation tests
1. When updating the animation timeline, ensure that nodes that are
   animating are marked dirty, if necessary, so any style queries will
   force an layout flush.
2. Disable the problematic transition test suites, as they are in Gecko.
   These suites often fail when Servo is so overloaded that it cannot
   deliver frames fast enough to get more than two samples during the
   animation lifecycle.

Fixes #28334.
Fixes #26435.
Fixes #21486.
2023-05-02 08:37:15 +02:00
Martin Robinson
0a3797d130 Clean up arguments passed to ScriptThread 2023-05-01 14:10:32 +02:00
yvt
effd5a3107 fix(script): request animation ticks if Animations::pending_events is not empty
Fixes the test case `/_mozilla/css/css-transition-cancel-event
.html`, which was failing under a specific circumstance.

The observed sequence of events during the failing test run looks like
this:

1. Transitions start in `div1` and `div2`.

2. `div1` generates a `transitionend` event.

3. The `transitionend` event handler removes `div2` from DOM, cancelling
   its ongoing transition.

4. `div2` is supposed to generate a `transitioncancel` event in a timely
   manner, which it does not. The test fails as a result.

What is going on here? Here's a possible explaination:

1. During one invocation of `ScriptThread::handle_msgs`...

2. In step 2, `ScriptThread::update_animations_send_events` -> `Document
   ::update_for_new_timeline_value` detects the completion of the
   transition, and in response, pends the `transitionend` event.

3. In step 3, `ScriptThread::update_animations_send_events` ->
   `Animations::send_pending_events` calls the `transitionend` handler.

4. The `transitionend` event handler removes `div2`, thereby cancelling
   its ongoing transition and triggering a reflow.

5. Reflow takes place. During this, `Animations::do_post_reflow_update`
   -> `Animations::handle_canceled_animations` pends the
   `transitioncancel` event (precursor to step 4).

6. Having discovering that there was no running animation, `Animations::
   do_post_reflow_update` calls `self.update_running_animation_presence
   (_, false)`, which sends `AnimationState::NoAnimationsPresent`.

7. The invocation of `ScriptThread::handle_msgs` ends, and another
   starts. It blocks waiting for events.

8. Meanwhile, the compositor receives `AnimationState::
   NoAnimationsPresent` and stops further generation of animation ticks.

9. With no events to wake it up, the script thread is stuck waiting
   despite having the pending `transitioncancel` event (step 4).

The HTML specification [says][1] that "an event loop must continually
run [...] as long as it exists" and does not say it can block if there
is nothing to do. Blocking is merely optimization in a user agent
implementation. Pending animation-related events must be processed every
time a "rendering opportunity" arises unless the user agent has a reason
to believe that it "would have no visible effect".

Skipping the processing of animation-related events would have visible
effect if such events are indeed present. The correct implementation in
Servo, therefore, would be to request more animation ticks so that such
events are processed in a subsequent tick.

[1]: https://html.spec.whatwg.org/multipage/#event-loop-processing-model
2023-02-10 14:44:27 +01:00
yvt
af1b0b0f14 fix(script): update animation timeline before processing pending events
This commit reverses the order of the `send_pending_events` and
`update_animation_timeline` calls in `ScriptThread::update_animations_
send_events` so that animation-related events pended by the latter are
processed by the former.

The new calling order is more compliant with the "update animations and
send events" algorithm steps from [the Web Animations specification][1].

The old implementation was prone to blocking for an indefinite period
while holding pending events. Due to complex interaction with other
events and timing behavior, I was only able to reproduce the problem
under the following conditions:

- *The `maybe_observe_paint_time` call in `LayoutThread::compute_abs_
  pos_and_build_display_list` is removed from the code*. While
  performance events may seem irrelevant to the issue, they would
  bombard the script thread with events. *Any* extra messages received
  would unblock the event loop and prevent the manifestation of the
  issue. (But, of course, we aren't supposed to count on that to avoid
  the issue.)

- Servo is running in a headless mode, which somehow makes it less
  likely for the script thread to receive a `TickAllAnimations` event
  after sending `AnimationState::NoAnimationsPresent`.

With the above conditions met and the stars aligned, you can reproduce
the problem by running the WPT test `/css/css-transitions/events-001.
html`.

[1]: https://drafts.csswg.org/web-animations-1/#update-animations-and-send-events
2023-02-10 12:42:51 +01:00
yvt
3090505fd4 refactor(script): navigate_or_reload_child_browsing_context should only handle cases involving navigation
The initial document creation does not involve navigation, and it would
cause a confusion if this was done by a function which has `navigation`
in its name. This commit renames `navigate_or_reload_child_browsing_
context` to `start_new_pipeline`, and introduces a new function which
has the original name and is dedicated to handle navigation.
2021-08-03 09:11:19 +09:00
bors-servo
bd92fad81a
Auto merge of #28546 - yvt:feat-cow-infra, r=jdm
Implement `Location`'s custom internal methods

This PR partly resurrects #16501 and introduces the use of principals object to associate objects and Realms with origins. Using this infrastructure, this PR implements [the custom internal methods][1] of the `Location` interface, which is "maybe-cross-origin".

Unimplemented/incomplete things:

 - Other maybe-cross-origin interfaces, namely `WindowProxy` and `DissimilarWindowLocation`, aren't implemented correctly yet (causing most test cases of `tests/wpt/web-platform-tests/html/browsers/origin/cross-origin-objects/cross-origin-objects.html` to fail).
     - `WindowProxy`: #28556
 - [The "perform a security check" operation][2] and `Location`'s non-cross-origin properties' relevant `Document` origin checks aren't implemented either (not sure if they are covered by the existing tests).
 - There are a slight deviation from the standard and inefficiency in `CrossOriginGetOwnPropertyHelper`'s current implementation.
     - #28557

[1]: https://html.spec.whatwg.org/multipage/#the-location-interface
[2]: https://html.spec.whatwg.org/multipage/browsers.html#integration-with-idl

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #16243 and make some progress in #2382

---
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because ___
2021-08-01 10:31:40 -04:00
yvt
41b3726271 feat: shorten thread names
The Linux kernel imposes a 15-byte limit on thread names[1]. This means
information that does not fit in this limit, e.g., the pipeline ID of
layout and script threads, is lost in a debugger and profiler (see the
first column of the table below).

This commit shortens the thread names used in Servo to maximize the
amount of information conveyed. It also rectifies some inconsistencies
in the names.

|       Before      |       After       |
|-------------------|-------------------|
| `BluetoothThread` | `Bluetooth`       |
| `CanvasThread`    | `Canvas`          |
| `display alert d` | `AlertDialog`     |
| `FontCacheThread` | `FontCache`       |
| `GLPlayerThread`  | `GLPlayer`        |
| `HTML Parser`     | `Parse:www.examp` |
| `LayoutThread Pi` | `Layout(1,1)`     |
| `Memory profiler` | `MemoryProfiler`  |
| `Memory profiler` | `MemoryProfTimer` |
| `OfflineAudioCon` | `OfflineACResolv` |
| `PullTimelineMar` | `PullTimelineDat` |
| `ScriptThread Pi` | `Script(1,1)`     |
| `WebWorker for h` | `WW:www.example.` |
| `ServiceWorker f` | `SW:www.example.` |
| `ServiceWorkerMa` | `SvcWorkerManage` |
| `Time profiler t` | `TimeProfTimer`   |
| `Time profiler`   | `TimeProfiler`    |
| `WebGL thread`    | `WebGL`           |
| `Choose a device` | `DevicePicker`    |
| `Pick a file`     | `FilePicker`      |
| `Pick files`      | `FilePicker`      |

[1]: https://stackoverflow.com/questions/5026531/thread-name-longer-than-15-chars
2021-07-19 00:57:48 +09:00
yvt
bfa2026220 feat(script): remove the call to JS_SetWrapObjectCallbacks
We don't make CCWs anymore.
2021-07-11 23:30:40 +09:00
teymour-aldridge
217147b2e4 fmt 2021-02-05 14:46:09 +00:00
teymour-aldridge
ff767b13a9 Remove unused arguments from methods. 2021-02-05 14:29:45 +00:00
teymour-aldridge
466e895cdf Fix errors 2021-02-05 14:29:30 +00:00
Andreu Botella
cd34f156f6 Fix document.characterSet not reflecting byte order marks.
The process of decoding the network byte stream to Unicode is backed by
an instance of `encoding_rs::Decoder`, which will switch the encoding it
uses if it finds a BOM in the byte stream. However, this change in
encoding is not communicated back to the caller and so
`document.characterSet` gives the wrong result. This change fixes that.

See whatwg/html#5359 and whatwg/encoding#203 for the spec-level backing
for this change.

Signed-off-by: Andreu Botella <abb@randomunok.com>
2020-12-31 13:43:33 +01:00
Jonathan Kingston
0e1479cc84 Add creation url and Secure Contexts 2020-11-25 18:30:50 +00:00
Utsav Oza
acbfd7b9ab Do not load srcdoc iframes synchronously 2020-08-05 18:44:28 +05:30