aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/worker.rs
Commit message (Collapse)AuthorAgeFilesLines
* Move `ScriptToConstellationMsg` to `constellation_traits` (#36364)Martin Robinson2025-04-051-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | This is the last big change necessary to create the `constellation_traits` crate. This moves the data structure for messages that originate from the `ScriptThread` and are sent to the `Contellation` to `constellation_traits`, effectively splitting `script_traits` in half. Before, `script_traits` was responsible for exposing the API of both the `ScriptThread` and the `Constellation` to the rest of Servo. - Data structures that are used by `ScriptToConstellationMsg` are moved to `constellation_traits`. The dependency graph looks a bit like this: `script_layout_interface` depends on `script_traits` depends on `constellation_traits` depends on `embedder_traits`. - Data structures that are used in the embedding layer (`UntrustedNodeAddress`, `CompositorHitTestResult`, `TouchEventResult` and `AnimationState`) are moved to embedder_traits, to avoid a dependency cycle between `webrender_traits` and `constellation_traits`. - Types dealing with MessagePorts and serialization are moved to `constellation_traits::message_port`. Testing: This is covered by existing tests as it just moves types around. Signed-off-by: Martin Robinson <mrobinson@igalia.com> Signed-off-by: Martin Robinson <mrobinson@igalia.com>
* Make DOMPoint and DOMPointReadOnly serializable (#35989)Josh Matthews2025-03-271-1/+1
| | | | | | | | | | | | | | | | | | | | | | | * script: Make DOMPointReadOnly serializable. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Make DOMPoint serializable. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Shrink worker script event. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Update components/script/dom/dompoint.rs Co-authored-by: Martin Robinson <mrobinson@igalia.com> Signed-off-by: Josh Matthews <josh@joshmatthews.net> --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net> Co-authored-by: Martin Robinson <mrobinson@igalia.com>
* devtools: Use `webview_id` as `browser_id` (#35956)atbrakhi2025-03-191-1/+3
| | | | | | | | | | | | | | | | | | | | | * use `webview_id` as `browser_id` Signed-off-by: atbrakhi <atbrakhi@igalia.com> * use correct webview id Signed-off-by: atbrakhi <atbrakhi@igalia.com> * fmt Signed-off-by: atbrakhi <atbrakhi@igalia.com> * review fix Signed-off-by: atbrakhi <atbrakhi@igalia.com> --------- Signed-off-by: atbrakhi <atbrakhi@igalia.com>
* Register iframes with the devtools (#35874)Simon Wülker2025-03-091-0/+1
| | | | | | | | | | | Previously, the devtools didn't know about <iframe>s. They either ignored messages coming from iframes or crashed. This reverts https://github.com/servo/servo/pull/34032 and then filters out non-tab globals in the "listTabs" message to the root actor. Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
* Update rustfmt to the 2024 style edition (#35764)Simon Wülker2025-03-031-3/+3
| | | | | | | | | | | | | * Use 2024 style edition Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Reformat all code Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> --------- Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
* Add support for Upgrade request to a potentially trustworthy URL. (#34986)Shubham Gupta2025-02-051-0/+1
| | | | | | | | | | | | | | | | * Add support for Upgrade request to a potentially trustworthy URL. Signed-off-by: Shubham Gupta <shubham13297@gmail.com> * script: Support inheritable insecure request policy in documents and workers. Signed-off-by: Josh Matthews <josh@joshmatthews.net> --------- Signed-off-by: Shubham Gupta <shubham13297@gmail.com> Signed-off-by: Josh Matthews <josh@joshmatthews.net> Co-authored-by: Shubham Gupta <shubham.gupta@chromium.org> Co-authored-by: Josh Matthews <josh@joshmatthews.net>
* Move various reflector types and traits to script_bindings (#35279)Josh Matthews2025-02-041-1/+1
| | | | | | | | | | | | | * script: Move Reflector to script_bindings. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Extract global() helper from DomObject into new trait. Move DomObject and related traits to script_bindings. Signed-off-by: Josh Matthews <josh@joshmatthews.net> --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* script: Feature-gate all crown support. (#35055)Josh Matthews2025-01-181-1/+1
| | | | | | | | | | | | | * script: Feature-gate all crown support. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Use cfg(crown) instead of a cargo feature. Signed-off-by: Josh Matthews <josh@joshmatthews.net> --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* script: Limit public exports. (#34915)Josh Matthews2025-01-101-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * script: Restrict reexport visibility of DOM types. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Mass pub->pub(crate) conversion. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Hide existing dead code warnings. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Formatting. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Fix clippy warnings. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Formatting. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Fix unit tests. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Fix clippy. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * More formatting. Signed-off-by: Josh Matthews <josh@joshmatthews.net> --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* script: Use `enum`s for event loop senders and receivers (#34896)Martin Robinson2025-01-081-3/+1
| | | | | | | | | | | | | | | | | | | | | | | Previously, senders and receivers to different kinds of event loops (the main `ScriptThread`, different types of workers) used a rust `trait` mechanism to implement dynamic behavior. This led to having many unused implementations of this `trait`. This change moves to using an `enum` based approach for these senders and receivers and removes all of the dead code. In addition, to allowing for use of rust's dead code detection, it simplifies the code a great deal. All of these generic senders and receivers are moved to the `messaging.rs` file and given proper documentation. Finally, empty an `JSTraceable` implementation is made for all crossbeam `Sender<...>`s to avoid having to manually skip them everytime they are included in structs. The pre-existing empty `MallocSizeOf` implementation is used more thoroughly. Other unecessary wrappers around these senders and receivers are removed as well. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
* script: Move `TaskManager` to `GlobalScope` (#34827)Martin Robinson2025-01-041-1/+4
| | | | | | | | | | | | | | | | | | | | This is a simplification of the internal `TaskQueue` API that moves the `TaskManager` to the `GlobalScope` itself. In addition, the handling of cancellers is moved to the `TaskManager` as well. This means that no arguments other than the `task` are necessary for queueing tasks, which makes the API a lot easier to use and cleaner. `TaskSource` now also keeps a copy of the canceller with it, so that they always know the proper way to cancel any tasks queued on them. There is one complication here. The event loop `sender` for dedicated workers is constantly changing as it is set to `None` when not handling messages. This is because this sender keeps a handle to the main thread's `Worker` object, preventing garbage collection while any messages are still in flight or being handled. This change allows setting the `sender` on the `TaskManager` to `None` to allow proper garbabge collection. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
* Add `webgpu` feature flag (#34444)atbrakhi2024-12-051-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Move script gpu files into webgpu folder Signed-off-by: atbrakhi <atbrakhi@igalia.com> * Modify gpu webidls Signed-off-by: atbrakhi <atbrakhi@igalia.com> * move gpu realted webidl Signed-off-by: atbrakhi <atbrakhi@igalia.com> * add webgpu feature to script Signed-off-by: atbrakhi <atbrakhi@igalia.com> * add dummy implementation for gpucanvascontext Signed-off-by: atbrakhi <atbrakhi@igalia.com> * fmt Signed-off-by: atbrakhi <atbrakhi@igalia.com> * add skip-if CARGO_FEATURE_WEBGPU Signed-off-by: atbrakhi <atbrakhi@igalia.com> * Move NavigatorGPU and workerNavigator GPU to webgpu idl Signed-off-by: atbrakhi <atbrakhi@igalia.com> * fmt and cleanup Signed-off-by: atbrakhi <atbrakhi@igalia.com> * review fix Signed-off-by: atbrakhi <atbrakhi@igalia.com> * enable webgpu by default and also some fmt fix Signed-off-by: atbrakhi <atbrakhi@igalia.com> * Add pref back, fix imports, small cleanups Signed-off-by: atbrakhi <atbrakhi@igalia.com> --------- Signed-off-by: atbrakhi <atbrakhi@igalia.com>
* Generate a trait abstracting over all known DOM interfaces (#34357)Josh Matthews2024-11-241-1/+1
| | | | | | | | | | | | | | | | | * script: Generate trait for all DOM interfaces and parameterize generated Methods traits over it. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Update trait implementations with new generic type. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Formatting. Signed-off-by: Josh Matthews <josh@joshmatthews.net> --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* Implement referrer policy for dom worker construction (#34192)shanehandley2024-11-091-2/+7
| | | Signed-off-by: Shane Handley <shanehandley@fastmail.com>
* CanGc fixes from EventTarget::fire_event (#33985)tanishka2024-10-231-3/+3
| | | Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>
* Prevent moving CanGc values between threads/tasks (#33902)Josh Matthews2024-10-181-1/+0
| | | | | | | | | | | | | * Make CanGc non-sendable, and add documentation. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Update CanGc usage to fix usages that were moved between threads/tasks. Signed-off-by: Josh Matthews <josh@joshmatthews.net> --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* More files with CanGc fixes (#33892)chickenleaf2024-10-181-3/+15
| | | | | | | | | | | | | * More files with CanGc fixes Signed-off-by: L Ashwin B <lashwinib@gmail.com> * removed the can_gc inside !task Signed-off-by: L Ashwin B <lashwinib@gmail.com> --------- Signed-off-by: L Ashwin B <lashwinib@gmail.com>
* Various CanGc fixes (#33800)webbeef2024-10-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * CanGc fix for pagetransitionevent Signed-off-by: webbeef <me@webbeef.org> * CanGc fix for dom/node Signed-off-by: webbeef <me@webbeef.org> * CanGc fix for gamepad Signed-off-by: webbeef <me@webbeef.org> * CanGc fix for gpu Signed-off-by: webbeef <me@webbeef.org> * CanGc fix for dom/element Signed-off-by: webbeef <me@webbeef.org> * CanGc fix for xhr Signed-off-by: webbeef <me@webbeef.org> * CanGc fix for dom/worker Signed-off-by: webbeef <me@webbeef.org> * CanGc fix for rtcdatachannel Signed-off-by: webbeef <me@webbeef.org> * CanGc fix for rtcerror Signed-off-by: webbeef <me@webbeef.org> * Address review comments Signed-off-by: webbeef <me@webbeef.org> --------- Signed-off-by: webbeef <me@webbeef.org>
* use `ThreadSafeJSContext` instead of `ContextForRequestInterrupt` (#33769)Samson2024-10-101-4/+5
| | | | | | | | | | | | | * use `ThreadSafeJSContext` instead of `ContextForRequestInterrupt` Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * use servo/mozjs Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --------- Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
* script: Include constructors and static methods in generated DOM traits (#33665)Josh Matthews2024-10-081-62/+62
| | | | | | | | | | | | | | | | | * Add all constructors, special operations, and static methods to generated DOM interface traits. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Move all constructors and static methods defined in bare impl blocks inside FooMethods trait impls. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Add missing doc links. Signed-off-by: Josh Matthews <josh@joshmatthews.net> --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* Propagate `CanGc` from `Document::new()` (#33386)Andriy Sultanov2024-09-091-0/+1
| | | | | | | | | | | | | * Add canGc as a parameter to autogenerated trait methods Signed-off-by: Andriy Sultanov <sultanovandriy@gmail.com> * Propagate CanGc from Document::new() Signed-off-by: Andriy Sultanov <sultanovandriy@gmail.com> --------- Signed-off-by: Andriy Sultanov <sultanovandriy@gmail.com>
* Start marking functions that can transitively trigger a GC (#33144)Josh Matthews2024-08-221-2/+5
| | | | | | | | | | | | | | | | | * Mark JS reflector wrappers as CanGc. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Propagate CanGc from reflect_dom_object_with_proto. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Mark DOM constructors as GC operations. Signed-off-by: Josh Matthews <josh@joshmatthews.net> --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* Initial structuredClone implementation (#32960)Taym Haddadi2024-08-081-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | * Initial structuredClone implementation Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com> * Rename PostMessageOptions to StructuredSerializeOptions Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com> * Update wpt test 2020 layout result Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com> * Remove dublicated StructuredClone implementation Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com> * Remove comment from StructuredSerializeOptions webidl Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> --------- Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com> Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
* clippy: Fix more clippy warnings in `components/scripts/dom` (#31914)Rosemary Ajayi2024-03-281-1/+1
| | | | | * refrence to a reference * refrence to a reference
* clippy: Fix option_map_unit_fn warnings (#31906)Oluwatobi Sofela2024-03-271-4/+3
|
* clippy: Fix redundant field names warnings (#31793)Oluwatobi Sofela2024-03-201-3/+3
|
* rustdoc: Fix many rustdoc errors (#31147)Martin Robinson2024-01-221-3/+3
| | | | 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.
* Replace script_plugins with a clippy like rustc driver (named crown) (#30508)Samson2023-12-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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>
* Strict import formatting (grouping and granularity) (#30325)Samson2023-09-111-14/+15
| | | | | * strict imports formatting * Reformat all imports
* No tracing of nop traceable fields (#29926)Samson2023-08-041-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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
* Fix race condition and other issues related to Worker destruction. (#30066)Mukilan Thiyagarajan2023-08-031-5/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Fix race condition in Worker destruction During shutdown, the main script thread calls JS_RequestInterruptCallback(cx) for each worker thread it owns where cx is the JSContext* created for that worker. Although JS_RequestInterruptCallback is safe to call from threads other than the worker thread, it is possible the JSContext* has already been destroyed For example, as noted in #30022, since the main thread sets the worker's `closing` flag to true to signal termination before it calls JS_RequestInterruptCallback, we can have a race condition where the worker exits its event loop when `closing` flags is set and then it (worker thread) destroys its own JSContext and JSRuntime. When the main thread resumes, it will call JS_RequestInterruptCallback for the worker's context, leading to a use-after-free bug. This patch solves this issue by improving the existing `ContextForRequestInterrupt` abstraction used for sharing the Worker's associated JSContext* with the parent script thread. Instead of simply wrapping a plain `*mut JSContext`, we now wrap the `*mut JSContext` in a nullable mutex i.e Mutex<Option<*mut JSContext>> The mutex lock needs to be held by the parent thread when it calls JS_RequestInterruptCallback. Similary, before the worker destroys its JSContext, it locks and sets the Option to None, signaling that the JSContext can no longer be used for interrupting the worker. This patch also fixes the issue in #30052 by enforcing the use of ContextForRequestInterrupt abstraction which ensures the correct JSContext is used by the main thread when Worker.terminate is called. Fixes #30022, #30052 * Fix Worker.importScripts to handle termination Fixing #30052 uncovered this issue in the implementation of `importScripts` method. After the fix for #30052, the WPT test `/workers/Worker-terminate-forever-during-evaluation.html` started to crash because when evaluation doesn't succeed `importScripts` always returns Error::JSFailed code to the caller, which indicates that there is a Dom/JS exception to be thrown. However, this is not true when the script is terminated, which causes the generated binding layer for 'importScript` to fail the assertion that there is a pending exception. This patch makes `importScripts` work similar to the [logic that evaluates the top-level script][1] of the Worker - it simply prints `evaluate_script failed - (terminated)' if the worker is terminating [1]: https://github.com/servo/servo/blob/3fea90a231a94338d67712398fe3d2ba9d402211/components/script/dom/workerglobalscope.rs#L434
* Rename reflect_dom_object2.Josh Matthews2023-05-311-2/+2
|
* Formatting.Josh Matthews2023-05-281-1/+5
|
* Support arbitrary protos when wrapping DOM objects with constructors.Josh Matthews2023-05-281-5/+7
|
* Make GlobalScope.get_cx a static method.Josh Matthews2023-05-201-2/+2
|
* ensure clean shutdown of all threads running JSGregory Terzian2020-06-301-1/+7
|
* add a control chan to workers, use to signal shutdownGregory Terzian2020-06-031-1/+4
|
* add mechanism to join on service- and dedicated-worker threadsGregory Terzian2020-05-291-3/+4
|
* Share single gpu_id_hub among all threads in a processKunal Mohan2020-05-151-0/+1
|
* Support connecting to worker globals from remote devtools.Josh Matthews2020-04-281-10/+23
|
* Support navigating browsing contexts in the devtools.Josh Matthews2020-04-261-1/+1
| | | | | | | | | | | | | Break the association between pipelines and browsing context actors. Now there is one browsing context actor per actual browsing context, and individual actors keep track of known pipelines as necessary. There is also one console/performance/timeline/inspector/etc. actor per browsing context. This also centralizes more information in the browsing context actor. Rather than duplicating state for the active pipeline in actors that need to use it, each actor now remembers the name of its associated browsing context actor and obtains that state whenever it's necessary.
* Add trait DomObjectWrap to provide WRAP functionYUAN LYU2020-03-201-6/+1
|
* rename compartment to realmKunal Mohan2020-01-241-1/+1
|
* Modify `script` to prevent further violations of snake_caseKunal Mohan2020-01-181-1/+1
|
* Remove `origin` parameter from `Worker::handle_message`Kunal Mohan2020-01-041-13/+2
|
* Remove Optional pipeline_idWarren Fisher2019-12-191-1/+1
|
* `WorkerId` changed to type UUID.Kunal Mohan2019-12-101-2/+3
|
* Use IDL sequence default valueKagami Sascha Rosylight2019-11-041-2/+0
|
* continue messageport, transferable, postmessage optionsGregory Terzian2019-10-191-14/+61
|
* begin messageport, transferable objects, implKeith Yeung2019-10-191-5/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Accept transfer argument for StructuredCloneData::write Allow structured clone reads to return a boolean Add Transferable trait Add basic skeletons to MessagePort Implement transfer and transfer-receiving steps on MessagePort Use transfer and transfer_receive in StructuredClone callbacks Implement MessageChannel Freeze the array object for the MessageEvent ports attribute Implement transfer argument on window.postMessage Use ReentrantMutex instead for MessagePortInternal Accept origin as a parameter in dispatch_jsval Fix BorrowMut crash with pending_port_message Detach port on closure and check for detached during transfer Enable webmessaging tests fix webidl fix