This commit remove more unused code from `script_module`,
`inline_module_map` and `dynamic_modules` fields from `GlobalScope` and
the now unused custom interface `DynamicModuleOwner`.
Testing: No functional change, a successful build is enough.
---------
Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
This replaces uses of our custom RootedVec type that were storing JS GC
values with stack rooting that is better integrated with the engine.
This ensures that storing nursery-allocated objects in these vectors is
handled correctly during GC, unlike our RootedVec implementation which
trips an assertion in debug mozjs builds.
Testing: No observable difference in non-mozjs builds.
Fixes: part of #40141
---------
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
Add an event listener for `pause` to `debugger.js` and the necessary
glue to access it from the `devtools` crate. This returns important
information to know where we are paused, such as the source location and
frame state.
Fix frame and object actor encoding into messages. Use information from
`debugger.js` to correctly fill the fields.
Add a new `frames` list to the thread actor and handle the `frames`
message.
Fix `getEnvironment` reply in the frame actor. It is out of form (has a
`type` field but it doesn't require a followup empty message, it already
counts as a reply), so we need to handle it specially.
Note: For now we are focusing on the protocol side of the debugger, and
this patch only shows where the pause would happen. Pausing Servo itself
will happen in a followup.

Testing: `mach test-devtools` and manual testing. No errors (apart from
#42006).
Part of: #36027
---------
Signed-off-by: eri <eri@igalia.com>
Co-authored-by: atbrakhi <atbrakhi@igalia.com>
Co-authored-by: Josh Matthews <josh@joshmatthews.net>
When building without the `testbinding` feature of `libservo`, we end up
with these compilation warnings (and one error):
```
warning: unused import: `native_from_handlevalue`
--> components/script_bindings/import.rs:108:9
|
108 | native_from_handlevalue, native_from_object_static,
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default
warning: unused imports: `DomSlice` and `Dom`
--> components/script_bindings/import.rs:131:34
|
131 | pub(crate) use crate::root::{Dom, DomSlice, MaybeUnreflectedDom, Root};
| ^^^ ^^^^^^^^
warning: unused import: `crate::root::DomRoot`
--> /home/webbeef/servo/target/debug/build/script_bindings-9c5650a8d750af8f/out/DomTypes.rs:3:5
|
3 | use crate::root::DomRoot;
| ^^^^^^^^^^^^^^^^^^^^
warning: unused import: `Maplike`
--> components/script_bindings/import.rs:124:34
|
124 | pub(crate) use crate::like::{Maplike, Setlike};
| ^^^^^^^
warning: `script_bindings` (lib) generated 4 warnings (run `cargo fix --lib -p script_bindings` to apply 3 suggestions)
error[E0412]: cannot find type `IdentityHub` in this scope
--> components/script/dom/debuggerglobalscope.rs:76:63
|
76 | #[cfg(feature = "webgpu")] gpu_id_hub: std::sync::Arc<IdentityHub>,
| ^^^^^^^^^^^ not found in this scope
|
help: consider importing this struct
|
5 + use crate::dom::identityhub::IdentityHub;
|
warning: method `worklet_id` is never used
--> components/script/dom/worklet.rs:121:19
|
95 | impl Worklet {
| ------------ method in this implementation
...
121 | pub(crate) fn worklet_id(&self) -> WorkletId {
| ^^^^^^^^^^
|
= note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default
```
Testing: No test needed, this won't change the default builds.
Signed-off-by: webbeef <me@webbeef.org>
Moves the drop logic for `GPUBindGroupLayout` to an inner struct
`DroppableGPUBindGroupLayout`.
Testing: No tests added
Fixes: Partially #26488
Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
Moves the drop implementation for `GPUBindGroup` to a separate
`DroppableGPUBindGroup` struct.
Testing: No tests added
Fixes: partially #26488
Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
Moves the adapter dropping logic from the `GPUAdapter` struct to a new
`DroppableGPUAdapter` struct.
Testing: No tests added.
Fixes: Partially #26488
Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
Reviewable per commit. First commit adds `&mut JSContext` to
`call_default_constructor`. Second commit adds `&mut JSContext` to
Interface, which in unfortunately required many changes (a lot of
passing `&mut JSContext` down).
Testing: Just a refactor, but should be covered by WPT
Part of #40600
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Refactors the `CookieStore` to use a separate `DroppableCookieStore`
struct for handling the drop logic.
Testing: No tests added
Fixes: Partially #26488
Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
Refactors the WebGLRenderingContext to manage resource cleanup via a
dedicated `DroppableWebGLRenderingContext` struct.
Testing: This task is only a refactor, no tests added
Fixes: partially #26488
Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
Replace `allow` with `expect` lints for `unused`, `unsafe_code`,
`dead_code`, and `non_upper_case_globals`.
Testing: So far just check it compiled on `x86_64-linux` on NixOS. Need
to use the module `system.fontconfig.enable = true;` I think in my NixOS
config.
Part of: #40383
Searching `allow\(.*\)` for `.rs` files shows the following. for
(total_results:total_files) went from `707:386` to `675:368`, a
reduction of `32:18`.
How many files is too many files per PR? I feel like the 20-30 I have is
too big.
---------
Signed-off-by: Wayne Van Son <waynevanson@gmail.com>
At the start of the script we create first (and only[^1]) safe
`JSContext`, from where we should pass it down to every code that needs
the cx. This PR brings it all the way down to message handlers. There is
clear separation between functions that use new model `&mut JSContext`
and the ones that use the old model (usually they take can_gc).
[^1]: Another place of construction are SM hooks (that pass us down raw
JSContext), but to reach that point we already needed to call another
function that takes `&mut JSContext`, so one can look at this case as
reentering/reborrowing (we derive new shorter `&mut JSContext` from the
old one).
Testing: This is just refactor, but should covered by WPT tests.
Part of #40600
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This PR adds support for using new JSContext/CurrentRealm to promise and
adds some more helpers that will ease migration to new context model.
Second commit has another demo.
Testing: Covered by WPT
Part of #40600
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Moves the concept of databases closer to the 3.0 spec, by implementing
the delete functionality, and the method returning current databases to
script.
Testing: WPT tests with new passes
Fixes: The "Implement databases deletion and `databases`" item of
https://github.com/servo/servo/issues/40983
---------
Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com>
Add placeholder implementation of DOM `VisualViewport` according to the
spec https://drafts.csswg.org/cssom-view/#visualviewport. This is the
first step of implementing the interface and syncing it with the
`PinchZoom` struct that we had in the `Embedder`.
Since this interface's is not accurate and couldn't fulfill it's
purpose, it would be gated behind a preference
`dom_visual_viewport_enabled` and would be open after the interface had
been integrated with `PinchZoom`, viewport resizing, and viewport
scroll.
Testing: Existing WPT Test.
Part of: #41341
---------
Signed-off-by: Jo Steven Novaryo <steven.novaryo@gmail.com>
This changes updates to the latest version of stylo which includes
vendor-prefixed properties such as `-moz-transform` and
`-webkit-transform`. This allows more web content to render properly.
Note: Unitless perspective is not supported as part of this yet, but
will be once https://phabricator.services.mozilla.com/D274128 is part
of our downstream version of Stylo.
Testing: There are tests for this change.
Fixes: #17635.
Fixes: #14941.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
There are two flavours of the mozjs `TypedArray<T>` wrapper for typed
array objects: one stores a `Box<Heap<*mut JSObject>>`, while the other
just has a bare `*mut JSObject`. The second one must only be stored
inside the `CustomAutoRoot` rooting values, but we were using it in many
other places like WebIDL dictionaries without rooting it safely. These
changes make our typed array APIs always use
`RootedTraceableBox<TypedArray<T>>` with the `Box<Heap<*mut JSObject>>`
flavour, which ensures that the JS object stored inside the typed array
wrapper is always visible to the SpiderMonkey GC.
Testing: Adds a new test that crashes without these changes.
Fixes: #41206
---------
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
The handwritten Drop implementation was removed in #37622, so we can now
remove the exception for it.
Testing: Compile-time generated code can't be meaningfully tested.
Fixes: part of #26488
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This implements the solution from #26488 that prevents implementing Drop
manually for DOM interfaces, which is very easy to write in a way that
can cause memory safety errors during JS runtime teardown. Since we have
a bunch of pre-existing implementations that we are working on removing,
this PR adds an opt-out mechanism that those interfaces use.
Testing: Compile-time code generation; not possible to test.
Fixes: part of #26488
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
The media session is allowed to control the state of the media element
(play, pause) and is holding DOM reference, so the latest registered
media element is not be able to be GCed, so let's use the weak reference
to break this dependency.
Note that `weakReference` property was added to interfaces
- HTMLMediaElement: The `Mutable/WeakRef` requires T to be bound by
`WeakReferenceable`
- HTMLAudio/VideoElement: The `DOM_WEAK_SLOT` must be reserved by
concrete DOM JS class
Testing: No expected testing results changes
The media session UI functionality is implemented for Android and didn't
test due lack of testing sample.
Fixes: https://github.com/servo/servo/issues/40854
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
script: add CanGc as argument to methods in HTMLOptionElement
Testing: These changes do not require tests because they are a refactor.
Addresses part of https://github.com/servo/servo/issues/34573
Signed-off-by: Yerkebulan Tulibergenov <yerkebulan@gmail.com>
The current implementation doesn't match the specification and is broken
in a way that makes nytimes.com endlessly attempt to enqueue resource
timing entries, making the page completely unresposive to user input.
This PR makes some surgical changes that fix the NYTimes behaviour and
add some comments to make it easier to further improve the
implementation in the future.
Testing: Various WPT that used to timeout now fail instead.
Fixes: #40808
---------
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
We replace many places that use `SafeJSContext` with `JSContext` and I
also rewrote `is_platform_object_same_origin` to use new `JSContext`.
Unfortunately using wrappers2 in them causes crashes (in handle code),
so I reverted that part in last commit and will fix handles in mozjs
later.
Testing: Refactor, but it is covered by WPT tests
Part of #40600
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This web API is alternative API to `throw e`, which is why we can reuse
a lot of the existing machinery.
The one testcase that isn't passing yet is because it reports an empty
`TypeError`. The current logic in `ErrorInfo` only retrieves the message
data, but doesn't include the type of the exception. For that, we need
to use `(*report)._base.errorNumber` and map that back to the original
type codes. However, deferring that to a follow-up as that requires some
more work in mozjs.
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Companion to https://github.com/servo/mozjs/pull/650
We added 3 new options to bindings.conf, each more powerful then the
previous one, so one should use the least powerful as possible to keep
things flexible:
1 `cx_no_gc` prepends argument `&JSContext`, which allows creating NoGC
tokens and using functions that do not trigger GC.
2. `cx` prepends argument `&mut JSContext`, which allows everything that
previous one allows, but it also allows calling GC triggering functions.
3. `realm` prepends argument `&mut CurrentRealm`, which can be deref_mut
to `&mut JSContext` (so it can do everything that previous can), but it
also ensures that there is current entered realm, which can be used for
creation of InRealm.
next steps: #40600
reviewable per commit
Testing: It's just refactoring
try run: https://github.com/sagudev/servo/actions/runs/19287700927
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
The `seek` method isn't explicitly exposed in the API, but is called
from various places (`currentTime`, `fastSeek`, by the `media metadata`
event) and doesn't itself create new DOM objects, so the `canGC`
argument can be omitted.
It was previously required because calling the `Seekable` method creates
a new `TimeRanges` object, but it will now be replaced by the internal
`seekable` method to avoid interaction with the JavaScript engine (and
potential garbage collector).
The `earlyest possible position` method has been changed to match the
specification and use `seekable` instead of `played`. See
https://html.spec.whatwg.org/multipage/#earliest-possible-position
Testing: No expected changes in tests
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
Implement read looping using a read request following the spec.
Testing: current wpt test should pass.
Fixes: #39482
---------
Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
Partially implement dialog.showModal()
Follow-ups will be needed to further implement proper dialog
functionality but this makes a good start.
Testing: Existing WPTs cover this.
---------
Signed-off-by: Luke Warlow <lwarlow@igalia.com>
Implement `Document.parseHTMLUnsafe`
Testing: Covered by existing WPTs, expectations have been updated.
Fixes: #40245
---------
Signed-off-by: Luke Warlow <lwarlow@igalia.com>
This avoids a borrow hazard when we create a new IDBObjectStore object
and that triggers a GC.
Testing: Many IndexedDB tests no longer crash when using a debug mozjs
build and full GC zeal. This configuration is not run in CI.
Fixes: #39946
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
add CanGc as argument to methods in PaintRenderingContext2D
Testing: These changes do not require tests because they are a refactor.
Addresses part of https://github.com/servo/servo/issues/34573.
Signed-off-by: Yerkebulan Tulibergenov <yerkebulan@gmail.com>
Follow the HTML specification and add the missing 'name' and 'areas' IDL
attributes to HTMLMapElement.
https://html.spec.whatwg.org/multipage/#htmlmapelement
Testing: Improvements in the following WPT tests
- custom-elements/reactions/customized-builtins/HTMLMapElement.html
- html/dom/idlharness.https.html
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>