@@ -69,6 +69,14 @@ use std::sync::mpsc::{channel, Receiver, Sender};
69
69
use std:: sync:: mpsc:: TryRecvError :: { Empty , Disconnected } ;
70
70
use time;
71
71
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
+
72
80
/// Extra information concerning the reason for reflowing.
73
81
#[ derive( Debug ) ]
74
82
pub enum ReflowReason {
@@ -170,7 +178,10 @@ pub struct Window {
170
178
pending_reflow_count : Cell < u32 > ,
171
179
172
180
/// 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 > ,
174
185
}
175
186
176
187
impl Window {
@@ -179,6 +190,7 @@ impl Window {
179
190
unsafe {
180
191
* self . js_runtime . borrow_for_script_deallocation ( ) = None ;
181
192
* self . browser_context . borrow_for_script_deallocation ( ) = None ;
193
+ self . current_state . set ( WindowState :: Zombie ) ;
182
194
}
183
195
}
184
196
@@ -544,6 +556,7 @@ pub trait WindowHelpers {
544
556
fn set_devtools_timeline_marker ( self , marker : TimelineMarkerType , reply : Sender < TimelineMarker > ) ;
545
557
fn drop_devtools_timeline_markers ( self ) ;
546
558
fn set_webdriver_script_chan ( self , chan : Option < Sender < WebDriverJSResult > > ) ;
559
+ fn is_alive ( self ) -> bool ;
547
560
}
548
561
549
562
pub trait ScriptHelpers {
@@ -595,6 +608,7 @@ impl<'a> WindowHelpers for JSRef<'a, Window> {
595
608
// which causes a panic!
596
609
self . Gc ( ) ;
597
610
611
+ self . current_state . set ( WindowState :: Zombie ) ;
598
612
* self . js_runtime . borrow_mut ( ) = None ;
599
613
* self . browser_context . borrow_mut ( ) = None ;
600
614
}
@@ -916,6 +930,10 @@ impl<'a> WindowHelpers for JSRef<'a, Window> {
916
930
fn set_webdriver_script_chan ( self , chan : Option < Sender < WebDriverJSResult > > ) {
917
931
* self . webdriver_script_chan . borrow_mut ( ) = chan;
918
932
}
933
+
934
+ fn is_alive ( self ) -> bool {
935
+ self . current_state . get ( ) == WindowState :: Alive
936
+ }
919
937
}
920
938
921
939
impl Window {
@@ -979,6 +997,7 @@ impl Window {
979
997
layout_join_port : DOMRefCell :: new ( None ) ,
980
998
window_size : Cell :: new ( window_size) ,
981
999
pending_reflow_count : Cell :: new ( 0 ) ,
1000
+ current_state : Cell :: new ( WindowState :: Alive ) ,
982
1001
983
1002
devtools_marker_sender : RefCell :: new ( None ) ,
984
1003
devtools_markers : RefCell :: new ( HashSet :: new ( ) ) ,
0 commit comments