Skip to content

Commit

Permalink
Auto merge of #21988 - CYBAI:drop-promises, r=jdm
Browse files Browse the repository at this point in the history
Clear refcounted promise before dropping JSRuntime

Not sure if this is the right solution?

I also tried to `impl Drop for LiveDOMReferences` but it's still executed after dropping JSRuntime.
So, maybe we should clear it before dropping the JSRuntime?

cc @jdm @asajeffrey

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #21331 .
- [x] There are tests for these changes; the status of `fetch/cross-origin-resource-policy/fetch-in-iframe.html` will be `OK`

<!-- 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/21988)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Oct 29, 2018
2 parents cbd81d2 + 2a7db89 commit e580250
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions components/script/dom/bindings/refcounted.rs
Expand Up @@ -224,6 +224,12 @@ impl LiveDOMReferences {
});
}

pub fn destruct() {
LIVE_REFERENCES.with(|ref r| {
*r.borrow_mut() = None;
});
}

#[allow(unrooted_must_root)]
fn addref_promise(&self, promise: Rc<Promise>) {
let mut table = self.promise_table.borrow_mut();
Expand Down
5 changes: 4 additions & 1 deletion components/script/script_runtime.rs
Expand Up @@ -271,7 +271,10 @@ pub struct Runtime(RustRuntime);

impl Drop for Runtime {
fn drop(&mut self) {
THREAD_ACTIVE.with(|t| t.set(false));
THREAD_ACTIVE.with(|t| {
LiveDOMReferences::destruct();
t.set(false);
});
}
}

Expand Down

0 comments on commit e580250

Please sign in to comment.