Do not panic on navigating across documents

This commit is contained in:
Utsav Oza 2020-07-30 16:31:36 +05:30
parent da45522085
commit 962e620529
3 changed files with 12 additions and 8 deletions

View file

@ -560,7 +560,8 @@ impl Document {
let new_dirty_root = element let new_dirty_root = element
.upcast::<Node>() .upcast::<Node>()
.common_ancestor(dirty_root.upcast(), ShadowIncluding::Yes); .common_ancestor(dirty_root.upcast(), ShadowIncluding::Yes)
.expect("Couldn't find common ancestor");
let mut has_dirty_descendants = true; let mut has_dirty_descendants = true;
for ancestor in dirty_root for ancestor in dirty_root
@ -1515,10 +1516,12 @@ impl Document {
FireMouseEventType::Enter | FireMouseEventType::Leave FireMouseEventType::Enter | FireMouseEventType::Leave
)); ));
let common_ancestor = related_target.as_ref().map_or_else( let common_ancestor = match related_target.as_ref() {
|| DomRoot::from_ref(&*event_target), Some(related_target) => event_target
|related_target| event_target.common_ancestor(related_target, ShadowIncluding::No), .common_ancestor(related_target, ShadowIncluding::No)
); .unwrap_or_else(|| DomRoot::from_ref(&*event_target)),
None => DomRoot::from_ref(&*event_target),
};
// We need to create a target chain in case the event target shares // We need to create a target chain in case the event target shares
// its boundaries with its ancestors. // its boundaries with its ancestors.

View file

@ -708,16 +708,16 @@ impl Node {
&self, &self,
other: &Node, other: &Node,
shadow_including: ShadowIncluding, shadow_including: ShadowIncluding,
) -> DomRoot<Node> { ) -> Option<DomRoot<Node>> {
for ancestor in self.inclusive_ancestors(shadow_including) { for ancestor in self.inclusive_ancestors(shadow_including) {
if other if other
.inclusive_ancestors(shadow_including) .inclusive_ancestors(shadow_including)
.any(|node| node == ancestor) .any(|node| node == ancestor)
{ {
return ancestor; return Some(ancestor);
} }
} }
unreachable!(); None
} }
pub fn is_inclusive_ancestor_of(&self, parent: &Node) -> bool { pub fn is_inclusive_ancestor_of(&self, parent: &Node) -> bool {

View file

@ -298,6 +298,7 @@ impl RangeMethods for Range {
fn CommonAncestorContainer(&self) -> DomRoot<Node> { fn CommonAncestorContainer(&self) -> DomRoot<Node> {
self.EndContainer() self.EndContainer()
.common_ancestor(&self.StartContainer(), ShadowIncluding::No) .common_ancestor(&self.StartContainer(), ShadowIncluding::No)
.expect("Couldn't find common ancestor container")
} }
// https://dom.spec.whatwg.org/#dom-range-setstart // https://dom.spec.whatwg.org/#dom-range-setstart