script: Implement jsglue trap for runJobs() (#38265)

in the [SpiderMonkey Debugger
API](https://firefox-source-docs.mozilla.org/js/Debugger/), hooks like
[onNewGlobalObject()](https://firefox-source-docs.mozilla.org/js/Debugger/Debugger.html#onnewglobalobject-global)
use an AutoDebuggerJobQueueInterruption to [switch to a new microtask
queue](b14aebff23/mozjs-sys/mozjs/js/src/debugger/Debugger.cpp (L2834-L2841))
and avoid clobbering the debuggee’s microtask queue. this in turn relies
on JobQueue::runJobs(), which is [not yet implemented in
RustJobQueue](b14aebff23/mozjs-sys/src/jsglue.cpp (L76-L78)).

this patch bumps mozjs to servo/mozjs#597, which implements
[runJobs()](b14aebff23/mozjs-sys/mozjs/js/public/Promise.h (L61-L76))
for RustJobQueue by calling into Servo’s MicrotaskQueue::checkpoint()
via a new function in JobQueueTraps.

SpiderMonkey [does not own external job
queues](b14aebff23/mozjs-sys/mozjs/js/public/Promise.h (L117-L123)),
so the lifetime of these queues is managed in Servo, where they are
stored in a Vec-based stack. stack-like behaviour is adequate for
SpiderMonkey’s save and restore patterns, as far as we can tell, but
we’ve added an assertion just in case.

Testing: manually tested working in devtools debugger patch (#37667),
where it will undergo automated tests

Signed-off-by: Delan Azabani <dazabani@igalia.com>
Co-authored-by: atbrakhi <atbrakhi@igalia.com>
This commit is contained in:
shuppy 2025-07-31 10:46:37 +08:00 committed by GitHub
parent b40d73de38
commit 8194aa7c1e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 3 deletions

6
Cargo.lock generated
View file

@ -5240,7 +5240,7 @@ dependencies = [
[[package]] [[package]]
name = "mozjs" name = "mozjs"
version = "0.14.1" version = "0.14.1"
source = "git+https://github.com/servo/mozjs#b23161580b082e1ccfa3273d94f43f6168aedc3d" source = "git+https://github.com/servo/mozjs#4035b0c4e9e2df5cacc68c4b71e7375a48605902"
dependencies = [ dependencies = [
"bindgen 0.71.1", "bindgen 0.71.1",
"cc", "cc",
@ -5251,8 +5251,8 @@ dependencies = [
[[package]] [[package]]
name = "mozjs_sys" name = "mozjs_sys"
version = "0.128.13-2" version = "0.128.13-3"
source = "git+https://github.com/servo/mozjs#b23161580b082e1ccfa3273d94f43f6168aedc3d" source = "git+https://github.com/servo/mozjs#4035b0c4e9e2df5cacc68c4b71e7375a48605902"
dependencies = [ dependencies = [
"bindgen 0.71.1", "bindgen 0.71.1",
"cc", "cc",

View file

@ -87,6 +87,7 @@ use crate::task_source::SendableTaskSource;
static JOB_QUEUE_TRAPS: JobQueueTraps = JobQueueTraps { static JOB_QUEUE_TRAPS: JobQueueTraps = JobQueueTraps {
getIncumbentGlobal: Some(get_incumbent_global), getIncumbentGlobal: Some(get_incumbent_global),
enqueuePromiseJob: Some(enqueue_promise_job), enqueuePromiseJob: Some(enqueue_promise_job),
runJobs: Some(run_jobs),
empty: Some(empty), empty: Some(empty),
pushNewInterruptQueue: Some(push_new_interrupt_queue), pushNewInterruptQueue: Some(push_new_interrupt_queue),
popInterruptQueue: Some(pop_interrupt_queue), popInterruptQueue: Some(pop_interrupt_queue),
@ -241,6 +242,17 @@ unsafe extern "C" fn get_incumbent_global(_: *const c_void, _: *mut RawJSContext
result result
} }
#[allow(unsafe_code)]
unsafe extern "C" fn run_jobs(microtask_queue: *const c_void, cx: *mut RawJSContext) {
let cx = JSContext::from_ptr(cx);
wrap_panic(&mut || {
let microtask_queue = &*(microtask_queue as *const MicrotaskQueue);
// TODO: run Promise- and User-variant Microtasks, and do #notify-about-rejected-promises.
// Those will require real `target_provider` and `globalscopes` values.
microtask_queue.checkpoint(cx, |_| None, vec![], CanGc::note());
});
}
#[allow(unsafe_code)] #[allow(unsafe_code)]
unsafe extern "C" fn empty(extra: *const c_void) -> bool { unsafe extern "C" fn empty(extra: *const c_void) -> bool {
let mut result = false; let mut result = false;