зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1729329 - Convert nsCOMArrays in XSLT code to nsTArrays and remove impossible to hit OOM errors. r=farre
Differential Revision: https://phabricator.services.mozilla.com/D124680
This commit is contained in:
Родитель
89dbebeac4
Коммит
a92812387c
|
@ -7,7 +7,7 @@
|
|||
#define TRANSFRMX_TXNAMESPACEMAP_H
|
||||
|
||||
#include "nsAtom.h"
|
||||
#include "nsCOMArray.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
class txNamespaceMap {
|
||||
|
|
|
@ -29,7 +29,7 @@ XPathResult::XPathResult(nsINode* aParent)
|
|||
XPathResult::XPathResult(const XPathResult& aResult)
|
||||
: mParent(aResult.mParent),
|
||||
mResult(aResult.mResult),
|
||||
mResultNodes(aResult.mResultNodes),
|
||||
mResultNodes(aResult.mResultNodes.Clone()),
|
||||
mDocument(aResult.mDocument),
|
||||
mContextNode(aResult.mContextNode),
|
||||
mCurrentPos(0),
|
||||
|
@ -93,7 +93,7 @@ nsINode* XPathResult::IterateNext(ErrorResult& aRv) {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
return mResultNodes.SafeObjectAt(mCurrentPos++);
|
||||
return mResultNodes.SafeElementAt(mCurrentPos++);
|
||||
}
|
||||
|
||||
void XPathResult::NodeWillBeDestroyed(const nsINode* aNode) {
|
||||
|
@ -177,7 +177,7 @@ void XPathResult::SetExprResult(txAExprResult* aExprResult,
|
|||
int32_t i, count = nodeSet->size();
|
||||
for (i = 0; i < count; ++i) {
|
||||
nsINode* node = txXPathNativeNode::getNode(nodeSet->get(i));
|
||||
mResultNodes.AppendObject(node);
|
||||
mResultNodes.AppendElement(node);
|
||||
}
|
||||
|
||||
if (count > 0) {
|
||||
|
@ -192,7 +192,7 @@ void XPathResult::SetExprResult(txAExprResult* aExprResult,
|
|||
mCurrentPos = 0;
|
||||
mInvalidIteratorState = false;
|
||||
|
||||
if (mResultNodes.Count() > 0) {
|
||||
if (!mResultNodes.IsEmpty()) {
|
||||
// If we support the document() function in DOM-XPath we need to
|
||||
// observe all documents that we have resultnodes in.
|
||||
mDocument = mResultNodes[0]->OwnerDoc();
|
||||
|
@ -231,12 +231,12 @@ nsresult XPathResult::GetExprResult(txAExprResult** aExprResult) {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
if (mResultNodes.Count() == 0) {
|
||||
if (mResultNodes.IsEmpty()) {
|
||||
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
||||
}
|
||||
|
||||
RefPtr<txNodeSet> nodeSet = new txNodeSet(nullptr);
|
||||
uint32_t i, count = mResultNodes.Count();
|
||||
uint32_t i, count = mResultNodes.Length();
|
||||
for (i = 0; i < count; ++i) {
|
||||
UniquePtr<txXPathNode> node(
|
||||
txXPathNativeNode::createXPathNode(mResultNodes[i]));
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
|
||||
#include "nsStubMutationObserver.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsCOMArray.h"
|
||||
#include "nsIWeakReferenceUtils.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsIWeakReferenceUtils.h"
|
||||
#include "nsTArray.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "nsString.h"
|
||||
|
@ -110,7 +110,7 @@ class XPathResult final : public nsIXPathResult,
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
return mResultNodes.SafeObjectAt(0);
|
||||
return mResultNodes.SafeElementAt(0);
|
||||
}
|
||||
bool InvalidIteratorState() const {
|
||||
return isIterator() && mInvalidIteratorState;
|
||||
|
@ -121,7 +121,7 @@ class XPathResult final : public nsIXPathResult,
|
|||
return 0;
|
||||
}
|
||||
|
||||
return (uint32_t)mResultNodes.Count();
|
||||
return (uint32_t)mResultNodes.Length();
|
||||
}
|
||||
nsINode* IterateNext(ErrorResult& aRv);
|
||||
nsINode* SnapshotItem(uint32_t aIndex, ErrorResult& aRv) const {
|
||||
|
@ -130,7 +130,7 @@ class XPathResult final : public nsIXPathResult,
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
return mResultNodes.SafeObjectAt(aIndex);
|
||||
return mResultNodes.SafeElementAt(aIndex);
|
||||
}
|
||||
|
||||
// nsIMutationObserver interface
|
||||
|
@ -168,7 +168,7 @@ class XPathResult final : public nsIXPathResult,
|
|||
|
||||
nsCOMPtr<nsINode> mParent;
|
||||
RefPtr<txAExprResult> mResult;
|
||||
nsCOMArray<nsINode> mResultNodes;
|
||||
nsTArray<nsCOMPtr<nsINode>> mResultNodes;
|
||||
RefPtr<Document> mDocument;
|
||||
nsWeakPtr mContextNode;
|
||||
uint32_t mCurrentPos;
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
* 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 "nsCOMArray.h"
|
||||
#include "nsIAuthPrompt.h"
|
||||
#include "mozilla/dom/Document.h"
|
||||
#include "nsIExpatSink.h"
|
||||
|
|
|
@ -256,8 +256,7 @@ nsresult txMozillaXMLOutput::endElement() {
|
|||
// Handle html-elements
|
||||
if (!mNoFixup) {
|
||||
if (element->IsHTMLElement()) {
|
||||
rv = endHTMLElement(element);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
endHTMLElement(element);
|
||||
}
|
||||
|
||||
// Handle elements that are different when parser-created
|
||||
|
@ -273,8 +272,7 @@ nsresult txMozillaXMLOutput::endElement() {
|
|||
// If the act of insertion evaluated the script, we're fine.
|
||||
// Else, add this script element to the array of loading scripts.
|
||||
if (block) {
|
||||
rv = mNotifier->AddScriptElement(sele);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
mNotifier->AddScriptElement(sele);
|
||||
}
|
||||
} else {
|
||||
MOZ_ASSERT(nsNameSpaceManager::GetInstance()->mSVGDisabled,
|
||||
|
@ -302,11 +300,11 @@ nsresult txMozillaXMLOutput::endElement() {
|
|||
|
||||
// Add the element to the tree if it wasn't added before and take one step
|
||||
// up the tree
|
||||
uint32_t last = mCurrentNodeStack.Count() - 1;
|
||||
NS_ASSERTION(last != (uint32_t)-1, "empty stack");
|
||||
|
||||
nsCOMPtr<nsINode> parent = mCurrentNodeStack.SafeObjectAt(last);
|
||||
mCurrentNodeStack.RemoveObjectAt(last);
|
||||
MOZ_ASSERT(!mCurrentNodeStack.IsEmpty(), "empty stack");
|
||||
nsCOMPtr<nsINode> parent;
|
||||
if (!mCurrentNodeStack.IsEmpty()) {
|
||||
parent = mCurrentNodeStack.PopLastElement();
|
||||
}
|
||||
|
||||
if (mCurrentNode == mNonAddedNode) {
|
||||
if (parent == mDocument) {
|
||||
|
@ -473,9 +471,7 @@ nsresult txMozillaXMLOutput::startElementInternal(nsAtom* aPrefix,
|
|||
|
||||
mTableStateStack.push(NS_INT32_TO_PTR(mTableState));
|
||||
|
||||
if (!mCurrentNodeStack.AppendObject(mCurrentNode)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
mCurrentNodeStack.AppendElement(mCurrentNode);
|
||||
|
||||
mTableState = NORMAL;
|
||||
mOpenedElementIsHTML = false;
|
||||
|
@ -612,9 +608,7 @@ nsresult txMozillaXMLOutput::createTxWrapper() {
|
|||
}
|
||||
}
|
||||
|
||||
if (!mCurrentNodeStack.AppendObject(wrapper)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
mCurrentNodeStack.AppendElement(wrapper);
|
||||
mCurrentNode = wrapper;
|
||||
mRootContentCreated = true;
|
||||
NS_ASSERTION(rootLocation == mDocument->GetChildCount(),
|
||||
|
@ -630,11 +624,12 @@ nsresult txMozillaXMLOutput::startHTMLElement(nsIContent* aElement,
|
|||
|
||||
if ((!aElement->IsHTMLElement(nsGkAtoms::tr) || !aIsHTML) &&
|
||||
NS_PTR_TO_INT32(mTableStateStack.peek()) == ADDED_TBODY) {
|
||||
uint32_t last = mCurrentNodeStack.Count() - 1;
|
||||
NS_ASSERTION(last != (uint32_t)-1, "empty stack");
|
||||
|
||||
mCurrentNode = mCurrentNodeStack.SafeObjectAt(last);
|
||||
mCurrentNodeStack.RemoveObjectAt(last);
|
||||
MOZ_ASSERT(!mCurrentNodeStack.IsEmpty(), "empty stack");
|
||||
if (mCurrentNodeStack.IsEmpty()) {
|
||||
mCurrentNode = nullptr;
|
||||
} else {
|
||||
mCurrentNode = mCurrentNodeStack.PopLastElement();
|
||||
}
|
||||
mTableStateStack.pop();
|
||||
}
|
||||
|
||||
|
@ -654,10 +649,7 @@ nsresult txMozillaXMLOutput::startHTMLElement(nsIContent* aElement,
|
|||
|
||||
mTableStateStack.push(NS_INT32_TO_PTR(ADDED_TBODY));
|
||||
|
||||
if (!mCurrentNodeStack.AppendObject(tbody)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
mCurrentNodeStack.AppendElement(tbody);
|
||||
mCurrentNode = tbody;
|
||||
} else if (aElement->IsHTMLElement(nsGkAtoms::head) &&
|
||||
mOutputFormat.mMethod == eHTMLOutput) {
|
||||
|
@ -691,20 +683,23 @@ nsresult txMozillaXMLOutput::startHTMLElement(nsIContent* aElement,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult txMozillaXMLOutput::endHTMLElement(nsIContent* aElement) {
|
||||
void txMozillaXMLOutput::endHTMLElement(nsIContent* aElement) {
|
||||
if (mTableState == ADDED_TBODY) {
|
||||
NS_ASSERTION(aElement->IsHTMLElement(nsGkAtoms::tbody),
|
||||
"Element flagged as added tbody isn't a tbody");
|
||||
uint32_t last = mCurrentNodeStack.Count() - 1;
|
||||
NS_ASSERTION(last != (uint32_t)-1, "empty stack");
|
||||
|
||||
mCurrentNode = mCurrentNodeStack.SafeObjectAt(last);
|
||||
mCurrentNodeStack.RemoveObjectAt(last);
|
||||
MOZ_ASSERT(!mCurrentNodeStack.IsEmpty(), "empty stack");
|
||||
if (mCurrentNodeStack.IsEmpty()) {
|
||||
mCurrentNode = nullptr;
|
||||
} else {
|
||||
mCurrentNode = mCurrentNodeStack.PopLastElement();
|
||||
}
|
||||
mTableState =
|
||||
static_cast<TableState>(NS_PTR_TO_INT32(mTableStateStack.pop()));
|
||||
|
||||
return NS_OK;
|
||||
} else if (mCreatingNewDocument && aElement->IsHTMLElement(nsGkAtoms::meta)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mCreatingNewDocument && aElement->IsHTMLElement(nsGkAtoms::meta)) {
|
||||
// handle HTTP-EQUIV data
|
||||
nsAutoString httpEquiv;
|
||||
aElement->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::httpEquiv,
|
||||
|
@ -720,8 +715,6 @@ nsresult txMozillaXMLOutput::endHTMLElement(nsIContent* aElement) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void txMozillaXMLOutput::processHTTPEquiv(nsAtom* aHeader,
|
||||
|
@ -891,7 +884,7 @@ txTransformNotifier::ScriptAvailable(nsresult aResult,
|
|||
nsIScriptElement* aElement,
|
||||
bool aIsInlineClassicScript, nsIURI* aURI,
|
||||
int32_t aLineNo) {
|
||||
if (NS_FAILED(aResult) && mScriptElements.RemoveObject(aElement)) {
|
||||
if (NS_FAILED(aResult) && mScriptElements.RemoveElement(aElement)) {
|
||||
SignalTransformEnd();
|
||||
}
|
||||
|
||||
|
@ -902,7 +895,7 @@ NS_IMETHODIMP
|
|||
txTransformNotifier::ScriptEvaluated(nsresult aResult,
|
||||
nsIScriptElement* aElement,
|
||||
bool aIsInline) {
|
||||
if (mScriptElements.RemoveObject(aElement)) {
|
||||
if (mScriptElements.RemoveElement(aElement)) {
|
||||
SignalTransformEnd();
|
||||
}
|
||||
|
||||
|
@ -932,9 +925,8 @@ void txTransformNotifier::Init(nsITransformObserver* aObserver) {
|
|||
mObserver = aObserver;
|
||||
}
|
||||
|
||||
nsresult txTransformNotifier::AddScriptElement(nsIScriptElement* aElement) {
|
||||
return mScriptElements.AppendObject(aElement) ? NS_OK
|
||||
: NS_ERROR_OUT_OF_MEMORY;
|
||||
void txTransformNotifier::AddScriptElement(nsIScriptElement* aElement) {
|
||||
mScriptElements.AppendElement(aElement);
|
||||
}
|
||||
|
||||
void txTransformNotifier::AddPendingStylesheet() { ++mPendingStylesheetCount; }
|
||||
|
@ -956,7 +948,7 @@ nsresult txTransformNotifier::SetOutputDocument(Document* aDocument) {
|
|||
void txTransformNotifier::SignalTransformEnd(nsresult aResult) {
|
||||
if (mInTransform ||
|
||||
(NS_SUCCEEDED(aResult) &&
|
||||
(mScriptElements.Count() > 0 || mPendingStylesheetCount > 0))) {
|
||||
(!mScriptElements.IsEmpty() || mPendingStylesheetCount > 0))) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include "txXMLEventHandler.h"
|
||||
#include "nsIScriptLoaderObserver.h"
|
||||
#include "txOutputFormat.h"
|
||||
#include "nsCOMArray.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsICSSLoaderObserver.h"
|
||||
#include "txStack.h"
|
||||
|
@ -42,7 +42,7 @@ class txTransformNotifier final : public nsIScriptLoaderObserver,
|
|||
nsresult aStatus) override;
|
||||
|
||||
void Init(nsITransformObserver* aObserver);
|
||||
nsresult AddScriptElement(nsIScriptElement* aElement);
|
||||
void AddScriptElement(nsIScriptElement* aElement);
|
||||
void AddPendingStylesheet();
|
||||
void OnTransformEnd(nsresult aResult = NS_OK);
|
||||
void OnTransformStart();
|
||||
|
@ -54,7 +54,7 @@ class txTransformNotifier final : public nsIScriptLoaderObserver,
|
|||
|
||||
nsCOMPtr<mozilla::dom::Document> mDocument;
|
||||
nsCOMPtr<nsITransformObserver> mObserver;
|
||||
nsCOMArray<nsIScriptElement> mScriptElements;
|
||||
nsTArray<nsCOMPtr<nsIScriptElement>> mScriptElements;
|
||||
uint32_t mPendingStylesheetCount;
|
||||
bool mInTransform;
|
||||
};
|
||||
|
@ -78,7 +78,7 @@ class txMozillaXMLOutput : public txAOutputXMLEventHandler {
|
|||
private:
|
||||
nsresult createTxWrapper();
|
||||
nsresult startHTMLElement(nsIContent* aElement, bool aXHTML);
|
||||
nsresult endHTMLElement(nsIContent* aElement);
|
||||
void endHTMLElement(nsIContent* aElement);
|
||||
void processHTTPEquiv(nsAtom* aHeader, const nsString& aValue);
|
||||
nsresult createHTMLElement(nsAtom* aName, mozilla::dom::Element** aResult);
|
||||
|
||||
|
@ -96,7 +96,7 @@ class txMozillaXMLOutput : public txAOutputXMLEventHandler {
|
|||
nsCOMPtr<mozilla::dom::Element> mOpenedElement;
|
||||
RefPtr<nsNodeInfoManager> mNodeInfoManager;
|
||||
|
||||
nsCOMArray<nsINode> mCurrentNodeStack;
|
||||
nsTArray<nsCOMPtr<nsINode>> mCurrentNodeStack;
|
||||
|
||||
nsCOMPtr<nsIContent> mNonAddedNode;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче