Auto merge of #11684 - servo:fix-failsafe, r=jdm

Avoid an index-out-of-bounds error in ScriptMemoryFailsafe.

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11684)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-06-09 11:33:17 -05:00
commit 0ac1ff0661
2 changed files with 10 additions and 2 deletions

View file

@ -108,6 +108,12 @@ impl BrowsingContext {
Root::from_ref(&self.history.borrow()[self.active_index.get()].document)
}
pub fn maybe_active_document(&self) -> Option<Root<Document>> {
self.history.borrow().get(self.active_index.get()).map(|entry| {
Root::from_ref(&*entry.document)
})
}
pub fn active_window(&self) -> Root<Window> {
Root::from_ref(self.active_document().window())
}

View file

@ -422,8 +422,10 @@ impl<'a> Drop for ScriptMemoryFailsafe<'a> {
Some(owner) => {
let context = owner.browsing_context.get();
for context in context.iter() {
let window = context.active_window();
window.clear_js_runtime_for_script_deallocation();
if let Some(document) = context.maybe_active_document() {
let window = document.window();
window.clear_js_runtime_for_script_deallocation();
}
}
}
None => (),