Auto merge of #21111 - gterzian:implement_document_load_cancellation, r=jdm

Implement document load cancellation

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [ ] `./mach build -d` does not report any errors
- [ ] `./mach test-tidy` does not report any errors
- [ ] These changes fix #19309 fix #21114 fix #21113 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/21111)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-07-29 11:14:29 -04:00 committed by GitHub
commit 076198fe80
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 195 additions and 104 deletions

View file

@ -26,6 +26,10 @@ DOMInterfaces = {
'weakReferenceable': True,
},
'EventSource': {
'weakReferenceable': True,
},
#FIXME(jdm): This should be 'register': False, but then we don't generate enum types
'TestBinding': {},

View file

@ -11,6 +11,7 @@
//! slot. When all associated `WeakRef` values are dropped, the
//! `WeakBox` itself is dropped too.
use dom::bindings::cell::DomRefCell;
use dom::bindings::reflector::DomObject;
use dom::bindings::root::DomRoot;
use dom::bindings::trace::JSTraceable;
@ -286,3 +287,34 @@ impl<'a, T: WeakReferenceable + 'a> Drop for WeakRefEntry<'a, T> {
*self.index += 1;
}
}
#[derive(MallocSizeOf)]
pub struct DOMTracker<T: WeakReferenceable> {
dom_objects: DomRefCell<WeakRefVec<T>>
}
impl<T: WeakReferenceable> DOMTracker<T> {
pub fn new() -> Self {
Self {
dom_objects: DomRefCell::new(WeakRefVec::new())
}
}
pub fn track(&self, dom_object: &T) {
self.dom_objects.borrow_mut().push(WeakRef::new(dom_object));
}
pub fn for_each<F: FnMut(DomRoot<T>)>(&self, mut f: F) {
self.dom_objects.borrow_mut().update(|weak_ref| {
let root = weak_ref.root().unwrap();
f(root);
});
}
}
#[allow(unsafe_code)]
unsafe impl<T: WeakReferenceable> JSTraceable for DOMTracker<T> {
unsafe fn trace(&self, _: *mut JSTracer) {
self.dom_objects.borrow_mut().retain_alive();
}
}