Skip to content

script: use &mut JSContext inside workers PostMessage api#42342

Merged
sagudev merged 1 commit into
servo:mainfrom
Gae24:workers-postmessage
Feb 4, 2026
Merged

script: use &mut JSContext inside workers PostMessage api#42342
sagudev merged 1 commit into
servo:mainfrom
Gae24:workers-postmessage

Conversation

@Gae24
Copy link
Copy Markdown
Contributor

@Gae24 Gae24 commented Feb 4, 2026

Switch PostMessage of Worker, DedicatedWorkerGlobalScope and ServiceWoker to use &mut JSContext, propagating it to post_message_impl.

Testing: A successful build is enough

@Gae24 Gae24 requested a review from gterzian as a code owner February 4, 2026 16:53
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Feb 4, 2026
@Gae24
Copy link
Copy Markdown
Contributor Author

Gae24 commented Feb 4, 2026

There haven’t been many pull requests to convert to &mut JSContext yet.
Should we start opening sub‑issues to kick things off?

@sagudev
Copy link
Copy Markdown
Member

sagudev commented Feb 4, 2026

There haven’t been many pull requests to convert to &mut JSContext yet. Should we start opening sub‑issues to kick things off?

Yes please! Fell free to ping me on any questions or for requesting reviews.

@sagudev
Copy link
Copy Markdown
Member

sagudev commented Feb 4, 2026

@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Feb 4, 2026
@sagudev sagudev added this pull request to the merge queue Feb 4, 2026
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Feb 4, 2026
Merged via the queue into servo:main with commit 97aac6e Feb 4, 2026
32 checks passed
@servo-highfive servo-highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Feb 4, 2026
@Gae24 Gae24 deleted the workers-postmessage branch February 5, 2026 18:35
MavenRain added a commit to MavenRain/servo that referenced this pull request May 9, 2026
… and

  `post_message_impl`.

  Continues the propagation of `&mut JSContext` (issue servo#42347) through the
  MessagePort message-passing chain: `pack_and_post_message`,
  `pack_and_post_message_handling_error`, `cross_realm_transform_send_error`,
  and `post_message_impl` now take `&mut JSContext` instead of `SafeJSContext`
  (or no `cx` parameter at all).  Stream callers in `underlyingsourcecontainer`,
   `writablestreamdefaultcontroller`, `readablestream`, and `writablestream`
  pass `cx` through.

  The `structuredclone::write` signature itself is left as a follow-up; this PR
  keeps the existing `cx.into()` bridge at the call site in
  `MessagePort::post_message_impl`, matching the pattern from servo#42342.

  Testing: No new tests; existing tests in CI cover the message-passing paths.
  Local cargo check could not be run because `mozjs_sys` requires `lld` (part of
   `./mach bootstrap`), so I am relying on CI for compile verification.
  Fixes: servo#42347

Signed-off-by: Onyeka Obi <[email protected]>
MavenRain added a commit to MavenRain/servo that referenced this pull request May 9, 2026
… and

  `post_message_impl`.

  Continues the propagation of `&mut JSContext` (issue servo#42347) through the
  MessagePort message-passing chain: `pack_and_post_message`,
  `pack_and_post_message_handling_error`, `cross_realm_transform_send_error`,
  and `post_message_impl` now take `&mut JSContext` instead of `SafeJSContext`
  (or no `cx` parameter at all).  Stream callers in `underlyingsourcecontainer`,
   `writablestreamdefaultcontroller`, `readablestream`, and `writablestream`
  pass `cx` through.

  The `structuredclone::write` signature itself is left as a follow-up; this PR
  keeps the existing `cx.into()` bridge at the call site in
  `MessagePort::post_message_impl`, matching the pattern from servo#42342.

  Testing: No new tests; existing tests in CI cover the message-passing paths.
  Local cargo check could not be run because `mozjs_sys` requires `lld` (part of
   `./mach bootstrap`), so I am relying on CI for compile verification.
  Fixes: servo#42347

Signed-off-by: Onyeka Obi <[email protected]>
MavenRain added a commit to MavenRain/servo that referenced this pull request May 9, 2026
… and

  `post_message_impl`.

  Continues the propagation of `&mut JSContext` (issue servo#42347) through the
  MessagePort message-passing chain: `pack_and_post_message`,
  `pack_and_post_message_handling_error`, `cross_realm_transform_send_error`,
  and `post_message_impl` now take `&mut JSContext` instead of `SafeJSContext`
  (or no `cx` parameter at all).  Stream callers in `underlyingsourcecontainer`,
   `writablestreamdefaultcontroller`, `readablestream`, and `writablestream`
  pass `cx` through.

  The `structuredclone::write` signature itself is left as a follow-up; this PR
  keeps the existing `cx.into()` bridge at the call site in
  `MessagePort::post_message_impl`, matching the pattern from servo#42342.

  Testing: No new tests; existing tests in CI cover the message-passing paths.
  Local cargo check could not be run because `mozjs_sys` requires `lld` (part of
   `./mach bootstrap`), so I am relying on CI for compile verification.
  Fixes: servo#42347

Signed-off-by: Onyeka Obi <[email protected]>
MavenRain added a commit to MavenRain/servo that referenced this pull request May 11, 2026
… and

  `post_message_impl`.

  Continues the propagation of `&mut JSContext` (issue servo#42347) through the
  MessagePort message-passing chain: `pack_and_post_message`,
  `pack_and_post_message_handling_error`, `cross_realm_transform_send_error`,
  and `post_message_impl` now take `&mut JSContext` instead of `SafeJSContext`
  (or no `cx` parameter at all).  Stream callers in `underlyingsourcecontainer`,
   `writablestreamdefaultcontroller`, `readablestream`, and `writablestream`
  pass `cx` through.

  The `structuredclone::write` signature itself is left as a follow-up; this PR
  keeps the existing `cx.into()` bridge at the call site in
  `MessagePort::post_message_impl`, matching the pattern from servo#42342.

  Testing: No new tests; existing tests in CI cover the message-passing paths.
  Local cargo check could not be run because `mozjs_sys` requires `lld` (part of
   `./mach bootstrap`), so I am relying on CI for compile verification.
  Fixes: servo#42347

Signed-off-by: Onyeka Obi <[email protected]>
MavenRain added a commit to MavenRain/servo that referenced this pull request May 11, 2026
… and

  `post_message_impl`.

  Continues the propagation of `&mut JSContext` (issue servo#42347) through the
  MessagePort message-passing chain: `pack_and_post_message`,
  `pack_and_post_message_handling_error`, `cross_realm_transform_send_error`,
  and `post_message_impl` now take `&mut JSContext` instead of `SafeJSContext`
  (or no `cx` parameter at all).  Stream callers in `underlyingsourcecontainer`,
   `writablestreamdefaultcontroller`, `readablestream`, and `writablestream`
  pass `cx` through.

  The `structuredclone::write` signature itself is left as a follow-up; this PR
  keeps the existing `cx.into()` bridge at the call site in
  `MessagePort::post_message_impl`, matching the pattern from servo#42342.

  Testing: No new tests; existing tests in CI cover the message-passing paths.
  Local cargo check could not be run because `mozjs_sys` requires `lld` (part of
   `./mach bootstrap`), so I am relying on CI for compile verification.
  Fixes: servo#42347

Signed-off-by: Onyeka Obi <[email protected]>
webbeef pushed a commit to webbeef/servo that referenced this pull request May 11, 2026
…and `post_message_impl`. (servo#44806)

Continues the propagation of `&mut JSContext` (issue servo#42347) through the
MessagePort message-passing chain: `pack_and_post_message`,
`pack_and_post_message_handling_error`,
`cross_realm_transform_send_error`, and `post_message_impl` now take
`&mut JSContext` instead of `SafeJSContext` (or no `cx` parameter at
all). Stream callers in `underlyingsourcecontainer`,
`writablestreamdefaultcontroller`, `readablestream`, and
`writablestream` pass `cx` through.

The `structuredclone::write` signature itself is left as a follow-up;
this PR keeps the existing `cx.into()` bridge at the call site in
`MessagePort::post_message_impl`, matching the pattern from servo#42342.

Testing: No new tests; existing tests in CI cover the message-passing
paths. Local cargo check could not be run because `mozjs_sys` requires
`lld` (part of `./mach bootstrap`), so I am relying on CI for compile
verification.

Fixes: servo#42347

Signed-off-by: Onyeka Obi <[email protected]>
MavenRain added a commit to MavenRain/servo that referenced this pull request May 15, 2026
  Migrate `structuredclone::write` from `SafeJSContext` to
  `&mut JSContext` (issue servo#42347), the last remaining checkbox in
  the MessagePort/structured-clone propagation chain started by
  servo#42342.

  Changes in `bindings/structuredclone.rs`:

  - Signature: `cx: SafeJSContext` becomes `cx: &mut JSContext`.
  - Body: `safe_to_jsval(cx, ...)` becomes `safe_to_jsval(cx.into(), ...)`;
    the `JS_WriteStructuredClone` import moves to `js::rust::wrappers2`
    so the call site passes `cx` directly; `*cx` becomes `cx.raw_cx()`
    at the `JS_IsExceptionPending` call site.
  - The `SafeJSContext` import is retained because the
    `read_callback` and `read_transfer_callback` paths still construct
    one via `SafeJSContext::from_ptr`.

  Caller cleanup across 13 files: drops the now-redundant `cx.into()`
  bridge at all 15 call sites; `cx` is passed by reborrow directly.
  All callers already had `cx: &mut JSContext` (or `&mut CurrentRealm`
  which auto-derefs) from earlier sub-PRs.

  Fixes servo#42347

  Signed-off-by: Onyeka Obi <[email protected]>
MavenRain added a commit to MavenRain/servo that referenced this pull request May 15, 2026
  Migrate `structuredclone::write` from `SafeJSContext` to
  `&mut JSContext` (issue servo#42347), the last remaining checkbox in
  the MessagePort/structured-clone propagation chain started by
  servo#42342.

  Changes in `bindings/structuredclone.rs`:

  - Signature: `cx: SafeJSContext` becomes `cx: &mut JSContext`.
  - Body: `safe_to_jsval(cx, ...)` becomes `safe_to_jsval(cx.into(), ...)`;
    the `JS_WriteStructuredClone` import moves to `js::rust::wrappers2`
    so the call site passes `cx` directly; `*cx` becomes `cx.raw_cx()`
    at the `JS_IsExceptionPending` call site.
  - The `SafeJSContext` import is retained because the
    `read_callback` and `read_transfer_callback` paths still construct
    one via `SafeJSContext::from_ptr`.

  Caller cleanup across 13 files: drops the now-redundant `cx.into()`
  bridge at all 15 call sites; `cx` is passed by reborrow directly.
  All callers already had `cx: &mut JSContext` (or `&mut CurrentRealm`
  which auto-derefs) from earlier sub-PRs.

  Fixes servo#42347

  Signed-off-by: Onyeka Obi <[email protected]>

Signed-off-by: Onyeka Obi <[email protected]>
MavenRain added a commit to MavenRain/servo that referenced this pull request May 15, 2026
  Migrate `structuredclone::write` from `SafeJSContext` to
  `&mut JSContext` (issue servo#42347), the last remaining checkbox in
  the MessagePort/structured-clone propagation chain started by
  servo#42342.

  Changes in `bindings/structuredclone.rs`:

  - Signature: `cx: SafeJSContext` becomes `cx: &mut JSContext`.
  - Body: `safe_to_jsval(cx, ...)` becomes `safe_to_jsval(cx.into(), ...)`;
    the `JS_WriteStructuredClone` import moves to `js::rust::wrappers2`
    so the call site passes `cx` directly; `*cx` becomes `cx.raw_cx()`
    at the `JS_IsExceptionPending` call site.
  - The `SafeJSContext` import is retained because the
    `read_callback` and `read_transfer_callback` paths still construct
    one via `SafeJSContext::from_ptr`.

  Caller cleanup across 13 files: drops the now-redundant `cx.into()`
  bridge at all 15 call sites; `cx` is passed by reborrow directly.
  All callers already had `cx: &mut JSContext` (or `&mut CurrentRealm`
  which auto-derefs) from earlier sub-PRs.

  Fixes servo#42347

  Signed-off-by: Onyeka Obi <[email protected]>

Signed-off-by: Onyeka Obi <[email protected]>
pull Bot pushed a commit to Patreos998/servo that referenced this pull request May 15, 2026
Migrate `structuredclone::write` from `SafeJSContext` to `&mut
JSContext`
  (issue servo#42347), the last remaining checkbox in the MessagePort /
  structured-clone propagation chain started by servo#42342.

  Changes in `components/script/dom/bindings/structuredclone.rs`:

  - Signature: `cx: SafeJSContext` becomes `cx: &mut JSContext`.
- Body: `safe_to_jsval(cx, ...)` becomes `safe_to_jsval(cx.into(),
...)`;
  `*cx` becomes `cx.raw_cx()` at the two `JS_WriteStructuredClone` and
  `JS_IsExceptionPending` call sites.
- The `SafeJSContext` import is retained because the `read_callback` and
  `read_transfer_callback` paths still construct one via
  `SafeJSContext::from_ptr`.

Caller cleanup across 13 files: drops the now-redundant `cx.into()`
bridge at
all 15 call sites; `cx` is passed by reborrow directly. All callers
already
had `cx: &mut JSContext` (or `&mut CurrentRealm` which auto-derefs) from
  earlier sub-PRs in the chain.

  Testing: No new tests required; this is a type-signature refactor
  (`SafeJSContext` to `&mut JSContext`) with no runtime behavior change.
Existing structured-clone tests continue to exercise the same code paths
  through `JS_WriteStructuredClone` and the `safe_to_jsval` conversion.
  
  Fixes: servo#42347

Signed-off-by: Onyeka Obi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants