Auto merge of #7557 - glennw:fix-layout-panic, r=pcwalton

Handle cases where the layout root is None. Fixes #6375.



<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7557)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-09-08 20:39:09 -06:00
commit 4221b354cf
3 changed files with 196 additions and 96 deletions

View file

@ -156,6 +156,14 @@ pub struct LayoutTaskData {
pub visible_rects: Arc<HashMap<LayerId, Rect<Au>, DefaultState<FnvHasher>>>,
}
impl LayoutTaskData {
pub fn layout_root(&self) -> Option<FlowRef> {
self.root_flow.as_ref().map(|root_flow| {
root_flow.clone()
})
}
}
/// Information needed by the layout task.
pub struct LayoutTask {
/// The ID of the pipeline that we belong to.
@ -786,10 +794,6 @@ impl LayoutTask {
Some(flow)
}
fn get_layout_root(&self, node: LayoutNode) -> FlowRef {
self.try_get_layout_root(node).expect("no layout root")
}
/// Performs layout constraint solving.
///
/// This corresponds to `Reflow()` in Gecko and `layout()` in WebKit/Blink and should be
@ -1161,7 +1165,7 @@ impl LayoutTask {
});
// Retrieve the (possibly rebuilt) root flow.
rw_data.root_flow = Some(self.get_layout_root((*node).clone()));
rw_data.root_flow = self.try_get_layout_root((*node).clone());
// Kick off animations if any were triggered.
animation::process_new_animations(&mut *rw_data, self.id);
@ -1178,7 +1182,7 @@ impl LayoutTask {
&mut rw_data,
&mut shared_layout_context);
let mut root_flow = (*rw_data.root_flow.as_ref().unwrap()).clone();
if let Some(mut root_flow) = rw_data.layout_root() {
match data.query_type {
ReflowQueryType::ContentBoxQuery(node) =>
process_content_box_request(node, &mut root_flow, &mut rw_data),
@ -1192,7 +1196,7 @@ impl LayoutTask {
self.process_offset_parent_query(node, &mut root_flow, &mut rw_data),
ReflowQueryType::NoQuery => {}
}
}
// Tell script that we're done.
//
@ -1279,14 +1283,8 @@ impl LayoutTask {
&self.url,
reflow_info.goal);
match rw_data.root_flow.as_ref() {
None => {
// We haven't performed a single layout yet! Do nothing.
return
}
Some(ref root_flow) => {
if let Some(mut root_flow) = rw_data.layout_root() {
// Perform an abbreviated style recalc that operates without access to the DOM.
let mut root_flow = (*root_flow).clone();
let animations = &*rw_data.running_animations;
profile(time::ProfilerCategory::LayoutStyleRecalc,
self.profiler_metadata(),
@ -1296,7 +1294,6 @@ impl LayoutTask {
animations)
});
}
}
self.perform_post_style_recalc_layout_passes(&reflow_info,
&mut *rw_data,
@ -1307,7 +1304,7 @@ impl LayoutTask {
data: &Reflow,
rw_data: &mut LayoutTaskData,
layout_context: &mut SharedLayoutContext) {
let mut root_flow = (*rw_data.root_flow.as_ref().unwrap()).clone();
if let Some(mut root_flow) = rw_data.layout_root() {
profile(time::ProfilerCategory::LayoutRestyleDamagePropagation,
self.profiler_metadata(),
self.time_profiler_chan.clone(),
@ -1356,13 +1353,14 @@ impl LayoutTask {
self.perform_post_main_layout_passes(data, rw_data, layout_context);
}
}
fn perform_post_main_layout_passes<'a>(&'a self,
data: &Reflow,
rw_data: &mut LayoutTaskData,
layout_context: &mut SharedLayoutContext) {
// Build the display list if necessary, and send it to the painter.
let mut root_flow = (*rw_data.root_flow.as_ref().unwrap()).clone();
if let Some(mut root_flow) = rw_data.layout_root() {
self.compute_abs_pos_and_build_display_list(data,
&mut root_flow,
&mut *layout_context,
@ -1379,6 +1377,7 @@ impl LayoutTask {
rw_data.generation += 1;
}
}
unsafe fn dirty_all_nodes(node: &mut LayoutNode) {
for node in node.traverse_preorder() {

View file

@ -1,3 +1,3 @@
[root-box-003.htm]
type: reftest
expected: CRASH
expected: TIMEOUT

View file

@ -1,3 +1,104 @@
[Document-createElement-namespace.html]
type: testharness
disabled: Issue 6386
[Created element's namespace in created XML document]
expected: FAIL
[Created element's namespace in created XHTML document]
expected: FAIL
[Created element's namespace in created SVG document]
expected: FAIL
[Created element's namespace in created MathML document]
expected: FAIL
[Created element's namespace in empty.xhtml]
expected: FAIL
[Created element's namespace in empty.xml]
expected: FAIL
[Created element's namespace in empty.svg]
expected: FAIL
[Created element's namespace in minimal_html.xhtml]
expected: FAIL
[Created element's namespace in minimal_html.xml]
expected: FAIL
[Created element's namespace in minimal_html.svg]
expected: FAIL
[Created element's namespace in xhtml.xhtml]
expected: FAIL
[Created element's namespace in xhtml.xml]
expected: FAIL
[Created element's namespace in xhtml.svg]
expected: FAIL
[Created element's namespace in svg.xhtml]
expected: FAIL
[Created element's namespace in svg.xml]
expected: FAIL
[Created element's namespace in svg.svg]
expected: FAIL
[Created element's namespace in mathml.xhtml]
expected: FAIL
[Created element's namespace in mathml.xml]
expected: FAIL
[Created element's namespace in mathml.svg]
expected: FAIL
[Created element's namespace in bare_xhtml.xhtml]
expected: FAIL
[Created element's namespace in bare_xhtml.xml]
expected: FAIL
[Created element's namespace in bare_xhtml.svg]
expected: FAIL
[Created element's namespace in bare_svg.xhtml]
expected: FAIL
[Created element's namespace in bare_svg.xml]
expected: FAIL
[Created element's namespace in bare_svg.svg]
expected: FAIL
[Created element's namespace in bare_mathml.xhtml]
expected: FAIL
[Created element's namespace in bare_mathml.xml]
expected: FAIL
[Created element's namespace in bare_mathml.svg]
expected: FAIL
[Created element's namespace in xhtml_ns_removed.xhtml]
expected: FAIL
[Created element's namespace in xhtml_ns_removed.xml]
expected: FAIL
[Created element's namespace in xhtml_ns_removed.svg]
expected: FAIL
[Created element's namespace in xhtml_ns_changed.xhtml]
expected: FAIL
[Created element's namespace in xhtml_ns_changed.xml]
expected: FAIL
[Created element's namespace in xhtml_ns_changed.svg]
expected: FAIL