Bug 1288590: Rename nsAttrInfo to mozilla::dom::BorrowedAttrInfo. r=bholley

Unfortunately couldn't add all the debug checks that I'd want, since we can't
assert that is not safe to run script in quite a few places :(

MozReview-Commit-ID: 8m3Wm1WntZs
This commit is contained in:
Emilio Cobos Álvarez 2016-07-22 14:11:41 -07:00
Родитель 0bbe4a681c
Коммит 11ac7c1d96
22 изменённых файлов: 86 добавлений и 54 удалений

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

@ -19,6 +19,7 @@
#include "nsWinUtils.h"
#include "nsRange.h"
#include "mozilla/dom/BorrowedAttrInfo.h"
#include "mozilla/dom/Element.h"
using namespace mozilla;
@ -149,7 +150,7 @@ sdnAccessible::get_attributes(unsigned short aMaxAttribs,
aAttribValues[index] = aAttribNames[index] = nullptr;
nsAutoString attributeValue;
nsAttrInfo attr = elm->GetAttrInfoAt(index);
dom::BorrowedAttrInfo attr = elm->GetAttrInfoAt(index);
attr.mValue->ToString(attributeValue);
aNameSpaceIDs[index] = static_cast<short>(attr.mName->NamespaceID());

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

@ -0,0 +1,28 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#include "mozilla/dom/BorrowedAttrInfo.h"
namespace mozilla {
namespace dom {
BorrowedAttrInfo::BorrowedAttrInfo(const nsAttrName* aName,
const nsAttrValue* aValue)
: mName(aName)
, mValue(aValue)
{
MOZ_ASSERT_IF(mName, mValue);
}
BorrowedAttrInfo::BorrowedAttrInfo(const BorrowedAttrInfo& aOther)
: mName(aOther.mName)
, mValue(aOther.mValue)
{
MOZ_ASSERT_IF(mName, mValue);
}
} // namespace dom
} // namespace mozilla

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

@ -4,38 +4,36 @@
* 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/. */
#ifndef nsAttrInfo_h__
#define nsAttrInfo_h__
#ifndef BorrowedAttrInfo_h__
#define BorrowedAttrInfo_h__
#include "mozilla/Assertions.h"
class nsAttrName;
class nsAttrValue;
namespace mozilla {
namespace dom {
/**
* Struct that stores info on an attribute. The name and value must
* either both be null or both be non-null.
* Struct that stores info on an attribute. The name and value must either both
* be null or both be non-null.
*
* Note that, just as the pointers returned by GetAttrNameAt, the pointers that
* this struct hold are only valid until the element or its attributes are
* mutated (directly or via script).
*/
struct nsAttrInfo
struct BorrowedAttrInfo
{
nsAttrInfo()
BorrowedAttrInfo()
: mName(nullptr)
, mValue(nullptr)
{
}
nsAttrInfo(const nsAttrName* aName, const nsAttrValue* aValue)
: mName(aName)
, mValue(aValue)
{
MOZ_ASSERT_IF(aName, aValue);
}
BorrowedAttrInfo(const nsAttrName* aName, const nsAttrValue* aValue);
nsAttrInfo(const nsAttrInfo& aOther)
: mName(aOther.mName)
, mValue(aOther.mValue)
{
}
BorrowedAttrInfo(const BorrowedAttrInfo& aOther);
const nsAttrName* mName;
const nsAttrValue* mValue;
@ -43,4 +41,6 @@ struct nsAttrInfo
explicit operator bool() const { return mName != nullptr; }
};
} // namespace dom
} // namespace mozilla
#endif

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

@ -8,9 +8,9 @@
#define mozilla_dom_DocumentFragment_h__
#include "mozilla/Attributes.h"
#include "mozilla/dom/BorrowedAttrInfo.h"
#include "mozilla/dom/FragmentOrElement.h"
#include "nsIDOMDocumentFragment.h"
#include "nsAttrInfo.h"
class nsIAtom;
class nsAString;
@ -89,9 +89,9 @@ public:
{
return nullptr;
}
virtual nsAttrInfo GetAttrInfoAt(uint32_t aIndex) const override
virtual BorrowedAttrInfo GetAttrInfoAt(uint32_t aIndex) const override
{
return nsAttrInfo(nullptr, nullptr);
return BorrowedAttrInfo(nullptr, nullptr);
}
virtual uint32_t GetAttrCount() const override
{

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

@ -2205,7 +2205,7 @@ Element::MaybeCheckSameAttrVal(int32_t aNamespaceID,
// listeners and don't plan to notify. The check for aNotify here is an
// optimization, the check for *aHasListeners is a correctness issue.
if (*aHasListeners || aNotify) {
nsAttrInfo info(GetAttrInfo(aNamespaceID, aName));
BorrowedAttrInfo info(GetAttrInfo(aNamespaceID, aName));
if (info.mValue) {
// Check whether the old value is the same as the new one. Note that we
// only need to actually _get_ the old value if we have listeners or
@ -2536,7 +2536,7 @@ Element::GetEventListenerManagerForAttr(nsIAtom* aAttrName,
return GetOrCreateListenerManager();
}
nsAttrInfo
BorrowedAttrInfo
Element::GetAttrInfo(int32_t aNamespaceID, nsIAtom* aName) const
{
NS_ASSERTION(nullptr != aName, "must have attribute name");
@ -2545,17 +2545,17 @@ Element::GetAttrInfo(int32_t aNamespaceID, nsIAtom* aName) const
int32_t index = mAttrsAndChildren.IndexOfAttr(aName, aNamespaceID);
if (index < 0) {
return nsAttrInfo(nullptr, nullptr);
return BorrowedAttrInfo(nullptr, nullptr);
}
return mAttrsAndChildren.AttrInfoAt(index);
}
nsAttrInfo
BorrowedAttrInfo
Element::GetAttrInfoAt(uint32_t aIndex) const
{
if (aIndex >= mAttrsAndChildren.AttrCount()) {
return nsAttrInfo(nullptr, nullptr);
return BorrowedAttrInfo(nullptr, nullptr);
}
return mAttrsAndChildren.AttrInfoAt(aIndex);

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

@ -509,7 +509,7 @@ public:
virtual nsresult UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
bool aNotify) override;
virtual const nsAttrName* GetAttrNameAt(uint32_t aIndex) const override;
virtual nsAttrInfo GetAttrInfoAt(uint32_t aIndex) const override;
virtual BorrowedAttrInfo GetAttrInfoAt(uint32_t aIndex) const override;
virtual uint32_t GetAttrCount() const override;
virtual bool IsNodeOfType(uint32_t aFlags) const override;
@ -973,7 +973,7 @@ public:
* is, this should only be called from methods that only care about attrs
* that effectively live in mAttrsAndChildren.
*/
virtual nsAttrInfo GetAttrInfo(int32_t aNamespaceID, nsIAtom* aName) const;
virtual BorrowedAttrInfo GetAttrInfo(int32_t aNamespaceID, nsIAtom* aName) const;
virtual void NodeInfoChanged()
{

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

@ -48,7 +48,6 @@ EXPORTS += [
'mozFlushType.h',
'nsAtomListUtils.h',
'nsAttrAndChildArray.h',
'nsAttrInfo.h',
'nsAttrName.h',
'nsAttrValue.h',
'nsAttrValueInlines.h',
@ -153,6 +152,7 @@ EXPORTS.mozilla.dom += [
'BarProps.h',
'BlobSet.h',
'BodyUtil.h',
'BorrowedAttrInfo.h',
'ChildIterator.h',
'ChromeNodeList.h',
'ChromeUtils.h',
@ -213,6 +213,7 @@ UNIFIED_SOURCES += [
'BarProps.cpp',
'BlobSet.cpp',
'BodyUtil.cpp',
'BorrowedAttrInfo.cpp',
'ChildIterator.cpp',
'ChromeNodeList.cpp',
'ChromeUtils.cpp',

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

@ -484,7 +484,7 @@ nsAttrAndChildArray::RemoveAttrAt(uint32_t aPos, nsAttrValue& aValue)
return MakeMappedUnique(mapped);
}
nsAttrInfo
BorrowedAttrInfo
nsAttrAndChildArray::AttrInfoAt(uint32_t aPos) const
{
NS_ASSERTION(aPos < AttrCount(),
@ -492,10 +492,10 @@ nsAttrAndChildArray::AttrInfoAt(uint32_t aPos) const
uint32_t nonmapped = NonMappedAttrCount();
if (aPos < nonmapped) {
return nsAttrInfo(&ATTRS(mImpl)[aPos].mName, &ATTRS(mImpl)[aPos].mValue);
return BorrowedAttrInfo(&ATTRS(mImpl)[aPos].mName, &ATTRS(mImpl)[aPos].mValue);
}
return nsAttrInfo(mImpl->mMappedAttrs->NameAt(aPos - nonmapped),
return BorrowedAttrInfo(mImpl->mMappedAttrs->NameAt(aPos - nonmapped),
mImpl->mMappedAttrs->AttrAt(aPos - nonmapped));
}

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

@ -14,9 +14,9 @@
#include "mozilla/Attributes.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/dom/BorrowedAttrInfo.h"
#include "nscore.h"
#include "nsAttrInfo.h"
#include "nsAttrName.h"
#include "nsAttrValue.h"
#include "nsCaseTreatment.h"
@ -47,6 +47,7 @@ class nsMappedAttributeElement;
class nsAttrAndChildArray
{
typedef mozilla::dom::BorrowedAttrInfo BorrowedAttrInfo;
public:
nsAttrAndChildArray();
~nsAttrAndChildArray();
@ -101,7 +102,7 @@ public:
const nsAttrName* AttrNameAt(uint32_t aPos) const;
// Returns the attribute info at a given position, *not* out-of-bounds safe
nsAttrInfo AttrInfoAt(uint32_t aPos) const;
BorrowedAttrInfo AttrInfoAt(uint32_t aPos) const;
// Returns attribute name at given position or null if aPos is out-of-bounds
const nsAttrName* GetSafeAttrNameAt(uint32_t aPos) const;

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

@ -4445,7 +4445,7 @@ nsContentUtils::CreateContextualFragment(nsINode* aContextNode,
uint32_t index;
for (index = 0; index < count; index++) {
const nsAttrInfo info = content->GetAttrInfoAt(index);
const BorrowedAttrInfo info = content->GetAttrInfoAt(index);
const nsAttrName* name = info.mName;
if (name->NamespaceEquals(kNameSpaceID_XMLNS)) {
info.mValue->ToString(uriStr);

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

@ -646,7 +646,7 @@ public:
/**
* Method that gets the primary presContext for the node.
*
*
* @param aContent The content node.
* @return the presContext, or nullptr if the content is not in a document
* (if GetCurrentDoc returns nullptr)

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

@ -647,10 +647,10 @@ nsGenericDOMDataNode::GetAttrNameAt(uint32_t aIndex) const
return nullptr;
}
nsAttrInfo
BorrowedAttrInfo
nsGenericDOMDataNode::GetAttrInfoAt(uint32_t aIndex) const
{
return nsAttrInfo(nullptr, nullptr);
return BorrowedAttrInfo(nullptr, nullptr);
}
uint32_t

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

@ -123,7 +123,7 @@ public:
virtual nsresult UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
bool aNotify) override;
virtual const nsAttrName* GetAttrNameAt(uint32_t aIndex) const override;
virtual nsAttrInfo GetAttrInfoAt(uint32_t aIndex) const override;
virtual mozilla::dom::BorrowedAttrInfo GetAttrInfoAt(uint32_t aIndex) const override;
virtual uint32_t GetAttrCount() const override;
virtual const nsTextFragment *GetText() override;
virtual uint32_t TextLength() const override;

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

@ -7,7 +7,7 @@
#define nsIContent_h___
#include "mozilla/Attributes.h"
#include "nsAttrInfo.h"
#include "mozilla/dom/BorrowedAttrInfo.h"
#include "nsCaseTreatment.h" // for enum, cannot be forward-declared
#include "nsINode.h"
@ -468,7 +468,7 @@ public:
/**
* Gets the attribute info (name and value) for this content at a given index.
*/
virtual nsAttrInfo GetAttrInfoAt(uint32_t aIndex) const = 0;
virtual mozilla::dom::BorrowedAttrInfo GetAttrInfoAt(uint32_t aIndex) const = 0;
/**
* Get the number of all specified attributes.

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

@ -306,7 +306,7 @@ nsXHTMLContentSerializer::SerializeAttributes(nsIContent* aContent,
continue;
}
nsAttrInfo info = aContent->GetAttrInfoAt(index);
BorrowedAttrInfo info = aContent->GetAttrInfoAt(index);
const nsAttrName* name = info.mName;
int32_t namespaceID = name->NamespaceID();

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

@ -730,7 +730,7 @@ nsXMLContentSerializer::ScanNamespaceDeclarations(nsIContent* aContent,
uint32_t skipAttr = count;
for (index = 0; index < count; index++) {
const nsAttrInfo info = aContent->GetAttrInfoAt(index);
const BorrowedAttrInfo info = aContent->GetAttrInfoAt(index);
const nsAttrName* name = info.mName;
int32_t namespaceID = name->NamespaceID();

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

@ -416,7 +416,7 @@ HTMLMenuItemElement::WalkRadioGroup(Visitor* aVisitor)
return;
}
nsAttrInfo info1(GetAttrInfo(kNameSpaceID_None,
BorrowedAttrInfo info1(GetAttrInfo(kNameSpaceID_None,
nsGkAtoms::radiogroup));
bool info1Empty = !info1.mValue || info1.mValue->IsEmptyString();
@ -429,7 +429,7 @@ HTMLMenuItemElement::WalkRadioGroup(Visitor* aVisitor)
continue;
}
nsAttrInfo info2(menuitem->GetAttrInfo(kNameSpaceID_None,
BorrowedAttrInfo info2(menuitem->GetAttrInfo(kNameSpaceID_None,
nsGkAtoms::radiogroup));
bool info2Empty = !info2.mValue || info2.mValue->IsEmptyString();

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

@ -301,7 +301,7 @@ SVGUseElement::CreateAnonymousContent()
return nullptr;
// copy attributes
nsAttrInfo info;
BorrowedAttrInfo info;
uint32_t i;
for (i = 0; (info = newcontent->GetAttrInfoAt(i)); i++) {
nsAutoString value;

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

@ -406,7 +406,7 @@ nsXBLBinding::GenerateAnonymousContent()
// Always check the content element for potential attributes.
// This shorthand hack always happens, even when we didn't
// build anonymous content.
nsAttrInfo attrInfo;
BorrowedAttrInfo attrInfo;
for (uint32_t i = 0; (attrInfo = content->GetAttrInfoAt(i)); ++i) {
int32_t namespaceID = attrInfo.mName->NamespaceID();
// Hold a strong reference here so that the atom doesn't go away during

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

@ -1125,7 +1125,7 @@ nsXBLPrototypeBinding::Write(nsIObjectOutputStream* aStream)
uint32_t attributes = mBinding->GetAttrCount();
nsAutoString attrValue;
for (uint32_t i = 0; i < attributes; ++i) {
nsAttrInfo attrInfo = mBinding->GetAttrInfoAt(i);
BorrowedAttrInfo attrInfo = mBinding->GetAttrInfoAt(i);
const nsAttrName* name = attrInfo.mName;
nsDependentAtomString attrName(attrInfo.mName->LocalName());
attrInfo.mValue->ToString(attrValue);
@ -1415,7 +1415,7 @@ nsXBLPrototypeBinding::WriteContentNode(nsIObjectOutputStream* aStream,
// Write out the namespace id, the namespace prefix, the local tag name,
// and the value, in that order.
const nsAttrInfo attrInfo = aNode->GetAttrInfoAt(i);
const BorrowedAttrInfo attrInfo = aNode->GetAttrInfoAt(i);
const nsAttrName* name = attrInfo.mName;
// XXXndeakin don't write out xbl:inherits?

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

@ -213,7 +213,7 @@ DoMatch(Implementor* aElement, nsIAtom* aNS, nsIAtom* aName, MatchFn aMatch)
return value && aMatch(value);
}
// No namespace means any namespace - we have to check them all. :-(
nsAttrInfo attrInfo;
BorrowedAttrInfo attrInfo;
for (uint32_t i = 0; (attrInfo = aElement->GetAttrInfoAt(i)); ++i) {
if (attrInfo.mName->LocalName() != aName) {
continue;

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

@ -9,9 +9,9 @@
#include "mozilla/EventStates.h"
#include "mozilla/TypedEnumBits.h"
#include "mozilla/dom/BorrowedAttrInfo.h"
#include "nsAttrName.h"
#include "nsAttrValue.h"
#include "nsAttrInfo.h"
#include "nsChangeHint.h"
#include "nsIAtom.h"
@ -61,6 +61,7 @@ MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(ServoElementSnapshotFlags)
*/
class ServoElementSnapshot
{
typedef dom::BorrowedAttrInfo BorrowedAttrInfo;
typedef dom::Element Element;
typedef EventStates::ServoType ServoStateType;
@ -116,12 +117,12 @@ public:
/**
* Needed methods for attribute matching.
*/
nsAttrInfo GetAttrInfoAt(uint32_t aIndex) const
BorrowedAttrInfo GetAttrInfoAt(uint32_t aIndex) const
{
if (aIndex >= mAttrs.Length()) {
return nsAttrInfo(nullptr, nullptr);
return BorrowedAttrInfo(nullptr, nullptr);
}
return nsAttrInfo(&mAttrs[aIndex].mName, &mAttrs[aIndex].mValue);
return BorrowedAttrInfo(&mAttrs[aIndex].mName, &mAttrs[aIndex].mValue);
}
const nsAttrValue* GetParsedAttr(nsIAtom* aLocalName) const