Bug 968766 - Part k: Move the hashmap for named access to document.all into HTMLAllCollection; r=jst

This commit is contained in:
Ms2ger 2014-02-09 09:04:37 +01:00
parent ce843f3b65
commit a570615379
4 changed files with 65 additions and 63 deletions

View File

@ -69,12 +69,14 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(HTMLAllCollection)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocument)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCollection)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mNamedMap)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(HTMLAllCollection)
tmp->mObject = nullptr;
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocument)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCollection)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mNamedMap)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(HTMLAllCollection)
@ -130,11 +132,65 @@ HTMLAllCollection::Collection()
return mCollection;
}
static bool
DocAllResultMatch(nsIContent* aContent, int32_t aNamespaceID, nsIAtom* aAtom,
void* aData)
{
if (aContent->GetID() == aAtom) {
return true;
}
nsGenericHTMLElement* elm = nsGenericHTMLElement::FromContent(aContent);
if (!elm) {
return false;
}
nsIAtom* tag = elm->Tag();
if (tag != nsGkAtoms::a &&
tag != nsGkAtoms::applet &&
tag != nsGkAtoms::button &&
tag != nsGkAtoms::embed &&
tag != nsGkAtoms::form &&
tag != nsGkAtoms::iframe &&
tag != nsGkAtoms::img &&
tag != nsGkAtoms::input &&
tag != nsGkAtoms::map &&
tag != nsGkAtoms::meta &&
tag != nsGkAtoms::object &&
tag != nsGkAtoms::select &&
tag != nsGkAtoms::textarea) {
return false;
}
const nsAttrValue* val = elm->GetParsedAttr(nsGkAtoms::name);
return val && val->Type() == nsAttrValue::eAtom &&
val->GetAtomValue() == aAtom;
}
nsContentList*
HTMLAllCollection::GetDocumentAllList(const nsAString& aID)
{
if (nsContentList* docAllList = mNamedMap.GetWeak(aID)) {
return docAllList;
}
Element* root = mDocument->GetRootElement();
if (!root) {
return nullptr;
}
nsCOMPtr<nsIAtom> id = do_GetAtom(aID);
nsRefPtr<nsContentList> docAllList =
new nsContentList(root, DocAllResultMatch, nullptr, nullptr, true, id);
mNamedMap.Put(aID, docAllList);
return docAllList;
}
nsISupports*
HTMLAllCollection::GetNamedItem(const nsAString& aID,
nsWrapperCache** aCache)
{
nsContentList* docAllList = mDocument->GetDocumentAllList(aID);
nsContentList* docAllList = GetDocumentAllList(aID);
if (!docAllList) {
return nullptr;
}

View File

@ -11,6 +11,7 @@
#include "nsAutoPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsISupportsImpl.h"
#include "nsRefPtrHashtable.h"
#include <stdint.h>
@ -43,9 +44,15 @@ public:
private:
nsContentList* Collection();
/**
* Returns the NodeList for document.all[aID], or null if there isn't one.
*/
nsContentList* GetDocumentAllList(const nsAString& aID);
JS::Heap<JSObject*> mObject;
nsRefPtr<nsHTMLDocument> mDocument;
nsRefPtr<nsContentList> mCollection;
nsRefPtrHashtable<nsStringHashKey, nsContentList> mNamedMap;
};
} // namespace dom

View File

@ -199,9 +199,8 @@ nsHTMLDocument::~nsHTMLDocument()
{
}
NS_IMPL_CYCLE_COLLECTION_INHERITED_12(nsHTMLDocument, nsDocument,
NS_IMPL_CYCLE_COLLECTION_INHERITED_11(nsHTMLDocument, nsDocument,
mAll,
mAllMap,
mImages,
mApplets,
mEmbeds,
@ -2556,61 +2555,6 @@ nsHTMLDocument::DeferredContentEditableCountChange(nsIContent *aElement)
}
}
static bool
DocAllResultMatch(nsIContent* aContent, int32_t aNamespaceID, nsIAtom* aAtom,
void* aData)
{
if (aContent->GetID() == aAtom) {
return true;
}
nsGenericHTMLElement* elm = nsGenericHTMLElement::FromContent(aContent);
if (!elm) {
return false;
}
nsIAtom* tag = elm->Tag();
if (tag != nsGkAtoms::a &&
tag != nsGkAtoms::applet &&
tag != nsGkAtoms::button &&
tag != nsGkAtoms::embed &&
tag != nsGkAtoms::form &&
tag != nsGkAtoms::iframe &&
tag != nsGkAtoms::img &&
tag != nsGkAtoms::input &&
tag != nsGkAtoms::map &&
tag != nsGkAtoms::meta &&
tag != nsGkAtoms::object &&
tag != nsGkAtoms::select &&
tag != nsGkAtoms::textarea) {
return false;
}
const nsAttrValue* val = elm->GetParsedAttr(nsGkAtoms::name);
return val && val->Type() == nsAttrValue::eAtom &&
val->GetAtomValue() == aAtom;
}
nsContentList*
nsHTMLDocument::GetDocumentAllList(const nsAString& aID)
{
if (nsContentList* docAllList = mAllMap.GetWeak(aID)) {
return docAllList;
}
Element* root = GetRootElement();
if (!root) {
return nullptr;
}
nsCOMPtr<nsIAtom> id = do_GetAtom(aID);
nsRefPtr<nsContentList> docAllList =
new nsContentList(root, DocAllResultMatch, nullptr, nullptr, true, id);
mAllMap.Put(aID, docAllList);
return docAllList;
}
HTMLAllCollection*
nsHTMLDocument::All()
{

View File

@ -102,10 +102,6 @@ public:
// nsIDOMHTMLDocument interface
NS_DECL_NSIDOMHTMLDOCUMENT
/**
* Returns the NodeList for document.all[aID], or null if there isn't one.
*/
nsContentList* GetDocumentAllList(const nsAString& aID);
mozilla::dom::HTMLAllCollection* All();
JSObject* GetAll(JSContext* aCx, mozilla::ErrorResult& aRv);
@ -292,7 +288,6 @@ protected:
nsRefPtr<nsContentList> mFormControls;
nsRefPtr<mozilla::dom::HTMLAllCollection> mAll;
nsRefPtrHashtable<nsStringHashKey, nsContentList> mAllMap;
/** # of forms in the document, synchronously set */
int32_t mNumForms;