aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/microtask.rs
diff options
context:
space:
mode:
authorJosh Matthews <josh@joshmatthews.net>2019-06-02 23:38:12 -0400
committerJosh Matthews <josh@joshmatthews.net>2019-06-26 18:10:46 -0400
commit63714c90fb5bbad86f28fc188120b2ecfd3337ab (patch)
treec4d8eaa4de8bcf26b6a382f450f1b194024f83c3 /components/script/microtask.rs
parentce9f35e0e3de762d84dffadf39fc30f8377aa4b9 (diff)
downloadservo-63714c90fb5bbad86f28fc188120b2ecfd3337ab.tar.gz
servo-63714c90fb5bbad86f28fc188120b2ecfd3337ab.zip
Upgrade to Spidermonkey 67.
Diffstat (limited to 'components/script/microtask.rs')
-rw-r--r--components/script/microtask.rs24
1 files changed, 20 insertions, 4 deletions
diff --git a/components/script/microtask.rs b/components/script/microtask.rs
index a523c1c83dc..db420e20eaa 100644
--- a/components/script/microtask.rs
+++ b/components/script/microtask.rs
@@ -16,6 +16,7 @@ use crate::dom::htmlmediaelement::MediaElementMicrotask;
use crate::dom::mutationobserver::MutationObserver;
use crate::script_runtime::notify_about_rejected_promises;
use crate::script_thread::ScriptThread;
+use js::jsapi::{JSContext, JobQueueIsEmpty, JobQueueMayNotBeEmpty};
use msg::constellation_msg::PipelineId;
use std::cell::Cell;
use std::mem;
@@ -54,14 +55,21 @@ pub struct EnqueuedPromiseCallback {
impl MicrotaskQueue {
/// Add a new microtask to this queue. It will be invoked as part of the next
/// microtask checkpoint.
- pub fn enqueue(&self, job: Microtask) {
+ #[allow(unsafe_code)]
+ pub unsafe fn enqueue(&self, job: Microtask, cx: *mut JSContext) {
self.microtask_queue.borrow_mut().push(job);
+ JobQueueMayNotBeEmpty(cx);
}
/// <https://html.spec.whatwg.org/multipage/#perform-a-microtask-checkpoint>
/// Perform a microtask checkpoint, executing all queued microtasks until the queue is empty.
- pub fn checkpoint<F>(&self, target_provider: F, globalscopes: Vec<DomRoot<GlobalScope>>)
- where
+ #[allow(unsafe_code)]
+ pub unsafe fn checkpoint<F>(
+ &self,
+ cx: *mut JSContext,
+ target_provider: F,
+ globalscopes: Vec<DomRoot<GlobalScope>>,
+ ) where
F: Fn(PipelineId) -> Option<DomRoot<GlobalScope>>,
{
if self.performing_a_microtask_checkpoint.get() {
@@ -76,7 +84,11 @@ impl MicrotaskQueue {
rooted_vec!(let mut pending_queue);
mem::swap(&mut *pending_queue, &mut *self.microtask_queue.borrow_mut());
- for job in pending_queue.iter() {
+ for (idx, job) in pending_queue.iter().enumerate() {
+ if idx == pending_queue.len() - 1 && self.microtask_queue.borrow().is_empty() {
+ JobQueueIsEmpty(cx);
+ }
+
match *job {
Microtask::Promise(ref job) => {
if let Some(target) = target_provider(job.pipeline) {
@@ -109,4 +121,8 @@ impl MicrotaskQueue {
// Step 5
self.performing_a_microtask_checkpoint.set(false);
}
+
+ pub fn empty(&self) -> bool {
+ self.microtask_queue.borrow().is_empty()
+ }
}