Bug 1398354 part 2. Update document.all item() and legacycaller to new spec semantics. r=mccr8

This commit is contained in:
Boris Zbarsky 2018-10-17 23:00:49 -04:00
Родитель 24d8300b00
Коммит 348aa22e01
5 изменённых файлов: 55 добавлений и 54 удалений

Просмотреть файл

@ -49,10 +49,37 @@ HTMLAllCollection::Length()
return Collection()->Length(true); return Collection()->Length(true);
} }
nsIContent* Element*
HTMLAllCollection::Item(uint32_t aIndex) HTMLAllCollection::Item(uint32_t aIndex)
{ {
return Collection()->Item(aIndex); nsIContent* item = Collection()->Item(aIndex);
return item ? item->AsElement() : nullptr;
}
void
HTMLAllCollection::Item(const Optional<nsAString>& aNameOrIndex,
Nullable<OwningHTMLCollectionOrElement>& aResult)
{
if (!aNameOrIndex.WasPassed()) {
aResult.SetNull();
return;
}
const nsAString& nameOrIndex = aNameOrIndex.Value();
uint32_t indexVal;
if (js::StringIsArrayIndex(nameOrIndex.BeginReading(),
nameOrIndex.Length(),
&indexVal)) {
Element* element = Item(indexVal);
if (element) {
aResult.SetValue().SetAsElement() = element;
} else {
aResult.SetNull();
}
return;
}
NamedItem(nameOrIndex, aResult);
} }
nsContentList* nsContentList*
@ -121,7 +148,7 @@ HTMLAllCollection::GetDocumentAllList(const nsAString& aID)
void void
HTMLAllCollection::NamedGetter(const nsAString& aID, HTMLAllCollection::NamedGetter(const nsAString& aID,
bool& aFound, bool& aFound,
Nullable<OwningNodeOrHTMLCollection>& aResult) Nullable<OwningHTMLCollectionOrElement>& aResult)
{ {
if (aID.IsEmpty()) { if (aID.IsEmpty()) {
aFound = false; aFound = false;
@ -148,7 +175,7 @@ HTMLAllCollection::NamedGetter(const nsAString& aID,
// There's only 0 or 1 items. Return the first one or null. // There's only 0 or 1 items. Return the first one or null.
if (nsIContent* node = docAllList->Item(0, true)) { if (nsIContent* node = docAllList->Item(0, true)) {
aFound = true; aFound = true;
aResult.SetValue().SetAsNode() = node; aResult.SetValue().SetAsElement() = node->AsElement();
return; return;
} }

Просмотреть файл

@ -16,14 +16,15 @@
class nsContentList; class nsContentList;
class nsHTMLDocument; class nsHTMLDocument;
class nsIContent;
class nsINode; class nsINode;
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
class OwningNodeOrHTMLCollection; class Element;
class OwningHTMLCollectionOrElement;
template<typename> struct Nullable; template<typename> struct Nullable;
template<typename> class Optional;
class HTMLAllCollection final : public nsISupports class HTMLAllCollection final : public nsISupports
, public nsWrapperCache , public nsWrapperCache
@ -40,32 +41,32 @@ public:
nsINode* GetParentObject() const; nsINode* GetParentObject() const;
uint32_t Length(); uint32_t Length();
nsIContent* Item(uint32_t aIndex); Element* IndexedGetter(uint32_t aIndex, bool& aFound)
void Item(const nsAString& aName, Nullable<OwningNodeOrHTMLCollection>& aResult)
{ {
NamedItem(aName, aResult); Element* result = Item(aIndex);
}
nsIContent* IndexedGetter(uint32_t aIndex, bool& aFound)
{
nsIContent* result = Item(aIndex);
aFound = !!result; aFound = !!result;
return result; return result;
} }
void NamedItem(const nsAString& aName, void NamedItem(const nsAString& aName,
Nullable<OwningNodeOrHTMLCollection>& aResult) Nullable<OwningHTMLCollectionOrElement>& aResult)
{ {
bool found = false; bool found = false;
NamedGetter(aName, found, aResult); NamedGetter(aName, found, aResult);
} }
void NamedGetter(const nsAString& aName, void NamedGetter(const nsAString& aName,
bool& aFound, bool& aFound,
Nullable<OwningNodeOrHTMLCollection>& aResult); Nullable<OwningHTMLCollectionOrElement>& aResult);
void GetSupportedNames(nsTArray<nsString>& aNames); void GetSupportedNames(nsTArray<nsString>& aNames);
void LegacyCall(JS::Handle<JS::Value>, const nsAString& aName,
Nullable<OwningNodeOrHTMLCollection>& aResult) void Item(const Optional<nsAString>& aNameOrIndex,
Nullable<OwningHTMLCollectionOrElement>& aResult);
void LegacyCall(JS::Handle<JS::Value>,
const Optional<nsAString>& aNameOrIndex,
Nullable<OwningHTMLCollectionOrElement>& aResult)
{ {
NamedItem(aName, aResult); Item(aNameOrIndex, aResult);
} }
private: private:
@ -76,6 +77,11 @@ private:
*/ */
nsContentList* GetDocumentAllList(const nsAString& aID); nsContentList* GetDocumentAllList(const nsAString& aID);
/**
* Helper for indexed getter and spec Item() method.
*/
Element* Item(uint32_t aIndex);
RefPtr<nsHTMLDocument> mDocument; RefPtr<nsHTMLDocument> mDocument;
RefPtr<nsContentList> mCollection; RefPtr<nsContentList> mCollection;
nsRefPtrHashtable<nsStringHashKey, nsContentList> mNamedMap; nsRefPtrHashtable<nsStringHashKey, nsContentList> mNamedMap;

Просмотреть файл

@ -6,9 +6,8 @@
[LegacyUnenumerableNamedProperties] [LegacyUnenumerableNamedProperties]
interface HTMLAllCollection { interface HTMLAllCollection {
readonly attribute unsigned long length; readonly attribute unsigned long length;
getter Node? (unsigned long index); getter Element (unsigned long index);
Node? item(unsigned long index); getter (HTMLCollection or Element)? namedItem(DOMString name);
(Node or HTMLCollection)? item(DOMString name); (HTMLCollection or Element)? item(optional DOMString nameOrIndex);
legacycaller (Node or HTMLCollection)? (DOMString name); legacycaller (HTMLCollection or Element)? (optional DOMString nameOrIndex);
getter (Node or HTMLCollection)? namedItem(DOMString name);
}; };

Просмотреть файл

@ -358,9 +358,6 @@
[interfaces.https.html?include=HTML.*] [interfaces.https.html?include=HTML.*]
[HTMLAllCollection interface: operation item(DOMString)]
expected: FAIL
[HTMLAllCollection must be primary interface of document.all] [HTMLAllCollection must be primary interface of document.all]
expected: FAIL expected: FAIL

Просмотреть файл

@ -1,31 +1,3 @@
[htmlallcollection.html] [htmlallcollection.html]
[legacy caller with "array index property name"]
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]
expected: FAIL
[item method with "array index property name"]
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] [collections are new live HTMLCollection instances]
expected: FAIL expected: FAIL
[legacy caller with undefined]
expected: FAIL
[item method with undefined]
expected: FAIL