Bug 1389922 - Update HTMLAllCollection IDL to spec; r?smaug
The expected fail in interfaces.html is bogus, due to a test bug that's
being fixed upstream at the given link. The added failure in
htmlallcollection.html will be fixed in a later commit. The update to
html.idl is per the current spec and is also submitted upstream.
MozReview-Commit-ID: 5ntR2xAYQDz
--- a/dom/html/HTMLAllCollection.cpp
+++ b/dom/html/HTMLAllCollection.cpp
@@ -44,20 +44,32 @@ HTMLAllCollection::GetParentObject() con
}
uint32_t
HTMLAllCollection::Length()
{
return Collection()->Length(true);
}
-nsIContent*
+Element*
HTMLAllCollection::Item(uint32_t aIndex)
{
- return Collection()->Item(aIndex);
+ nsCOMPtr<nsIContent> content = Collection()->Item(aIndex);
+ return content ? content->AsElement() : nullptr;
+}
+
+void
+HTMLAllCollection::Item(const Optional<nsAString>& aName,
+ Nullable<OwningHTMLCollectionOrElement>& aResult)
+{
+ if (!aName.WasPassed()) {
+ aResult.SetNull();
+ return;
+ }
+ NamedItem(aName.Value(), aResult);
}
nsContentList*
HTMLAllCollection::Collection()
{
if (!mCollection) {
nsIDocument* document = mDocument;
mCollection = document->GetElementsByTagName(NS_LITERAL_STRING("*"));
@@ -116,17 +128,17 @@ HTMLAllCollection::GetDocumentAllList(co
return new nsContentList(mDocument, DocAllResultMatch, nullptr,
nullptr, true, id);
});
}
void
HTMLAllCollection::NamedGetter(const nsAString& aID,
bool& aFound,
- Nullable<OwningNodeOrHTMLCollection>& aResult)
+ Nullable<OwningHTMLCollectionOrElement>& aResult)
{
if (aID.IsEmpty()) {
aFound = false;
aResult.SetNull();
return;
}
nsContentList* docAllList = GetDocumentAllList(aID);
@@ -143,17 +155,17 @@ HTMLAllCollection::NamedGetter(const nsA
aFound = true;
aResult.SetValue().SetAsHTMLCollection() = docAllList;
return;
}
// There's only 0 or 1 items. Return the first one or null.
if (nsIContent* node = docAllList->Item(0, true)) {
aFound = true;
- aResult.SetValue().SetAsNode() = node;
+ aResult.SetValue().SetAsElement() = node->AsElement();
return;
}
aFound = false;
aResult.SetNull();
}
void
--- a/dom/html/HTMLAllCollection.h
+++ b/dom/html/HTMLAllCollection.h
@@ -6,28 +6,31 @@
#ifndef mozilla_dom_HTMLAllCollection_h
#define mozilla_dom_HTMLAllCollection_h
#include "nsCycleCollectionParticipant.h"
#include "nsISupportsImpl.h"
#include "nsRefPtrHashtable.h"
#include "nsWrapperCache.h"
+#include "mozilla/dom/BindingDeclarations.h"
+#include "mozilla/dom/Nullable.h"
#include <stdint.h>
class nsContentList;
class nsHTMLDocument;
class nsIContent;
class nsINode;
namespace mozilla {
namespace dom {
-class OwningNodeOrHTMLCollection;
+class Element;
+class OwningHTMLCollectionOrElement;
template<typename> struct Nullable;
class HTMLAllCollection final : public nsISupports
, public nsWrapperCache
{
~HTMLAllCollection();
public:
@@ -35,42 +38,40 @@ public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(HTMLAllCollection)
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
nsINode* GetParentObject() const;
uint32_t Length();
- nsIContent* Item(uint32_t aIndex);
- void Item(const nsAString& aName, Nullable<OwningNodeOrHTMLCollection>& aResult)
+ Element* Item(uint32_t aIndex);
+ void Item(const Optional<nsAString>& aName,
+ Nullable<OwningHTMLCollectionOrElement>& aResult);
+ Element* IndexedGetter(uint32_t aIndex, bool& aFound)
{
- NamedItem(aName, aResult);
- }
- nsIContent* IndexedGetter(uint32_t aIndex, bool& aFound)
- {
- nsIContent* result = Item(aIndex);
+ Element* result = Item(aIndex);
aFound = !!result;
return result;
}
void NamedItem(const nsAString& aName,
- Nullable<OwningNodeOrHTMLCollection>& aResult)
+ Nullable<OwningHTMLCollectionOrElement>& aResult)
{
bool found = false;
NamedGetter(aName, found, aResult);
}
void NamedGetter(const nsAString& aName,
bool& aFound,
- Nullable<OwningNodeOrHTMLCollection>& aResult);
+ Nullable<OwningHTMLCollectionOrElement>& aResult);
void GetSupportedNames(nsTArray<nsString>& aNames);
- void LegacyCall(JS::Handle<JS::Value>, const nsAString& aName,
- Nullable<OwningNodeOrHTMLCollection>& aResult)
+ void LegacyCall(JS::Handle<JS::Value>, const Optional<nsAString>& aName,
+ Nullable<OwningHTMLCollectionOrElement>& aResult)
{
- NamedItem(aName, aResult);
+ Item(aName, aResult);
}
private:
nsContentList* Collection();
/**
* Returns the HTMLCollection for document.all[aID], or null if there isn't one.
*/
--- a/dom/webidl/HTMLAllCollection.webidl
+++ b/dom/webidl/HTMLAllCollection.webidl
@@ -1,14 +1,13 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* Emulates undefined through Codegen.py. */
[LegacyUnenumerableNamedProperties]
interface HTMLAllCollection {
readonly attribute unsigned long length;
- getter Node? (unsigned long index);
- Node? item(unsigned long index);
- (Node or HTMLCollection)? item(DOMString name);
- legacycaller (Node or HTMLCollection)? (DOMString name);
- getter (Node or HTMLCollection)? namedItem(DOMString name);
+ getter Element? (unsigned long index);
+ getter (HTMLCollection or Element)? namedItem(DOMString name);
+ legacycaller (HTMLCollection or Element)? (optional DOMString nameOrIndex);
+ (HTMLCollection or Element)? item(optional DOMString nameOrIndex);
};
--- a/testing/web-platform/meta/html/dom/interfaces.html.ini
+++ b/testing/web-platform/meta/html/dom/interfaces.html.ini
@@ -365,16 +365,20 @@
expected: FAIL
[HTMLAllCollection interface: document.all must inherit property "namedItem" with the proper type (2)]
expected: FAIL
[HTMLAllCollection interface: calling namedItem(DOMString) on document.all with too few arguments must throw TypeError]
expected: FAIL
+ [HTMLAllCollection interface: document.all must inherit property "item" with the proper type (3)]
+ expected: FAIL
+ bug: https://github.com/w3c/web-platform-tests/pull/6820
+
[HTMLCollection interface: document.all must inherit property "length" with the proper type (0)]
expected: FAIL
[HTMLCollection interface: document.all must inherit property "item" with the proper type (1)]
expected: FAIL
[HTMLCollection interface: calling item(unsigned long) on document.all with too few arguments must throw TypeError]
expected: FAIL
--- a/testing/web-platform/meta/html/infrastructure/common-dom-interfaces/collections/htmlallcollection.html.ini
+++ b/testing/web-platform/meta/html/infrastructure/common-dom-interfaces/collections/htmlallcollection.html.ini
@@ -4,23 +4,20 @@
expected: FAIL
[legacy caller with "array index property name" as number]
expected: FAIL
[legacy caller with invalid "array index property name"]
expected: FAIL
- [legacy caller with no argument]
+ [item method with "array index property name"]
expected: FAIL
- [item method with "array index property name"]
+ [item method with "array index property name" as number]
expected: FAIL
[item method with invalid "array index property name"]
expected: FAIL
- [item method with no argument]
- expected: FAIL
-
[collections are new live HTMLCollection instances]
expected: FAIL
--- a/testing/web-platform/tests/interfaces/html.idl
+++ b/testing/web-platform/tests/interfaces/html.idl
@@ -17,19 +17,19 @@ interface HTMLHyperlinkElementUtils {
attribute USVString port;
attribute USVString pathname;
attribute USVString search;
attribute USVString hash;
};
interface HTMLAllCollection {
readonly attribute unsigned long length;
- getter Element? item(unsigned long index);
- (HTMLCollection or Element)? item(DOMString name);
- legacycaller getter (HTMLCollection or Element)? namedItem(DOMString name);
+ getter Element? (unsigned long index);
+ getter (HTMLCollection or Element)? namedItem(DOMString name);
+ legacycaller getter (HTMLCollection or Element)? item(optional DOMString nameOrIndex);
};
interface HTMLFormControlsCollection : HTMLCollection {
// inherits length and item()
getter (RadioNodeList or Element)? namedItem(DOMString name); // shadows inherited namedItem()
};
interface RadioNodeList : NodeList {