Skip to content

script: Propagate js::context::JSContext through Event::fire.#45040

Merged
jdm merged 3 commits into
servo:mainfrom
jdm:fire-cx
May 21, 2026
Merged

script: Propagate js::context::JSContext through Event::fire.#45040
jdm merged 3 commits into
servo:mainfrom
jdm:fire-cx

Conversation

@jdm

@jdm jdm commented May 20, 2026

Copy link
Copy Markdown
Member

Testing: No behaviour changes; existing tests are sufficient.
Fixes: Part of #42638

@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label May 20, 2026
Comment thread components/script/dom/bindings/error.rs Outdated
Comment thread components/script/dom/webrtc/rtcdatachannel.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-blocking: we could use SM functions from https://doc.servo.org/mozjs/rust/wrappers2/index.html

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to leave this for a followup.

) {
let cx = GlobalScope::get_cx();
// SAFETY: always safe from a JS engine hook.
let mut cx = unsafe { temp_cx() };

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we are in SM hook, this is perma cx from thin air not temporary (to be removed someday), so we should do like:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no cx pointer to adopt, so I'm not sure exactly what to do.

@sagudev sagudev May 21, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. jsshell uses TLS: https://searchfox.org/firefox-main/source/js/src/shell/js.cpp#1301 so we should use it here to, meaning that we just need to inline temp_cx.

Side-note: We should probably have this kind of function (so perma cx) in mozjs under mozjs::context::JSContext::get to match https://doc.servo.org/mozjs/rust/struct.Runtime.html#method.get

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figure I'll leave this to be addressed by servo/mozjs#748

@servo-highfive servo-highfive added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels May 21, 2026
Comment thread components/script/dom/webrtc/rtcdatachannel.rs Outdated
Comment thread components/script/dom/webxr/xrsession.rs Outdated
@servo-highfive servo-highfive added the S-needs-rebase There are merge conflict errors. label May 21, 2026
jdm added 2 commits May 21, 2026 21:32
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
@servo-highfive servo-highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. S-needs-rebase There are merge conflict errors. labels May 21, 2026
@jdm jdm requested a review from sagudev May 21, 2026 19:33
@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label May 21, 2026
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label May 21, 2026
@jdm jdm enabled auto-merge May 21, 2026 21:52
@jdm jdm added this pull request to the merge queue May 21, 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 May 21, 2026
Merged via the queue into servo:main with commit 8c5aa91 May 21, 2026
33 checks passed
@jdm jdm deleted the fire-cx branch May 21, 2026 22:50
@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 May 21, 2026
yonas pushed a commit to yonasBSD/mozjs that referenced this pull request Jun 3, 2026
This is unofficially perma cx. Sometimes it is needed:
servo/servo#45040 (comment) and
https://doc.servo.org/mozjs/rust/struct.Runtime.html#method.get is
planned to be removed.

---------

Signed-off-by: Sam <16504129+sagudev@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-awaiting-review There is new code that needs to be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants