aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorJosh Matthews <josh@joshmatthews.net>2015-02-27 19:17:55 -0500
committerJosh Matthews <josh@joshmatthews.net>2015-03-03 16:25:40 -0500
commit1fb12b11f4beb2a544ba9ba1a4624aff857ad649 (patch)
treeee5c5613b8f89e54d1d9294344fcd0e4624a7c02 /components/script
parent4972b623e18d2bdad62a8c617e6885eb9b8158b8 (diff)
downloadservo-1fb12b11f4beb2a544ba9ba1a4624aff857ad649.tar.gz
servo-1fb12b11f4beb2a544ba9ba1a4624aff857ad649.zip
Remove the newly-created Page from the tree if loading fails.
Diffstat (limited to 'components/script')
-rw-r--r--components/script/script_task.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/components/script/script_task.rs b/components/script/script_task.rs
index 0538b2c0b72..59b6278a67d 100644
--- a/components/script/script_task.rs
+++ b/components/script/script_task.rs
@@ -909,6 +909,49 @@ impl ScriptTask {
parent_page.children.borrow_mut().push(page.clone());
}
+ enum PageToRemove {
+ Root,
+ Child(PipelineId),
+ }
+ struct AutoPageRemover<'a> {
+ page: PageToRemove,
+ script_task: &'a ScriptTask,
+ neutered: bool,
+ }
+ impl<'a> AutoPageRemover<'a> {
+ fn new(script_task: &'a ScriptTask, page: PageToRemove) -> AutoPageRemover<'a> {
+ AutoPageRemover {
+ page: page,
+ script_task: script_task,
+ neutered: false,
+ }
+ }
+
+ fn neuter(&mut self) {
+ self.neutered = true;
+ }
+ }
+ #[unsafe_destructor]
+ impl<'a> Drop for AutoPageRemover<'a> {
+ fn drop(&mut self) {
+ if !self.neutered {
+ match self.page {
+ PageToRemove::Root => *self.script_task.page.borrow_mut() = None,
+ PageToRemove::Child(id) => {
+ let _ = self.script_task.root_page().remove(id);
+ }
+ }
+ }
+ }
+ }
+
+ let page_to_remove = if !root_page_exists {
+ PageToRemove::Root
+ } else {
+ PageToRemove::Child(incomplete.pipeline_id)
+ };
+ let mut page_remover = AutoPageRemover::new(self, page_to_remove);
+
// Create the window and document objects.
let window = Window::new(cx.clone(),
page.clone(),
@@ -1000,6 +1043,8 @@ impl ScriptTask {
page_info)).unwrap();
}
}
+
+ page_remover.neuter();
}
fn scroll_fragment_point(&self, pipeline_id: PipelineId, node: JSRef<Element>) {