Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix various crashes, leaks, and cycles #468

Closed
wants to merge 6 commits into from

Add document teardown operation to safely remove rooting for DOM tree…

… and prevent leaks.
  • Loading branch information
jdm committed May 22, 2013
commit 982dd0c0f037ae0077fbdf322852b4d8cfce7bba
@@ -34,18 +34,6 @@ pub fn Document(root: AbstractNode, window: Option<@mut Window>) -> @mut Documen
doc
}

#[unsafe_destructor]
impl Drop for Document {
fn finalize(&self) {
let compartment = global_script_context().js_compartment;
do self.root.with_base |base| {
assert!(base.wrapper.get_wrapper().is_not_null());
let rootable = base.wrapper.get_rootable();
JS_RemoveObjectRoot(compartment.cx.ptr, rootable);
}
}
}

pub impl Document {
fn getElementsByTagName(&self, tag: DOMString) -> Option<@mut HTMLCollection> {
let mut elements = ~[];
@@ -67,5 +55,14 @@ pub impl Document {
window.content_changed()
}
}

fn teardown(&self) {
let compartment = global_script_context().js_compartment;
do self.root.with_base |node| {
assert!(node.wrapper.get_wrapper().is_not_null());
let rootable = node.wrapper.get_rootable();
JS_RemoveObjectRoot(compartment.cx.ptr, rootable);
}
}
}

@@ -285,6 +285,10 @@ impl ScriptContext {

/// Handles a request to exit the script task and shut down layout.
fn handle_exit_msg(&mut self) {
self.join_layout();
for self.root_frame.each |frame| {
frame.document.teardown();
}
self.layout_task.send(layout_task::ExitMsg)
}

@@ -5,7 +5,8 @@ var count = 1000000;
var start = new Date();
for (var i = 0; i < count; i++) {
div.setAttribute('id', 'styled');
div.getBoundingClientRect();
//div.getBoundingClientRect();
}
var stop = new Date();
window.alert((stop - start) / count * 1e6);
window.close();
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.