Separate disposing of layout data from the GCing of the DOM object reflectors. Change the order of operations when shutting down the script task to ensure that Window globals aren't used after they've been GCed.

This commit is contained in:
Josh Matthews 2015-02-26 00:19:27 -05:00
parent c816975750
commit 4972b623e1
3 changed files with 20 additions and 11 deletions

View file

@ -490,9 +490,18 @@ pub trait NodeHelpers<'a> {
fn get_unique_id(self) -> String;
fn summarize(self) -> NodeInfo;
fn teardown(self);
}
impl<'a> NodeHelpers<'a> for JSRef<'a, Node> {
fn teardown(self) {
self.layout_data.dispose();
for kid in self.children() {
kid.teardown();
}
}
/// Dumps the subtree rooted at this node, for debugging.
fn dump(self) {
self.dump_indent(0);

View file

@ -461,6 +461,9 @@ impl<'a, T: Reflectable> ScriptHelpers for JSRef<'a, T> {
impl<'a> WindowHelpers for JSRef<'a, Window> {
fn clear_js_context(self) {
let document = self.Document().root();
NodeCast::from_ref(document.r()).teardown();
*self.js_context.borrow_mut() = None;
*self.browser_context.borrow_mut() = None;
}