diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs
index acf1d2ed9ce..7cebebade0a 100644
--- a/components/script/dom/htmlimageelement.rs
+++ b/components/script/dom/htmlimageelement.rs
@@ -429,16 +429,12 @@ impl HTMLImageElement {
return None
}
- let map = self.upcast::()
- .following_siblings()
- .filter_map(Root::downcast::)
- .find(|n| n.upcast::().get_string_attribute(&LocalName::from("name")) == last);
+ let useMapElements = document_from_node(self).upcast::()
+ .traverse_preorder()
+ .filter_map(Root::downcast::)
+ .find(|n| n.upcast::().get_string_attribute(&LocalName::from("name")) == last);
- let elements: Vec> = map.unwrap().upcast::()
- .children()
- .filter_map(Root::downcast::)
- .collect();
- Some(elements)
+ useMapElements.map(|mapElem| mapElem.get_area_elements())
}
}
diff --git a/components/script/dom/htmlmapelement.rs b/components/script/dom/htmlmapelement.rs
index c6bcb615431..9a2ae807619 100644
--- a/components/script/dom/htmlmapelement.rs
+++ b/components/script/dom/htmlmapelement.rs
@@ -3,9 +3,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::Bindings::HTMLMapElementBinding;
+use dom::bindings::inheritance::Castable;
use dom::bindings::js::Root;
use dom::bindings::str::DOMString;
use dom::document::Document;
+use dom::htmlareaelement::HTMLAreaElement;
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use dom_struct::dom_struct;
@@ -33,4 +35,11 @@ impl HTMLMapElement {
document,
HTMLMapElementBinding::Wrap)
}
+
+ pub fn get_area_elements(&self) -> Vec> {
+ self.upcast::()
+ .traverse_preorder()
+ .filter_map(Root::downcast::).collect()
+ }
}
+
diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json
index aeb28a8527b..3e7ec3422b6 100644
--- a/tests/wpt/mozilla/meta/MANIFEST.json
+++ b/tests/wpt/mozilla/meta/MANIFEST.json
@@ -12960,12 +12960,24 @@
{}
]
],
+ "mozilla/img_find_non_sibling_map.html": [
+ [
+ "/_mozilla/mozilla/img_find_non_sibling_map.html",
+ {}
+ ]
+ ],
"mozilla/img_multiple_request.html": [
[
"/_mozilla/mozilla/img_multiple_request.html",
{}
]
],
+ "mozilla/img_no_panic_on_no_map.html": [
+ [
+ "/_mozilla/mozilla/img_no_panic_on_no_map.html",
+ {}
+ ]
+ ],
"mozilla/img_width_height.html": [
[
"/_mozilla/mozilla/img_width_height.html",
@@ -25489,10 +25501,18 @@
"3c4f36abed83367c851d943b1f25b8394de6fe75",
"testharness"
],
+ "mozilla/img_find_non_sibling_map.html": [
+ "d34100c4cc22adcaa1014095ba4b7b929b8e079d",
+ "testharness"
+ ],
"mozilla/img_multiple_request.html": [
"0a6263ad87c9b3307f2dc694747b094a0517b79b",
"testharness"
],
+ "mozilla/img_no_panic_on_no_map.html": [
+ "be2ae22f4664b4577224ba6c7f3c4df8589c160a",
+ "testharness"
+ ],
"mozilla/img_width_height.html": [
"37a04735261a6d2b36c3d529ce81eda46ed6967e",
"testharness"
diff --git a/tests/wpt/mozilla/tests/mozilla/img_find_non_sibling_map.html b/tests/wpt/mozilla/tests/mozilla/img_find_non_sibling_map.html
new file mode 100644
index 00000000000..9b88509ecce
--- /dev/null
+++ b/tests/wpt/mozilla/tests/mozilla/img_find_non_sibling_map.html
@@ -0,0 +1,22 @@
+
+
+Test for issue #15884
+
+
+
+
+
+
+
+
+
diff --git a/tests/wpt/mozilla/tests/mozilla/img_no_panic_on_no_map.html b/tests/wpt/mozilla/tests/mozilla/img_no_panic_on_no_map.html
new file mode 100644
index 00000000000..e9f1b56ac4c
--- /dev/null
+++ b/tests/wpt/mozilla/tests/mozilla/img_no_panic_on_no_map.html
@@ -0,0 +1,18 @@
+
+
+ Test for issue #15884
+
+
+
+
+
+
+