Bug 1223523. The named getter on document should not return images with an empty name. r=peterv

This commit is contained in:
Boris Zbarsky 2015-11-20 16:54:49 -05:00
parent 3aeb07f68e
commit 90b1f50abc
5 changed files with 13 additions and 18 deletions

View File

@ -960,10 +960,16 @@ public:
static inline bool
ShouldExposeIdAsHTMLDocumentProperty(Element* aElement)
{
return aElement->IsAnyOfHTMLElements(nsGkAtoms::img,
nsGkAtoms::applet,
nsGkAtoms::embed,
nsGkAtoms::object);
if (aElement->IsAnyOfHTMLElements(nsGkAtoms::applet,
nsGkAtoms::embed,
nsGkAtoms::object)) {
return true;
}
// Per spec, <img> is exposed by id only if it also has a nonempty
// name (which doesn't have to match the id or anything).
// HasName() is true precisely when name is nonempty.
return aElement->IsHTMLElement(nsGkAtoms::img) && aElement->HasName();
}
static bool

View File

@ -1,5 +1,3 @@
{
"If there are two imgs, a collection should be returned. (name)": true,
"If there is one img, it should not be returned (id)": true,
"If there are two imgs, nothing should be returned. (id)": true
"If there are two imgs, a collection should be returned. (name)": true
}

View File

@ -63,9 +63,7 @@ test(function() {
assert_equals(img2.id, "test4");
assert_false("test4" in document, '"test4" in document should be false');
var collection = document.test4;
assert_class_string(collection, "HTMLCollection", "collection should be an HTMLCollection");
assert_array_equals(collection, [img1, img2]);
assert_equals(document.test4, undefined);
}, "If there are two imgs, nothing should be returned. (id)");
test(function() {

View File

@ -2,10 +2,3 @@
type: testharness
[If there are two imgs, a collection should be returned. (name)]
expected: FAIL
[If there is one img, it should not be returned (id)]
expected: FAIL
[If there are two imgs, nothing should be returned. (id)]
expected: FAIL

View File

@ -15,7 +15,7 @@
<img id=test3>
<img id=test4>
<img id=test4>
<img id=test4 name="">
<img name=test5>
<img id=test5>