Commit Graph

18 Commits

Author SHA1 Message Date
Tim van der Lippe
c8029ea092 script: Rename CanGc::note() to CanGc::deprecated_note() (#44081)
Per the suggestion in

https://servo.zulipchat.com/#narrow/channel/263398-general/topic/PSA.3A.20avoid.20new.20usages.20of.20CanGc.20whenever.20possible/near/583995807
to mark this method as deprecated and make clear it shouldn't be used
anymore, as alternatives exist.

Part of #40600

Testing: It compiles

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2026-04-10 06:07:52 +00:00
Gae24
113b06f2ee script: Correctly setup request for worker module scripts (#43585)
According to spec we should fetch worker modules using the _outside
settings_, however we can't use it directly since we are on a different
thread. To fix it, a new struct `ModuleFetchClient` is now part of
`LoadState` and replace the `with_global_scope` call done in
`fetch_a_single_module_script`.
This also tidy worker classic script related code.

Testing: There are new passes

---------

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
2026-03-24 05:28:27 +00:00
Kelechi Ebiri
a63a00936f remove referrer field from ScriptFetchOptions (#43532)
Remove `referrer` field from `ScriptFetchOptions` and pass it directly
to `script_fetch_request`.

This keeps ScriptFetchOptions aligned with the HTML 
fixes #42875

---------

Signed-off-by: Kelechi Ebiri <ebiritg@gmail.com>
2026-03-22 16:41:29 +00:00
Philipp Albrecht
15a400b42a Add basic support for handling module scripts in workers (#40365)
While we now pass a lot of worker tests, we still fail a bunch:
```
% fd '^worker-.*.html.ini'
tests/wpt/meta/content-security-policy/gen/top.http-rp/script-src-self/worker-import.http.html.ini
tests/wpt/meta/content-security-policy/gen/top.http-rp/script-src-self/worker-import.https.html.ini
tests/wpt/meta/content-security-policy/gen/top.http-rp/worker-src-self/worker-import.http.html.ini
tests/wpt/meta/content-security-policy/gen/top.http-rp/worker-src-self/worker-import.https.html.ini
tests/wpt/meta/content-security-policy/gen/top.meta/script-src-self/worker-import.http.html.ini
tests/wpt/meta/content-security-policy/gen/top.meta/script-src-self/worker-import.https.html.ini
tests/wpt/meta/content-security-policy/gen/top.meta/worker-src-self/worker-import.http.html.ini
tests/wpt/meta/content-security-policy/gen/top.meta/worker-src-self/worker-import.https.html.ini
tests/wpt/meta/content-security-policy/script-src/worker-data-set-timeout.sub.html.ini
tests/wpt/meta/content-security-policy/script-src/worker-importscripts.sub.html.ini
tests/wpt/meta/content-security-policy/script-src/worker-set-timeout.sub.html.ini
tests/wpt/meta/fetch/metadata/generated/worker-dedicated-constructor.sub.html.ini
tests/wpt/meta/fetch/metadata/generated/worker-dedicated-importscripts.https.sub.html.ini
tests/wpt/meta/fetch/metadata/generated/worker-dedicated-importscripts.sub.html.ini
tests/wpt/meta/mixed-content/gen/top.http-rp/opt-in/worker-import-data.https.html.ini
tests/wpt/meta/mixed-content/gen/top.http-rp/opt-in/worker-import.https.html.ini
tests/wpt/meta/referrer-policy/generic/subresource-test/worker-messaging.html.ini
tests/wpt/meta/service-workers/service-worker/worker-client-id.https.html.ini
tests/wpt/meta/service-workers/service-worker/worker-in-sandboxed-iframe-by-csp-fetch-event.https.html.ini
tests/wpt/meta/service-workers/service-worker/worker-interception-redirect.https.html.ini
tests/wpt/meta/service-workers/service-worker/worker-interception.https.html.ini
tests/wpt/meta/upgrade-insecure-requests/gen/worker-classic.http-rp/upgrade/worker-classic.https.html.ini
tests/wpt/meta/upgrade-insecure-requests/gen/worker-classic.http-rp/upgrade/worker-module.https.html.ini
tests/wpt/meta/upgrade-insecure-requests/gen/worker-module.http-rp/upgrade/worker-classic.https.html.ini
tests/wpt/meta/upgrade-insecure-requests/gen/worker-module.http-rp/upgrade/worker-module.https.html.ini
tests/wpt/meta/wasm/webapi/esm-integration/worker-import-source-phase.tentative.html.ini
tests/wpt/meta/wasm/webapi/esm-integration/worker-import.tentative.html.ini
tests/wpt/meta/workers/Worker-creation-happens-in-parallel.https.html.ini
tests/wpt/meta/workers/Worker-postMessage-happens-in-parallel.https.html.ini
tests/wpt/meta/workers/Worker-terminate-forever-during-evaluation.html.ini
tests/wpt/meta/workers/worker-request-animation-frame.html.ini
```

Also, we are passing `Option<PolicyContainer>` down the call stack
through `LoadState`, which is more of a workaround. However, since
maintaining this long-lived branch is becoming a bit painful (merge
conflicts) and I was starting to lose momentum because of that, I would
like get this merged rather sooner than later.

We will address the failing tests and find the right place for
`PolicyContainer` in follow-ups, including the added
`#[allow(clippy::too_many_arguments)]`.


# See also
* https://html.spec.whatwg.org/multipage/#worker-processing-model
*
https://html.spec.whatwg.org/multipage/#fetch-a-module-worker-script-tree

---

Fixes: #23308
Testing: WPT tests

Signed-off-by: pylbrecht <pylbrecht@mailbox.org>
Co-authored-by: Gae24 <96017547+Gae24@users.noreply.github.com>
2026-03-20 00:58:16 +00:00
Simon Wülker
c0ff7c1fc9 Everywhere: Remove instances of clippy::redundant-clone (#43212)
This change fixes all instances where
[`clippy::redundant-clone`](https://rust-lang.github.io/rust-clippy/master/index.html?groups=complexity%2Ccorrectness%2Cnursery%2Csuspicious&levels=allow#redundant_clone)
would trigger. It's allowed by default

I've also changed the lint to warn-by-default for servo.

Testing: Covered by WPT

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2026-03-12 13:28:21 +00:00
Martin Robinson
e725fdbfdf script_bindings: Eliminate DOMString::from_string (#43089)
This method is the same as `DOMString::from` with a `String` argument
and `From` and `Into` are preferred when writing modern Rust.

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

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2026-03-08 11:46:42 +00:00
Sam
8757ccbc8d script: Replace RAII AutoIncumbentScript with function wrapper (#42905)
As in https://github.com/servo/servo/pull/42715 we will need cx in drop
so we need to go to function wrapper pattern.

Testing: Just refactor should be covered by WPT tests.

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2026-02-28 06:53:07 +00:00
Gae24
c1ee5ff522 script: Don't stop at scopes's first module specifier map when resolving a module specifier (#42821)
Previously, the resolution loop would break immediately after running
`resolve_imports_match` against the first module specifier map of the
import map's scopes, regardless of whether a match was actually found.

Testing: All sub-tests of `resolving.html` now pass
Part of #37553

---------

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
2026-02-24 19:16:06 +00:00
Gae24
49adfed9a8 script: implement resolve_a_module_integrity_metadata (#42604)
`ImportMap` _integrity_ entry was practically unused, since it is only
needed for [resolving a module integrity
metadata](https://html.spec.whatwg.org/multipage/#resolving-a-module-integrity-metadata).
Now, we correctly initialize `ScriptFetchOptions` when loading a
module's descendants.
I slightly modified `nonimport-integrity.html` test to run
`modulepreload` test cases at the end. Since we haven't an
implementation for it, the test timeout, making the test cases that
comes after them not run.

Testing: More tests start passing
Part of #37553

---------

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
2026-02-14 10:26:49 +00:00
Sam
d5d400c7d6 script: Use CString for Error::Type and Error::Range (#42576)
Continuation of https://github.com/servo/servo/pull/42135, switch
Error::Type and Error::Range to also use CStrings internally, as they
are converted to CString for throwing JS exceptions (other get thrown as
DomException object, which uses rust string internally).

Changes in script crate are mechanical.

Testing: Should be covered by WPT tests.
Part of #42126

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2026-02-12 15:17:30 +00:00
Gae24
fe932a4d1f script: Start using &mut JSContext and wrappers2 functions inside module script code (#42294)
Start using `&mut JSContext` and wrappers2 functions for module script
code.


Testing: A successful build should be enough

---------

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
2026-02-04 06:01:23 +00:00
Gae24
9c4d17e9e1 script: support JSON modules (#42138)
With import attributes enabled we can now support non javascript
modules, for now we are limited to json ones.
Switch `GlobalScope` `modulemap` to be keyed by the tuple url and
module's type.

Testing: Enabled a new directory, new tests should pass

---------

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
Co-authored-by: Josh Matthews <josh@joshmatthews.net>
2026-01-31 01:18:51 +00:00
Gae24
dfed00367a script: Enable module scripts import attributes (#42185)
While working on #42138 I found out that import attributes are an opt-in
feature, which can be enabled by `ContextOptionsRef`'s
`compileOptions_`.
This is likely the reason why `GetRequestedModuleSpecifier` wouldn't
fail.
Now we catch any `GetRequestedModuleSpecifier` exception and pass it to
`load_state`.

Testing: Covered by existing tests

---------

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
2026-01-29 07:46:02 +00:00
Gae24
047cb39fa9 script: Drop ModuleTree network_error and simplify pending fetches logic (#42127)
Since we use `NetworkError` just for logging reasons, we don't really
need to pass it around; instead lets follow spec more closely and pass a
`None` on network failures.
Make more explicit if a `modulemap` entry is currently fetching or
ready.

Testing: No functional change, covered by existing tests

---------

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
2026-01-26 05:43:12 +00:00
Krzysztof Biedroń
17e3061ecd script: Modify ModuleObject::handle() to return a handle with a lifetime (#42071)
Changed the return type of `ModuleObject::handle()` to the original type
of its contained handle by removing `.into()` call, as requested in the
linked issue.

Additional changes are due to temporary borrows now sharing lifetime
with returned handle reference.

Testing: No new tests needed, as the code is functionally the same after
the changes. Verified with running `./mach test-build` and `./mach
test-unit` successfully.
Fixes: https://github.com/servo/servo/issues/42051

Signed-off-by: Krzysztof Biedroń <arkendil@gmail.com>
2026-01-25 00:13:32 +00:00
Josh Matthews
7925a26a99 script: Use OnceCell instead of RefCell for some module fields. (#42119)
This better reflects the intention of the code, which is that these
fields are set at most one time.

Testing: No behaviour change expected, so existing tests suffice.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
2026-01-24 06:53:33 +00:00
Gae24
b7ccf86cb8 script: remove more unused code (#42081)
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>
2026-01-22 15:12:09 +00:00
Gae24
a953ba954a script: revamp module script loading to follow current spec (#41779)
Rewrite module script fetching logic to follow current spec.

Testing: Covered by existing wpt tests
Fixes: #31397

---------

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
2026-01-22 11:40:53 +00:00