mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
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:
parent
b40d73de38
commit
8194aa7c1e
2 changed files with 15 additions and 3 deletions
|
@ -87,6 +87,7 @@ use crate::task_source::SendableTaskSource;
|
|||
static JOB_QUEUE_TRAPS: JobQueueTraps = JobQueueTraps {
|
||||
getIncumbentGlobal: Some(get_incumbent_global),
|
||||
enqueuePromiseJob: Some(enqueue_promise_job),
|
||||
runJobs: Some(run_jobs),
|
||||
empty: Some(empty),
|
||||
pushNewInterruptQueue: Some(push_new_interrupt_queue),
|
||||
popInterruptQueue: Some(pop_interrupt_queue),
|
||||
|
@ -241,6 +242,17 @@ unsafe extern "C" fn get_incumbent_global(_: *const c_void, _: *mut RawJSContext
|
|||
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)]
|
||||
unsafe extern "C" fn empty(extra: *const c_void) -> bool {
|
||||
let mut result = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue