Skip to content

Commit 1060cfd

Browse files
author
bors-servo
committed
Auto merge of servo#6152 - glennw:runnable-panic, r=jdm
<!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6152) <!-- Reviewable:end -->
2 parents 7ae5d11 + b84c6fa commit 1060cfd

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

components/gfx/paint_task.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ impl<C> PaintTask<C> where C: PaintListener + Send + 'static {
308308
// If we own buffers in the compositor and we are not exiting completely, wait
309309
// for the compositor to return buffers, so that we can release them properly.
310310
// When doing a complete exit, the compositor lets all buffers leak.
311-
println!("PaintTask {:?}: Saw ExitMsg, {} buffers in use", self.id, self.used_buffer_count);
311+
debug!("PaintTask {:?}: Saw ExitMsg, {} buffers in use", self.id, self.used_buffer_count);
312312
waiting_for_compositor_buffers_to_exit = true;
313313
exit_response_channel = response_channel;
314314
}

components/script/dom/document.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,13 +1830,17 @@ impl DocumentProgressHandler {
18301830

18311831
impl Runnable for DocumentProgressHandler {
18321832
fn handler(self: Box<DocumentProgressHandler>) {
1833-
match self.task {
1834-
DocumentProgressTask::DOMContentLoaded => {
1835-
self.dispatch_dom_content_loaded();
1836-
}
1837-
DocumentProgressTask::Load => {
1838-
self.set_ready_state_complete();
1839-
self.dispatch_load();
1833+
let document = self.addr.to_temporary().root();
1834+
let window = document.r().window().root();
1835+
if window.r().is_alive() {
1836+
match self.task {
1837+
DocumentProgressTask::DOMContentLoaded => {
1838+
self.dispatch_dom_content_loaded();
1839+
}
1840+
DocumentProgressTask::Load => {
1841+
self.set_ready_state_complete();
1842+
self.dispatch_load();
1843+
}
18401844
}
18411845
}
18421846
}

components/script/dom/window.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ use std::sync::mpsc::{channel, Receiver, Sender};
6969
use std::sync::mpsc::TryRecvError::{Empty, Disconnected};
7070
use time;
7171

72+
/// Current state of the window object
73+
#[derive(Copy, Clone, Debug, PartialEq)]
74+
#[jstraceable]
75+
enum WindowState {
76+
Alive,
77+
Zombie, // Pipeline is closed, but the window hasn't been GCed yet.
78+
}
79+
7280
/// Extra information concerning the reason for reflowing.
7381
#[derive(Debug)]
7482
pub enum ReflowReason {
@@ -170,7 +178,10 @@ pub struct Window {
170178
pending_reflow_count: Cell<u32>,
171179

172180
/// A channel for communicating results of async scripts back to the webdriver server
173-
webdriver_script_chan: RefCell<Option<Sender<WebDriverJSResult>>>
181+
webdriver_script_chan: RefCell<Option<Sender<WebDriverJSResult>>>,
182+
183+
/// The current state of the window object
184+
current_state: Cell<WindowState>,
174185
}
175186

176187
impl Window {
@@ -179,6 +190,7 @@ impl Window {
179190
unsafe {
180191
*self.js_runtime.borrow_for_script_deallocation() = None;
181192
*self.browser_context.borrow_for_script_deallocation() = None;
193+
self.current_state.set(WindowState::Zombie);
182194
}
183195
}
184196

@@ -544,6 +556,7 @@ pub trait WindowHelpers {
544556
fn set_devtools_timeline_marker(self, marker: TimelineMarkerType, reply: Sender<TimelineMarker>);
545557
fn drop_devtools_timeline_markers(self);
546558
fn set_webdriver_script_chan(self, chan: Option<Sender<WebDriverJSResult>>);
559+
fn is_alive(self) -> bool;
547560
}
548561

549562
pub trait ScriptHelpers {
@@ -595,6 +608,7 @@ impl<'a> WindowHelpers for JSRef<'a, Window> {
595608
// which causes a panic!
596609
self.Gc();
597610

611+
self.current_state.set(WindowState::Zombie);
598612
*self.js_runtime.borrow_mut() = None;
599613
*self.browser_context.borrow_mut() = None;
600614
}
@@ -916,6 +930,10 @@ impl<'a> WindowHelpers for JSRef<'a, Window> {
916930
fn set_webdriver_script_chan(self, chan: Option<Sender<WebDriverJSResult>>) {
917931
*self.webdriver_script_chan.borrow_mut() = chan;
918932
}
933+
934+
fn is_alive(self) -> bool {
935+
self.current_state.get() == WindowState::Alive
936+
}
919937
}
920938

921939
impl Window {
@@ -979,6 +997,7 @@ impl Window {
979997
layout_join_port: DOMRefCell::new(None),
980998
window_size: Cell::new(window_size),
981999
pending_reflow_count: Cell::new(0),
1000+
current_state: Cell::new(WindowState::Alive),
9821001

9831002
devtools_marker_sender: RefCell::new(None),
9841003
devtools_markers: RefCell::new(HashSet::new()),

0 commit comments

Comments
 (0)