Backed out 23 changesets (bug 1729329) for causing mochitest failures. CLOSED TREE

Backed out changeset a93125ed5957 (bug 1729329)
Backed out changeset dc99904cbba2 (bug 1729329)
Backed out changeset 71b980477982 (bug 1729329)
Backed out changeset 95961bdd8342 (bug 1729329)
Backed out changeset 75a787792d04 (bug 1729329)
Backed out changeset b2569472c3ff (bug 1729329)
Backed out changeset 41bb3539816d (bug 1729329)
Backed out changeset 28ec9a8c87d8 (bug 1729329)
Backed out changeset e54965a98dc1 (bug 1729329)
Backed out changeset 73767c02ff30 (bug 1729329)
Backed out changeset db670850cf51 (bug 1729329)
Backed out changeset cebb8e6014d9 (bug 1729329)
Backed out changeset 9008da35b3bb (bug 1729329)
Backed out changeset 9c171b04d134 (bug 1729329)
Backed out changeset ea3b6cfc339c (bug 1729329)
Backed out changeset 1f89052caba5 (bug 1729329)
Backed out changeset 105de5963c64 (bug 1729329)
Backed out changeset 122ca4b1e1d5 (bug 1729329)
Backed out changeset b1ed3b891384 (bug 1729329)
Backed out changeset 7c2ea3b9ab2b (bug 1729329)
Backed out changeset 6fba0c67d51e (bug 1729329)
Backed out changeset e8cb19427b66 (bug 1729329)
Backed out changeset e88066fc3cff (bug 1729329)
This commit is contained in:
Cristian Tuns 2021-09-29 04:02:02 -04:00
Родитель f33530917e
Коммит b022ae1fc0
36 изменённых файлов: 878 добавлений и 464 удалений

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

@ -30,6 +30,8 @@ nsresult txExpandedNameMap_base::addItem(const txExpandedName& aKey,
}
MapItem* item = mItems.AppendElement();
NS_ENSURE_TRUE(item, NS_ERROR_OUT_OF_MEMORY);
item->mNamespaceID = aKey.mNamespaceID;
item->mLocalName = aKey.mLocalName;
item->mValue = aValue;
@ -55,6 +57,8 @@ nsresult txExpandedNameMap_base::setItem(const txExpandedName& aKey,
}
MapItem* item = mItems.AppendElement();
NS_ENSURE_TRUE(item, NS_ERROR_OUT_OF_MEMORY);
item->mNamespaceID = aKey.mNamespaceID;
item->mLocalName = aKey.mLocalName;
item->mValue = aValue;

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

@ -25,7 +25,7 @@ txList::txList() {
*/
txList::~txList() { clear(); } //-- ~txList
void txList::add(void* objPtr) { insertBefore(objPtr, nullptr); } //-- add
void txList::add(void* objPtr) { insertBefore(objPtr, 0); } //-- add
/**
* Returns the number of items in this txList
@ -40,7 +40,12 @@ int32_t List::getLength() { return itemCount; } //-- getLength
* is a private method, I feel that's a valid assumption
**/
void txList::insertAfter(void* objPtr, ListItem* refItem) {
insertBefore(objPtr, refItem ? refItem->nextItem : firstItem);
//-- if refItem == null insert at front
if (!refItem) {
insertBefore(objPtr, firstItem);
} else {
insertBefore(objPtr, refItem->nextItem);
}
} //-- insertAfter
/**
@ -138,7 +143,7 @@ void txListIterator::addAfter(void* objPtr) {
if (currentItem || !atEndOfList) {
list->insertAfter(objPtr, currentItem);
} else {
list->insertBefore(objPtr, nullptr);
list->insertBefore(objPtr, 0);
}
} //-- addAfter
@ -152,7 +157,7 @@ void txListIterator::addBefore(void* objPtr) {
if (currentItem || atEndOfList) {
list->insertBefore(objPtr, currentItem);
} else {
list->insertAfter(objPtr, nullptr);
list->insertAfter(objPtr, 0);
}
} //-- addBefore

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

@ -46,7 +46,12 @@ nsresult txNamespaceMap::mapNamespace(nsAtom* aPrefix,
}
// New mapping
// XXX(Bug 1631371) Check if this should use a fallible operation as it
// pretended earlier.
mPrefixes.AppendElement(prefix);
// XXX(Bug 1631371) Check if this should use a fallible operation as it
// pretended earlier.
mNamespaces.AppendElement(nsId);
return NS_OK;

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

@ -7,7 +7,7 @@
#define TRANSFRMX_TXNAMESPACEMAP_H
#include "nsAtom.h"
#include "nsCOMPtr.h"
#include "nsCOMArray.h"
#include "nsTArray.h"
class txNamespaceMap {

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

@ -27,7 +27,12 @@ class txStack : private nsTArray<void*> {
* @param obj a pointer to the object that is to be added to the
* top of this stack.
*/
inline void push(void* aObject) { AppendElement(aObject); }
inline nsresult push(void* aObject) {
// XXX(Bug 1631371) Check if this should use a fallible operation as it
// pretended earlier, or change the return type to void.
AppendElement(aObject);
return NS_OK;
}
/**
* Removes and returns the specified object from the top of this

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

@ -29,7 +29,7 @@ XPathResult::XPathResult(nsINode* aParent)
XPathResult::XPathResult(const XPathResult& aResult)
: mParent(aResult.mParent),
mResult(aResult.mResult),
mResultNodes(aResult.mResultNodes.Clone()),
mResultNodes(aResult.mResultNodes),
mDocument(aResult.mDocument),
mContextNode(aResult.mContextNode),
mCurrentPos(0),
@ -93,7 +93,7 @@ nsINode* XPathResult::IterateNext(ErrorResult& aRv) {
return nullptr;
}
return mResultNodes.SafeElementAt(mCurrentPos++);
return mResultNodes.SafeObjectAt(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.AppendElement(node);
mResultNodes.AppendObject(node);
}
if (count > 0) {
@ -192,7 +192,7 @@ void XPathResult::SetExprResult(txAExprResult* aExprResult,
mCurrentPos = 0;
mInvalidIteratorState = false;
if (!mResultNodes.IsEmpty()) {
if (mResultNodes.Count() > 0) {
// 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,16 @@ nsresult XPathResult::GetExprResult(txAExprResult** aExprResult) {
return NS_OK;
}
if (mResultNodes.IsEmpty()) {
if (mResultNodes.Count() == 0) {
return NS_ERROR_DOM_INVALID_STATE_ERR;
}
RefPtr<txNodeSet> nodeSet = new txNodeSet(nullptr);
uint32_t i, count = mResultNodes.Length();
if (!nodeSet) {
return NS_ERROR_OUT_OF_MEMORY;
}
uint32_t i, count = mResultNodes.Count();
for (i = 0; i < count; ++i) {
UniquePtr<txXPathNode> node(
txXPathNativeNode::createXPathNode(mResultNodes[i]));

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

@ -8,9 +8,9 @@
#include "nsStubMutationObserver.h"
#include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsCOMArray.h"
#include "nsIWeakReferenceUtils.h"
#include "nsTArray.h"
#include "nsCycleCollectionParticipant.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.SafeElementAt(0);
return mResultNodes.SafeObjectAt(0);
}
bool InvalidIteratorState() const {
return isIterator() && mInvalidIteratorState;
@ -121,7 +121,7 @@ class XPathResult final : public nsIXPathResult,
return 0;
}
return (uint32_t)mResultNodes.Length();
return (uint32_t)mResultNodes.Count();
}
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.SafeElementAt(aIndex);
return mResultNodes.SafeObjectAt(aIndex);
}
// nsIMutationObserver interface
@ -168,7 +168,7 @@ class XPathResult final : public nsIXPathResult,
nsCOMPtr<nsINode> mParent;
RefPtr<txAExprResult> mResult;
nsTArray<nsCOMPtr<nsINode>> mResultNodes;
nsCOMArray<nsINode> mResultNodes;
RefPtr<Document> mDocument;
nsWeakPtr mContextNode;
uint32_t mCurrentPos;

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

@ -222,8 +222,14 @@ class FunctionCall : public Expr {
* The ownership of the given Expr is passed over to the FunctionCall,
* even on failure.
* @param aExpr the Expr to add to this FunctionCall's parameter list
* @return nsresult indicating out of memory
*/
void addParam(Expr* aExpr) { mParams.AppendElement(aExpr); }
nsresult addParam(Expr* aExpr) {
// XXX(Bug 1631371) Check if this should use a fallible operation as it
// pretended earlier, or change the return type to void.
mParams.AppendElement(aExpr);
return NS_OK;
}
/**
* Check if the number of parameters falls within a range.
@ -441,10 +447,14 @@ class PredicateList {
* The ownership of the given Expr is passed over the PredicateList,
* even on failure.
* @param aExpr the Expr to add to the list
* @return nsresult indicating out of memory
*/
void add(Expr* aExpr) {
nsresult add(Expr* aExpr) {
NS_ASSERTION(aExpr, "missing expression");
// XXX(Bug 1631371) Check if this should use a fallible operation as it
// pretended earlier, or change the return type to void.
mPredicates.AppendElement(aExpr);
return NS_OK;
}
nsresult evaluatePredicates(txNodeSet* aNodes, txIMatchContext* aContext);
@ -700,8 +710,9 @@ class PathExpr : public Expr {
* The ownership of the given Expr is passed over the PathExpr,
* even on failure.
* @param aExpr the Expr to add to this PathExpr
* @return nsresult indicating out of memory
*/
void addExpr(Expr* aExpr, PathOperator pathOp);
nsresult addExpr(Expr* aExpr, PathOperator pathOp);
/**
* Removes and deletes the expression at the given index.
@ -776,8 +787,14 @@ class UnionExpr : public Expr {
* The ownership of the given Expr is passed over the UnionExpr,
* even on failure.
* @param aExpr the Expr to add to this UnionExpr
* @return nsresult indicating out of memory
*/
void addExpr(Expr* aExpr) { mExpressions.AppendElement(aExpr); }
nsresult addExpr(Expr* aExpr) {
// XXX(Bug 1631371) Check if this should use a fallible operation as it
// pretended earlier, or change the return type to void.
mExpressions.AppendElement(aExpr);
return NS_OK;
}
/**
* Removes and deletes the expression at the given index.
@ -817,8 +834,11 @@ class txNamedAttributeStep : public Expr {
*/
class txUnionNodeTest : public txNodeTest {
public:
void addNodeTest(txNodeTest* aNodeTest) {
nsresult addNodeTest(txNodeTest* aNodeTest) {
// XXX(Bug 1631371) Check if this should use a fallible operation as it
// pretended earlier, or change the return type to void.
mNodeTests.AppendElement(aNodeTest);
return NS_OK;
}
TX_DECL_NODE_TEST

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

@ -319,6 +319,7 @@ nsresult txExprLexer::parse(const nsAString& aPattern) {
}
}
if (isToken) {
NS_ENSURE_TRUE(newToken, NS_ERROR_OUT_OF_MEMORY);
NS_ENSURE_TRUE(newToken != mLastItem, NS_ERROR_FAILURE);
prevToken = newToken;
addToken(newToken);

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

@ -121,11 +121,13 @@ nsresult txExprParser::createAVT(const nsAString& aAttrValue,
} else {
if (!concat) {
concat = new txCoreFunctionCall(txCoreFunctionCall::CONCAT);
concat->addParam(expr.release());
rv = concat->addParam(expr.release());
expr = WrapUnique(concat);
NS_ENSURE_SUCCESS(rv, rv);
}
concat->addParam(newExpr.release());
rv = concat->addParam(newExpr.release());
NS_ENSURE_SUCCESS(rv, rv);
}
}
@ -172,7 +174,8 @@ nsresult txExprParser::createExprInternal(const nsAString& aExpression,
txXPathOptimizer optimizer;
Expr* newExpr = nullptr;
optimizer.optimize(expr.get(), &newExpr);
rv = optimizer.optimize(expr.get(), &newExpr);
NS_ENSURE_SUCCESS(rv, rv);
*aExpr = newExpr ? newExpr : expr.release();
@ -250,6 +253,7 @@ nsresult txExprParser::createBinaryExpr(UniquePtr<Expr>& left,
MOZ_ASSERT_UNREACHABLE("operator tokens should be already checked");
return NS_ERROR_UNEXPECTED;
}
NS_ENSURE_TRUE(expr, NS_ERROR_OUT_OF_MEMORY);
Unused << left.release();
Unused << right.release();
@ -284,11 +288,13 @@ nsresult txExprParser::createExpr(txExprLexer& lexer, txIParseContext* aContext,
if (negations > 0) {
if (negations % 2 == 0) {
auto fcExpr =
MakeUnique<txCoreFunctionCall>(txCoreFunctionCall::NUMBER);
FunctionCall* fcExpr =
new txCoreFunctionCall(txCoreFunctionCall::NUMBER);
fcExpr->addParam(expr.release());
expr = std::move(fcExpr);
rv = fcExpr->addParam(expr.get());
if (NS_FAILED(rv)) return rv;
Unused << expr.release();
expr = WrapUnique(fcExpr);
} else {
expr = MakeUnique<UnaryExpr>(expr.release());
}
@ -585,6 +591,8 @@ nsresult txExprParser::createNodeTypeTest(txExprLexer& lexer,
return NS_ERROR_XPATH_NO_NODE_TYPE_TEST;
}
NS_ENSURE_TRUE(nodeTest, NS_ERROR_OUT_OF_MEMORY);
if (nodeTok->mType == Token::PROC_INST_AND_PAREN &&
lexer.peek()->mType == Token::LITERAL) {
Token* tok = lexer.nextToken();
@ -643,7 +651,11 @@ nsresult txExprParser::createPathExpr(txExprLexer& lexer,
// We have a PathExpr containing several steps
UniquePtr<PathExpr> pathExpr(new PathExpr());
pathExpr->addExpr(expr.release(), PathExpr::RELATIVE_OP);
rv = pathExpr->addExpr(expr.get(), PathExpr::RELATIVE_OP);
NS_ENSURE_SUCCESS(rv, rv);
Unused << expr.release();
// this is ugly
while (1) {
@ -664,7 +676,10 @@ nsresult txExprParser::createPathExpr(txExprLexer& lexer,
rv = createLocationStep(lexer, aContext, getter_Transfers(expr));
NS_ENSURE_SUCCESS(rv, rv);
pathExpr->addExpr(expr.release(), pathOp);
rv = pathExpr->addExpr(expr.get(), pathOp);
NS_ENSURE_SUCCESS(rv, rv);
Unused << expr.release();
}
MOZ_ASSERT_UNREACHABLE("internal xpath parser error");
return NS_ERROR_UNEXPECTED;
@ -689,7 +704,11 @@ nsresult txExprParser::createUnionExpr(txExprLexer& lexer,
}
UniquePtr<UnionExpr> unionExpr(new UnionExpr());
unionExpr->addExpr(expr.release());
rv = unionExpr->addExpr(expr.get());
NS_ENSURE_SUCCESS(rv, rv);
Unused << expr.release();
while (lexer.peek()->mType == Token::UNION_OP) {
lexer.nextToken(); //-- eat token
@ -697,7 +716,8 @@ nsresult txExprParser::createUnionExpr(txExprLexer& lexer,
rv = createPathExpr(lexer, aContext, getter_Transfers(expr));
NS_ENSURE_SUCCESS(rv, rv);
unionExpr->addExpr(expr.release());
rv = unionExpr->addExpr(expr.release());
NS_ENSURE_SUCCESS(rv, rv);
}
*aResult = unionExpr.release();
@ -736,7 +756,10 @@ nsresult txExprParser::parsePredicates(PredicateList* aPredicateList,
rv = createExpr(lexer, aContext, getter_Transfers(expr));
NS_ENSURE_SUCCESS(rv, rv);
aPredicateList->add(expr.release());
rv = aPredicateList->add(expr.get());
NS_ENSURE_SUCCESS(rv, rv);
Unused << expr.release();
if (lexer.peek()->mType != Token::R_BRACKET) {
return NS_ERROR_XPATH_BRACKET_EXPECTED;
@ -769,7 +792,8 @@ nsresult txExprParser::parseParameters(FunctionCall* aFnCall,
NS_ENSURE_SUCCESS(rv, rv);
if (aFnCall) {
aFnCall->addParam(expr.release());
rv = aFnCall->addParam(expr.release());
NS_ENSURE_SUCCESS(rv, rv);
}
switch (lexer.peek()->mType) {

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

@ -21,12 +21,17 @@ using mozilla::WrapUnique;
* Adds the Expr to this PathExpr
* @param expr the Expr to add to this PathExpr
**/
void PathExpr::addExpr(Expr* aExpr, PathOperator aPathOp) {
nsresult PathExpr::addExpr(Expr* aExpr, PathOperator aPathOp) {
NS_ASSERTION(!mItems.IsEmpty() || aPathOp == RELATIVE_OP,
"First step has to be relative in PathExpr");
PathExprItem* pxi = mItems.AppendElement();
if (!pxi) {
return NS_ERROR_OUT_OF_MEMORY;
}
pxi->expr = WrapUnique(aExpr);
pxi->pathOp = aPathOp;
return NS_OK;
}
//-----------------------------/

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

@ -32,18 +32,28 @@ void txResultRecycler::recycle(txAExprResult* aResult) {
RefPtr<txResultRecycler> kungFuDeathGrip;
aResult->mRecycler.swap(kungFuDeathGrip);
nsresult rv = NS_OK;
switch (aResult->getResultType()) {
case txAExprResult::STRING: {
mStringResults.push(static_cast<StringResult*>(aResult));
rv = mStringResults.push(static_cast<StringResult*>(aResult));
if (NS_FAILED(rv)) {
delete aResult;
}
return;
}
case txAExprResult::NODESET: {
static_cast<txNodeSet*>(aResult)->clear();
mNodeSetResults.push(static_cast<txNodeSet*>(aResult));
rv = mNodeSetResults.push(static_cast<txNodeSet*>(aResult));
if (NS_FAILED(rv)) {
delete aResult;
}
return;
}
case txAExprResult::NUMBER: {
mNumberResults.push(static_cast<NumberResult*>(aResult));
rv = mNumberResults.push(static_cast<NumberResult*>(aResult));
if (NS_FAILED(rv)) {
delete aResult;
}
return;
}
default: {

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

@ -46,8 +46,9 @@ class txEarlyEvalContext : public txIEvalContext {
txResultRecycler* mRecycler;
};
void txXPathOptimizer::optimize(Expr* aInExpr, Expr** aOutExpr) {
nsresult txXPathOptimizer::optimize(Expr* aInExpr, Expr** aOutExpr) {
*aOutExpr = nullptr;
nsresult rv = NS_OK;
// First check if the expression will produce the same result
// under any context.
@ -60,12 +61,12 @@ void txXPathOptimizer::optimize(Expr* aInExpr, Expr** aOutExpr) {
// Don't throw if this fails since it could be that the expression
// is or contains an error-expression.
nsresult rv = aInExpr->evaluate(&context, getter_AddRefs(exprRes));
rv = aInExpr->evaluate(&context, getter_AddRefs(exprRes));
if (NS_SUCCEEDED(rv)) {
*aOutExpr = new txLiteralExpr(exprRes);
}
return;
return NS_OK;
}
// Then optimize sub expressions
@ -73,7 +74,8 @@ void txXPathOptimizer::optimize(Expr* aInExpr, Expr** aOutExpr) {
Expr* subExpr;
while ((subExpr = aInExpr->getSubExprAt(i))) {
Expr* newExpr = nullptr;
optimize(subExpr, &newExpr);
rv = optimize(subExpr, &newExpr);
NS_ENSURE_SUCCESS(rv, rv);
if (newExpr) {
delete subExpr;
aInExpr->setSubExprAt(i, newExpr);
@ -85,23 +87,22 @@ void txXPathOptimizer::optimize(Expr* aInExpr, Expr** aOutExpr) {
// Finally see if current expression can be optimized
switch (exprType) {
case Expr::LOCATIONSTEP_EXPR:
optimizeStep(aInExpr, aOutExpr);
return;
return optimizeStep(aInExpr, aOutExpr);
case Expr::PATH_EXPR:
optimizePath(aInExpr, aOutExpr);
return;
return optimizePath(aInExpr, aOutExpr);
case Expr::UNION_EXPR:
optimizeUnion(aInExpr, aOutExpr);
return;
return optimizeUnion(aInExpr, aOutExpr);
default:
return;
break;
}
return NS_OK;
}
void txXPathOptimizer::optimizeStep(Expr* aInExpr, Expr** aOutExpr) {
nsresult txXPathOptimizer::optimizeStep(Expr* aInExpr, Expr** aOutExpr) {
LocationStep* step = static_cast<LocationStep*>(aInExpr);
if (step->getAxisIdentifier() == LocationStep::ATTRIBUTE_AXIS) {
@ -113,7 +114,7 @@ void txXPathOptimizer::optimizeStep(Expr* aInExpr, Expr** aOutExpr) {
->mLocalName != nsGkAtoms::_asterisk) {
*aOutExpr = new txNamedAttributeStep(
nameTest->mNamespace, nameTest->mPrefix, nameTest->mLocalName);
return; // return since we no longer have a step-object.
return NS_OK; // return since we no longer have a step-object.
}
}
@ -126,9 +127,11 @@ void txXPathOptimizer::optimizeStep(Expr* aInExpr, Expr** aOutExpr) {
step->dropFirst();
step->setNodeTest(predTest);
}
return NS_OK;
}
void txXPathOptimizer::optimizePath(Expr* aInExpr, Expr** aOutExpr) {
nsresult txXPathOptimizer::optimizePath(Expr* aInExpr, Expr** aOutExpr) {
PathExpr* path = static_cast<PathExpr*>(aInExpr);
uint32_t i;
@ -170,7 +173,7 @@ void txXPathOptimizer::optimizePath(Expr* aInExpr, Expr** aOutExpr) {
*aOutExpr = path->getSubExprAt(1);
path->setSubExprAt(1, nullptr);
return;
return NS_OK;
}
// Just delete the '.' step and leave the rest of the PathExpr
@ -178,14 +181,17 @@ void txXPathOptimizer::optimizePath(Expr* aInExpr, Expr** aOutExpr) {
}
}
}
return NS_OK;
}
void txXPathOptimizer::optimizeUnion(Expr* aInExpr, Expr** aOutExpr) {
nsresult txXPathOptimizer::optimizeUnion(Expr* aInExpr, Expr** aOutExpr) {
UnionExpr* uni = static_cast<UnionExpr*>(aInExpr);
// Check for expressions like "foo | bar" and
// "descendant::foo | descendant::bar"
nsresult rv;
uint32_t current;
Expr* subExpr;
for (current = 0; (subExpr = uni->getSubExprAt(current)); ++current) {
@ -216,14 +222,16 @@ void txXPathOptimizer::optimizeUnion(Expr* aInExpr, Expr** aOutExpr) {
// Create a txUnionNodeTest if needed
if (!unionTest) {
UniquePtr<txNodeTest> owner(unionTest = new txUnionNodeTest);
unionTest->addNodeTest(currentStep->getNodeTest());
rv = unionTest->addNodeTest(currentStep->getNodeTest());
NS_ENSURE_SUCCESS(rv, rv);
currentStep->setNodeTest(unionTest);
Unused << owner.release();
}
// Merge the nodetest into the union
unionTest->addNodeTest(step->getNodeTest());
rv = unionTest->addNodeTest(step->getNodeTest());
NS_ENSURE_SUCCESS(rv, rv);
step->setNodeTest(nullptr);
@ -240,7 +248,9 @@ void txXPathOptimizer::optimizeUnion(Expr* aInExpr, Expr** aOutExpr) {
*aOutExpr = currentStep;
// Return right away since we no longer have a union
return;
return NS_OK;
}
}
return NS_OK;
}

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

@ -18,13 +18,13 @@ class txXPathOptimizer {
* @param aOutExpr Resulting expression, null if optimization didn't
* result in a new expression.
*/
void optimize(Expr* aInExpr, Expr** aOutExpr);
nsresult optimize(Expr* aInExpr, Expr** aOutExpr);
private:
// Helper methods for optimizing specific classes
void optimizeStep(Expr* aInExpr, Expr** aOutExpr);
void optimizePath(Expr* aInExpr, Expr** aOutExpr);
void optimizeUnion(Expr* aInExpr, Expr** aOutExpr);
nsresult optimizeStep(Expr* aInExpr, Expr** aOutExpr);
nsresult optimizePath(Expr* aInExpr, Expr** aOutExpr);
nsresult optimizeUnion(Expr* aInExpr, Expr** aOutExpr);
};
#endif

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

@ -242,7 +242,15 @@ nsresult txExecutionState::getVariable(int32_t aNamespace, nsAtom* aLName,
return rv;
}
} else {
pushResultHandler(new txRtfHandler);
UniquePtr<txRtfHandler> rtfHandler(new txRtfHandler);
rv = pushResultHandler(rtfHandler.get());
if (NS_FAILED(rv)) {
popAndDeleteEvalContextUntil(mInitialEvalContext);
return rv;
}
Unused << rtfHandler.release();
txInstruction* prevInstr = mNextInstruction;
// set return to nullptr to stop execution
@ -263,8 +271,7 @@ nsresult txExecutionState::getVariable(int32_t aNamespace, nsAtom* aLName,
popTemplateRule();
mNextInstruction = prevInstr;
UniquePtr<txRtfHandler> rtfHandler(
static_cast<txRtfHandler*>(popResultHandler()));
rtfHandler = WrapUnique((txRtfHandler*)popResultHandler());
rv = rtfHandler->getAsRTF(&aResult);
if (NS_FAILED(rv)) {
popAndDeleteEvalContextUntil(mInitialEvalContext);
@ -298,9 +305,13 @@ void txExecutionState::receiveError(const nsAString& aMsg, nsresult aRes) {
// XXX implement me
}
void txExecutionState::pushEvalContext(txIEvalContext* aContext) {
mEvalContextStack.push(mEvalContext);
nsresult txExecutionState::pushEvalContext(txIEvalContext* aContext) {
nsresult rv = mEvalContextStack.push(mEvalContext);
NS_ENSURE_SUCCESS(rv, rv);
mEvalContext = aContext;
return NS_OK;
}
txIEvalContext* txExecutionState::popEvalContext() {
@ -310,7 +321,12 @@ txIEvalContext* txExecutionState::popEvalContext() {
return prev;
}
void txExecutionState::pushBool(bool aBool) { mBoolStack.AppendElement(aBool); }
nsresult txExecutionState::pushBool(bool aBool) {
// XXX(Bug 1631371) Check if this should use a fallible operation as it
// pretended earlier, or change the return type to void.
mBoolStack.AppendElement(aBool);
return NS_OK;
}
bool txExecutionState::popBool() {
NS_ASSERTION(mBoolStack.Length(), "popping from empty stack");
@ -318,9 +334,13 @@ bool txExecutionState::popBool() {
return mBoolStack.IsEmpty() ? false : mBoolStack.PopLastElement();
}
void txExecutionState::pushResultHandler(txAXMLEventHandler* aHandler) {
mResultHandlerStack.push(mResultHandler);
nsresult txExecutionState::pushResultHandler(txAXMLEventHandler* aHandler) {
nsresult rv = mResultHandlerStack.push(mResultHandler);
NS_ENSURE_SUCCESS(rv, rv);
mResultHandler = aHandler;
return NS_OK;
}
txAXMLEventHandler* txExecutionState::popResultHandler() {
@ -408,8 +428,11 @@ nsresult txExecutionState::runTemplate(txInstruction* aTemplate) {
NS_ENSURE_TRUE(++mRecursionDepth < kMaxRecursionDepth,
NS_ERROR_XSLT_BAD_RECURSION);
mLocalVarsStack.push(mLocalVariables);
mReturnStack.push(mNextInstruction);
nsresult rv = mLocalVarsStack.push(mLocalVariables);
NS_ENSURE_SUCCESS(rv, rv);
rv = mReturnStack.push(mNextInstruction);
NS_ENSURE_SUCCESS(rv, rv);
mLocalVariables = nullptr;
mNextInstruction = aTemplate;

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

@ -81,7 +81,7 @@ class txExecutionState : public txIMatchContext {
};
// Stack functions
void pushEvalContext(txIEvalContext* aContext);
nsresult pushEvalContext(txIEvalContext* aContext);
txIEvalContext* popEvalContext();
/**
@ -91,9 +91,9 @@ class txExecutionState : public txIMatchContext {
*/
void popAndDeleteEvalContextUntil(txIEvalContext* aContext);
void pushBool(bool aBool);
nsresult pushBool(bool aBool);
bool popBool();
void pushResultHandler(txAXMLEventHandler* aHandler);
nsresult pushResultHandler(txAXMLEventHandler* aHandler);
txAXMLEventHandler* popResultHandler();
void pushTemplateRule(txStylesheet::ImportFrame* aFrame,
const txExpandedName& aMode, txParameterMap* aParams);

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

@ -21,7 +21,6 @@
#include "txTextHandler.h"
#include "txXSLTNumber.h"
using mozilla::MakeUnique;
using mozilla::UniquePtr;
nsresult txApplyDefaultElementTemplate::execute(txExecutionState& aEs) {
@ -292,7 +291,8 @@ nsresult txCopy::execute(txExecutionState& aEs) {
rv = aEs.mResultHandler->characters(u""_ns, false);
NS_ENSURE_SUCCESS(rv, rv);
aEs.pushBool(false);
rv = aEs.pushBool(false);
NS_ENSURE_SUCCESS(rv, rv);
break;
}
@ -305,7 +305,8 @@ nsresult txCopy::execute(txExecutionState& aEs) {
// XXX copy namespace nodes once we have them
aEs.pushBool(true);
rv = aEs.pushBool(true);
NS_ENSURE_SUCCESS(rv, rv);
break;
}
@ -546,26 +547,35 @@ nsresult txPushNewContext::execute(txExecutionState& aEs) {
rv = sorter.sortNodeSet(nodes, &aEs, getter_AddRefs(sortedNodes));
NS_ENSURE_SUCCESS(rv, rv);
auto context = MakeUnique<txNodeSetContext>(sortedNodes, &aEs);
txNodeSetContext* context = new txNodeSetContext(sortedNodes, &aEs);
NS_ENSURE_TRUE(context, NS_ERROR_OUT_OF_MEMORY);
context->next();
aEs.pushEvalContext(context.release());
rv = aEs.pushEvalContext(context);
if (NS_FAILED(rv)) {
delete context;
return rv;
}
return NS_OK;
}
void txPushNewContext::addSort(UniquePtr<Expr>&& aSelectExpr,
UniquePtr<Expr>&& aLangExpr,
UniquePtr<Expr>&& aDataTypeExpr,
UniquePtr<Expr>&& aOrderExpr,
UniquePtr<Expr>&& aCaseOrderExpr) {
SortKey* key = mSortKeys.AppendElement();
// workaround for not triggering the Copy Constructor
key->mSelectExpr = std::move(aSelectExpr);
key->mLangExpr = std::move(aLangExpr);
key->mDataTypeExpr = std::move(aDataTypeExpr);
key->mOrderExpr = std::move(aOrderExpr);
key->mCaseOrderExpr = std::move(aCaseOrderExpr);
nsresult txPushNewContext::addSort(UniquePtr<Expr>&& aSelectExpr,
UniquePtr<Expr>&& aLangExpr,
UniquePtr<Expr>&& aDataTypeExpr,
UniquePtr<Expr>&& aOrderExpr,
UniquePtr<Expr>&& aCaseOrderExpr) {
if (SortKey* key = mSortKeys.AppendElement()) {
// workaround for not triggering the Copy Constructor
key->mSelectExpr = std::move(aSelectExpr);
key->mLangExpr = std::move(aLangExpr);
key->mDataTypeExpr = std::move(aDataTypeExpr);
key->mOrderExpr = std::move(aOrderExpr);
key->mCaseOrderExpr = std::move(aCaseOrderExpr);
return NS_OK;
}
return NS_ERROR_OUT_OF_MEMORY;
}
nsresult txPushNullTemplateRule::execute(txExecutionState& aEs) {
@ -579,7 +589,12 @@ nsresult txPushParams::execute(txExecutionState& aEs) {
}
nsresult txPushRTFHandler::execute(txExecutionState& aEs) {
aEs.pushResultHandler(new txRtfHandler);
txAXMLEventHandler* handler = new txRtfHandler;
nsresult rv = aEs.pushResultHandler(handler);
if (NS_FAILED(rv)) {
delete handler;
return rv;
}
return NS_OK;
}
@ -588,7 +603,12 @@ txPushStringHandler::txPushStringHandler(bool aOnlyText)
: mOnlyText(aOnlyText) {}
nsresult txPushStringHandler::execute(txExecutionState& aEs) {
aEs.pushResultHandler(new txTextHandler(mOnlyText));
txAXMLEventHandler* handler = new txTextHandler(mOnlyText);
nsresult rv = aEs.pushResultHandler(handler);
if (NS_FAILED(rv)) {
delete handler;
return rv;
}
return NS_OK;
}
@ -710,7 +730,8 @@ nsresult txStartElement::execute(txExecutionState& aEs) {
}
NS_ENSURE_SUCCESS(rv, rv);
aEs.pushBool(success);
rv = aEs.pushBool(success);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
@ -728,7 +749,8 @@ nsresult txStartLREElement::execute(txExecutionState& aEs) {
mPrefix, mLocalName, mLowercaseLocalName, mNamespaceID);
NS_ENSURE_SUCCESS(rv, rv);
aEs.pushBool(true);
rv = aEs.pushBool(true);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}

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

@ -229,11 +229,11 @@ class txPushNewContext : public txInstruction {
TX_DECL_TXINSTRUCTION
void addSort(mozilla::UniquePtr<Expr>&& aSelectExpr,
mozilla::UniquePtr<Expr>&& aLangExpr,
mozilla::UniquePtr<Expr>&& aDataTypeExpr,
mozilla::UniquePtr<Expr>&& aOrderExpr,
mozilla::UniquePtr<Expr>&& aCaseOrderExpr);
nsresult addSort(mozilla::UniquePtr<Expr>&& aSelectExpr,
mozilla::UniquePtr<Expr>&& aLangExpr,
mozilla::UniquePtr<Expr>&& aDataTypeExpr,
mozilla::UniquePtr<Expr>&& aOrderExpr,
mozilla::UniquePtr<Expr>&& aCaseOrderExpr);
struct SortKey {
mozilla::UniquePtr<Expr> mSelectExpr;

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

@ -300,11 +300,15 @@ nsresult txXSLKey::testNode(const txXPathNode& aNode, txKeyValueHashKey& aKey,
NS_ENSURE_SUCCESS(rv, rv);
if (matched) {
aEs.pushEvalContext(new txSingleNodeContext(aNode, &aEs));
txSingleNodeContext* evalContext = new txSingleNodeContext(aNode, &aEs);
NS_ENSURE_TRUE(evalContext, NS_ERROR_OUT_OF_MEMORY);
nsresult rv = aEs.pushEvalContext(evalContext);
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<txAExprResult> exprResult;
nsresult rv = mKeys[currKey].useExpr->evaluate(
aEs.getEvalContext(), getter_AddRefs(exprResult));
rv = mKeys[currKey].useExpr->evaluate(evalContext,
getter_AddRefs(exprResult));
delete aEs.popEvalContext();
NS_ENSURE_SUCCESS(rv, rv);

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

@ -3,6 +3,7 @@
* 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"
@ -424,6 +425,7 @@ nsresult txCompileObserver::startLoad(nsIURI* aUri,
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<txStylesheetSink> sink = new txStylesheetSink(aCompiler, parser);
NS_ENSURE_TRUE(sink, NS_ERROR_OUT_OF_MEMORY);
channel->SetNotificationCallbacks(sink);
@ -445,9 +447,11 @@ nsresult TX_LoadSheet(nsIURI* aUri, txMozillaXSLTProcessor* aProcessor,
RefPtr<txCompileObserver> observer =
new txCompileObserver(aProcessor, aLoaderDocument);
NS_ENSURE_TRUE(observer, NS_ERROR_OUT_OF_MEMORY);
RefPtr<txStylesheetCompiler> compiler = new txStylesheetCompiler(
NS_ConvertUTF8toUTF16(spec), aReferrerPolicy, observer);
NS_ENSURE_TRUE(compiler, NS_ERROR_OUT_OF_MEMORY);
return observer->startLoad(aUri, compiler, principal, aReferrerPolicy);
}
@ -607,9 +611,11 @@ nsresult TX_CompileStylesheet(nsINode* aNode,
NS_ConvertUTF8toUTF16 stylesheetURI(spec);
RefPtr<txSyncCompileObserver> obs = new txSyncCompileObserver(aProcessor);
NS_ENSURE_TRUE(obs, NS_ERROR_OUT_OF_MEMORY);
RefPtr<txStylesheetCompiler> compiler =
new txStylesheetCompiler(stylesheetURI, doc->GetReferrerPolicy(), obs);
NS_ENSURE_TRUE(compiler, NS_ERROR_OUT_OF_MEMORY);
compiler->setBaseURI(baseURI);

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

@ -256,7 +256,8 @@ nsresult txMozillaXMLOutput::endElement() {
// Handle html-elements
if (!mNoFixup) {
if (element->IsHTMLElement()) {
endHTMLElement(element);
rv = endHTMLElement(element);
NS_ENSURE_SUCCESS(rv, rv);
}
// Handle elements that are different when parser-created
@ -272,7 +273,8 @@ 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) {
mNotifier->AddScriptElement(sele);
rv = mNotifier->AddScriptElement(sele);
NS_ENSURE_SUCCESS(rv, rv);
}
} else {
MOZ_ASSERT(nsNameSpaceManager::GetInstance()->mSVGDisabled,
@ -300,11 +302,11 @@ nsresult txMozillaXMLOutput::endElement() {
// Add the element to the tree if it wasn't added before and take one step
// up the tree
MOZ_ASSERT(!mCurrentNodeStack.IsEmpty(), "empty stack");
nsCOMPtr<nsINode> parent;
if (!mCurrentNodeStack.IsEmpty()) {
parent = mCurrentNodeStack.PopLastElement();
}
uint32_t last = mCurrentNodeStack.Count() - 1;
NS_ASSERTION(last != (uint32_t)-1, "empty stack");
nsCOMPtr<nsINode> parent = mCurrentNodeStack.SafeObjectAt(last);
mCurrentNodeStack.RemoveObjectAt(last);
if (mCurrentNode == mNonAddedNode) {
if (parent == mDocument) {
@ -469,9 +471,12 @@ nsresult txMozillaXMLOutput::startElementInternal(nsAtom* aPrefix,
++mTreeDepth;
mTableStateStack.push(NS_INT32_TO_PTR(mTableState));
rv = mTableStateStack.push(NS_INT32_TO_PTR(mTableState));
NS_ENSURE_SUCCESS(rv, rv);
mCurrentNodeStack.AppendElement(mCurrentNode);
if (!mCurrentNodeStack.AppendObject(mCurrentNode)) {
return NS_ERROR_OUT_OF_MEMORY;
}
mTableState = NORMAL;
mOpenedElementIsHTML = false;
@ -608,7 +613,9 @@ nsresult txMozillaXMLOutput::createTxWrapper() {
}
}
mCurrentNodeStack.AppendElement(wrapper);
if (!mCurrentNodeStack.AppendObject(wrapper)) {
return NS_ERROR_OUT_OF_MEMORY;
}
mCurrentNode = wrapper;
mRootContentCreated = true;
NS_ASSERTION(rootLocation == mDocument->GetChildCount(),
@ -624,12 +631,11 @@ nsresult txMozillaXMLOutput::startHTMLElement(nsIContent* aElement,
if ((!aElement->IsHTMLElement(nsGkAtoms::tr) || !aIsHTML) &&
NS_PTR_TO_INT32(mTableStateStack.peek()) == ADDED_TBODY) {
MOZ_ASSERT(!mCurrentNodeStack.IsEmpty(), "empty stack");
if (mCurrentNodeStack.IsEmpty()) {
mCurrentNode = nullptr;
} else {
mCurrentNode = mCurrentNodeStack.PopLastElement();
}
uint32_t last = mCurrentNodeStack.Count() - 1;
NS_ASSERTION(last != (uint32_t)-1, "empty stack");
mCurrentNode = mCurrentNodeStack.SafeObjectAt(last);
mCurrentNodeStack.RemoveObjectAt(last);
mTableStateStack.pop();
}
@ -647,9 +653,13 @@ nsresult txMozillaXMLOutput::startHTMLElement(nsIContent* aElement,
return error.StealNSResult();
}
mTableStateStack.push(NS_INT32_TO_PTR(ADDED_TBODY));
rv = mTableStateStack.push(NS_INT32_TO_PTR(ADDED_TBODY));
NS_ENSURE_SUCCESS(rv, rv);
if (!mCurrentNodeStack.AppendObject(tbody)) {
return NS_ERROR_OUT_OF_MEMORY;
}
mCurrentNodeStack.AppendElement(tbody);
mCurrentNode = tbody;
} else if (aElement->IsHTMLElement(nsGkAtoms::head) &&
mOutputFormat.mMethod == eHTMLOutput) {
@ -683,23 +693,20 @@ nsresult txMozillaXMLOutput::startHTMLElement(nsIContent* aElement,
return NS_OK;
}
void txMozillaXMLOutput::endHTMLElement(nsIContent* aElement) {
nsresult txMozillaXMLOutput::endHTMLElement(nsIContent* aElement) {
if (mTableState == ADDED_TBODY) {
NS_ASSERTION(aElement->IsHTMLElement(nsGkAtoms::tbody),
"Element flagged as added tbody isn't a tbody");
MOZ_ASSERT(!mCurrentNodeStack.IsEmpty(), "empty stack");
if (mCurrentNodeStack.IsEmpty()) {
mCurrentNode = nullptr;
} else {
mCurrentNode = mCurrentNodeStack.PopLastElement();
}
uint32_t last = mCurrentNodeStack.Count() - 1;
NS_ASSERTION(last != (uint32_t)-1, "empty stack");
mCurrentNode = mCurrentNodeStack.SafeObjectAt(last);
mCurrentNodeStack.RemoveObjectAt(last);
mTableState =
static_cast<TableState>(NS_PTR_TO_INT32(mTableStateStack.pop()));
return;
}
if (mCreatingNewDocument && aElement->IsHTMLElement(nsGkAtoms::meta)) {
return NS_OK;
} else if (mCreatingNewDocument && aElement->IsHTMLElement(nsGkAtoms::meta)) {
// handle HTTP-EQUIV data
nsAutoString httpEquiv;
aElement->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::httpEquiv,
@ -715,6 +722,8 @@ void txMozillaXMLOutput::endHTMLElement(nsIContent* aElement) {
}
}
}
return NS_OK;
}
void txMozillaXMLOutput::processHTTPEquiv(nsAtom* aHeader,
@ -884,7 +893,7 @@ txTransformNotifier::ScriptAvailable(nsresult aResult,
nsIScriptElement* aElement,
bool aIsInlineClassicScript, nsIURI* aURI,
int32_t aLineNo) {
if (NS_FAILED(aResult) && mScriptElements.RemoveElement(aElement)) {
if (NS_FAILED(aResult) && mScriptElements.RemoveObject(aElement)) {
SignalTransformEnd();
}
@ -895,7 +904,7 @@ NS_IMETHODIMP
txTransformNotifier::ScriptEvaluated(nsresult aResult,
nsIScriptElement* aElement,
bool aIsInline) {
if (mScriptElements.RemoveElement(aElement)) {
if (mScriptElements.RemoveObject(aElement)) {
SignalTransformEnd();
}
@ -925,8 +934,9 @@ void txTransformNotifier::Init(nsITransformObserver* aObserver) {
mObserver = aObserver;
}
void txTransformNotifier::AddScriptElement(nsIScriptElement* aElement) {
mScriptElements.AppendElement(aElement);
nsresult txTransformNotifier::AddScriptElement(nsIScriptElement* aElement) {
return mScriptElements.AppendObject(aElement) ? NS_OK
: NS_ERROR_OUT_OF_MEMORY;
}
void txTransformNotifier::AddPendingStylesheet() { ++mPendingStylesheetCount; }
@ -948,7 +958,7 @@ nsresult txTransformNotifier::SetOutputDocument(Document* aDocument) {
void txTransformNotifier::SignalTransformEnd(nsresult aResult) {
if (mInTransform ||
(NS_SUCCEEDED(aResult) &&
(!mScriptElements.IsEmpty() || mPendingStylesheetCount > 0))) {
(mScriptElements.Count() > 0 || mPendingStylesheetCount > 0))) {
return;
}

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

@ -9,7 +9,7 @@
#include "txXMLEventHandler.h"
#include "nsIScriptLoaderObserver.h"
#include "txOutputFormat.h"
#include "nsTArray.h"
#include "nsCOMArray.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);
void AddScriptElement(nsIScriptElement* aElement);
nsresult 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;
nsTArray<nsCOMPtr<nsIScriptElement>> mScriptElements;
nsCOMArray<nsIScriptElement> mScriptElements;
uint32_t mPendingStylesheetCount;
bool mInTransform;
};
@ -78,7 +78,7 @@ class txMozillaXMLOutput : public txAOutputXMLEventHandler {
private:
nsresult createTxWrapper();
nsresult startHTMLElement(nsIContent* aElement, bool aXHTML);
void endHTMLElement(nsIContent* aElement);
nsresult 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;
nsTArray<nsCOMPtr<nsINode>> mCurrentNodeStack;
nsCOMArray<nsINode> mCurrentNodeStack;
nsCOMPtr<nsIContent> mNonAddedNode;

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

@ -182,6 +182,7 @@ nsresult txToFragmentHandlerFactory::createHandlerWith(
break;
}
}
NS_ENSURE_TRUE(*aHandler, NS_ERROR_OUT_OF_MEMORY);
return NS_OK;
}
@ -432,6 +433,7 @@ txMozillaXSLTProcessor::AddXSLTParam(const nsString& aName,
}
var = new txVariable(value);
NS_ENSURE_TRUE(var, NS_ERROR_OUT_OF_MEMORY);
return mVariables.add(varName, var);
}
@ -1214,6 +1216,10 @@ nsresult txVariable::Convert(nsIVariant* aValue, txAExprResult** aResult) {
}
*aResult = new txNodeSet(*xpathNode, nullptr);
if (!*aResult) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(*aResult);
return NS_OK;
@ -1227,6 +1233,9 @@ nsresult txVariable::Convert(nsIVariant* aValue, txAExprResult** aResult) {
nsCOMPtr<nsINodeList> nodeList = do_QueryInterface(supports);
if (nodeList) {
RefPtr<txNodeSet> nodeSet = new txNodeSet(nullptr);
if (!nodeSet) {
return NS_ERROR_OUT_OF_MEMORY;
}
uint32_t length = nodeList->Length();

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

@ -16,7 +16,6 @@
#include "mozilla/UniquePtrExtensions.h"
using mozilla::CheckedUint32;
using mozilla::MakeUnique;
using mozilla::MakeUniqueFallible;
using mozilla::UniquePtr;
@ -125,6 +124,12 @@ nsresult txNodeSorter::sortNodeSet(txNodeSet* aNodes, txExecutionState* aEs,
nsresult rv = aEs->recycler()->getNodeSet(getter_AddRefs(sortedNodes));
NS_ENSURE_SUCCESS(rv, rv);
txNodeSetContext* evalContext = new txNodeSetContext(aNodes, aEs);
NS_ENSURE_TRUE(evalContext, NS_ERROR_OUT_OF_MEMORY);
rv = aEs->pushEvalContext(evalContext);
NS_ENSURE_SUCCESS(rv, rv);
// Create and set up memoryblock for sort-values and indexarray
CheckedUint32 len = aNodes->size();
CheckedUint32 numSortValues = len * mNKeys;
@ -145,17 +150,12 @@ nsresult txNodeSorter::sortNodeSet(txNodeSet* aNodes, txExecutionState* aEs,
}
memset(sortValues.get(), 0, sortValuesSize.value());
auto nodeSetContext = MakeUnique<txNodeSetContext>(aNodes, aEs);
// Sort the indexarray
SortData sortData;
sortData.mNodeSorter = this;
sortData.mContext = nodeSetContext.get();
sortData.mContext = evalContext;
sortData.mSortValues = sortValues.get();
sortData.mRv = NS_OK;
aEs->pushEvalContext(nodeSetContext.release());
NS_QuickSort(indexes.get(), len.value(), sizeof(uint32_t), compareNodes,
&sortData);

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

@ -6,16 +6,18 @@
#include "txPatternOptimizer.h"
#include "txXSLTPatterns.h"
void txPatternOptimizer::optimize(txPattern* aInPattern,
txPattern** aOutPattern) {
nsresult txPatternOptimizer::optimize(txPattern* aInPattern,
txPattern** aOutPattern) {
*aOutPattern = nullptr;
nsresult rv = NS_OK;
// First optimize sub expressions
uint32_t i = 0;
Expr* subExpr;
while ((subExpr = aInPattern->getSubExprAt(i))) {
Expr* newExpr = nullptr;
mXPathOptimizer.optimize(subExpr, &newExpr);
rv = mXPathOptimizer.optimize(subExpr, &newExpr);
NS_ENSURE_SUCCESS(rv, rv);
if (newExpr) {
delete subExpr;
aInPattern->setSubExprAt(i, newExpr);
@ -29,7 +31,8 @@ void txPatternOptimizer::optimize(txPattern* aInPattern,
i = 0;
while ((subPattern = aInPattern->getSubPatternAt(i))) {
txPattern* newPattern = nullptr;
optimize(subPattern, &newPattern);
rv = optimize(subPattern, &newPattern);
NS_ENSURE_SUCCESS(rv, rv);
if (newPattern) {
delete subPattern;
aInPattern->setSubPatternAt(i, newPattern);
@ -41,16 +44,17 @@ void txPatternOptimizer::optimize(txPattern* aInPattern,
// Finally see if current pattern can be optimized
switch (aInPattern->getType()) {
case txPattern::STEP_PATTERN:
optimizeStep(aInPattern, aOutPattern);
return;
return optimizeStep(aInPattern, aOutPattern);
default:
break;
}
return NS_OK;
}
void txPatternOptimizer::optimizeStep(txPattern* aInPattern,
txPattern** aOutPattern) {
nsresult txPatternOptimizer::optimizeStep(txPattern* aInPattern,
txPattern** aOutPattern) {
txStepPattern* step = static_cast<txStepPattern*>(aInPattern);
// Test for predicates that can be combined into the nodetest
@ -62,4 +66,6 @@ void txPatternOptimizer::optimizeStep(txPattern* aInPattern,
step->dropFirst();
step->setNodeTest(predTest);
}
return NS_OK;
}

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

@ -18,11 +18,11 @@ class txPatternOptimizer {
* @param aOutPattern Resulting pattern, null if optimization didn't
* result in a new pattern.
*/
void optimize(txPattern* aInPattern, txPattern** aOutPattern);
nsresult optimize(txPattern* aInPattern, txPattern** aOutPattern);
private:
// Helper methods for optimizing specific classes
void optimizeStep(txPattern* aInPattern, txPattern** aOutPattern);
nsresult optimizeStep(txPattern* aInPattern, txPattern** aOutPattern);
txXPathOptimizer mXPathOptimizer;
};

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

@ -34,7 +34,8 @@ nsresult txPatternParser::createPattern(const nsString& aPattern,
txPatternOptimizer optimizer;
txPattern* newPattern = nullptr;
optimizer.optimize(pattern.get(), &newPattern);
rv = optimizer.optimize(pattern.get(), &newPattern);
NS_ENSURE_SUCCESS(rv, rv);
*aResult = newPattern ? newPattern : pattern.release();
@ -62,7 +63,14 @@ nsresult txPatternParser::createUnionPattern(txExprLexer& aLexer,
}
txUnionPattern* unionPattern = new txUnionPattern();
unionPattern->addPattern(locPath);
rv = unionPattern->addPattern(locPath);
#if 0 // XXX addPattern can't fail yet, it doesn't check for mem
if (NS_FAILED(rv)) {
delete unionPattern;
delete locPath;
return rv;
}
#endif
aLexer.nextToken();
do {
@ -71,7 +79,14 @@ nsresult txPatternParser::createUnionPattern(txExprLexer& aLexer,
delete unionPattern;
return rv;
}
unionPattern->addPattern(locPath);
rv = unionPattern->addPattern(locPath);
#if 0 // XXX addPattern can't fail yet, it doesn't check for mem
if (NS_FAILED(rv)) {
delete unionPattern;
delete locPath;
return rv;
}
#endif
type = aLexer.nextToken()->mType;
} while (type == Token::UNION_OP);
@ -143,10 +158,21 @@ nsresult txPatternParser::createLocPathPattern(txExprLexer& aLexer,
root->setSerialize(false);
#endif
pathPattern->addStep(root, isChild);
rv = pathPattern->addStep(root, isChild);
if (NS_FAILED(rv)) {
delete stepPattern;
delete pathPattern;
delete root;
return NS_ERROR_OUT_OF_MEMORY;
}
}
pathPattern->addStep(stepPattern, isChild);
rv = pathPattern->addStep(stepPattern, isChild);
if (NS_FAILED(rv)) {
delete stepPattern;
delete pathPattern;
return NS_ERROR_OUT_OF_MEMORY;
}
stepPattern = 0; // stepPattern is part of pathPattern now
while (type == Token::PARENT_OP || type == Token::ANCESTOR_OP) {
@ -157,7 +183,12 @@ nsresult txPatternParser::createLocPathPattern(txExprLexer& aLexer,
delete pathPattern;
return rv;
}
pathPattern->addStep(stepPattern, isChild);
rv = pathPattern->addStep(stepPattern, isChild);
if (NS_FAILED(rv)) {
delete stepPattern;
delete pathPattern;
return NS_ERROR_OUT_OF_MEMORY;
}
stepPattern = 0; // stepPattern is part of pathPattern now
type = aLexer.peek()->mType;
}

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

@ -310,7 +310,10 @@ nsresult txStylesheet::doneCompiling() {
itemIter.remove(); // remove() moves to the previous
itemIter.next();
}
// XXX(Bug 1631371) Check if this should use a fallible operation as it
// pretended earlier.
mStripSpaceTests.AppendElements(frameStripSpaceTests);
frameStripSpaceTests.Clear();
}
@ -351,7 +354,7 @@ nsresult txStylesheet::addTemplate(txTemplateItem* aTemplate,
aImportFrame->mMatchableTemplates.get(aTemplate->mMode);
if (!templates) {
UniquePtr<nsTArray<MatchableTemplate>> newList(
UniquePtr<nsTArray<MatchableTemplate> > newList(
new nsTArray<MatchableTemplate>);
nsresult rv =
aImportFrame->mMatchableTemplates.set(aTemplate->mMode, newList.get());
@ -387,6 +390,8 @@ nsresult txStylesheet::addTemplate(txTemplateItem* aTemplate,
}
MatchableTemplate* nt = templates->InsertElementAt(i);
NS_ENSURE_TRUE(nt, NS_ERROR_OUT_OF_MEMORY);
nt->mFirstInstruction = instr;
nt->mMatch = std::move(simple);
nt->mPriority = priority;
@ -437,7 +442,10 @@ nsresult txStylesheet::addStripSpace(
break;
}
}
// XXX(Bug 1631371) Check if this should use a fallible operation as it
// pretended earlier.
aFrameStripSpaceTests.InsertElementAt(i, sst);
aStripSpaceItem->mStripSpaceTests.RemoveElementAt(testCount - 1);
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -18,7 +18,7 @@ using HandleStartFn = nsresult (*)(int32_t aNamespaceID, nsAtom* aLocalName,
txStylesheetAttr* aAttributes,
int32_t aAttrCount,
txStylesheetCompilerState& aState);
using HandleEndFn = void (*)(txStylesheetCompilerState& aState);
using HandleEndFn = nsresult (*)(txStylesheetCompilerState& aState);
using HandleTextFn = nsresult (*)(const nsAString& aStr,
txStylesheetCompilerState& aState);

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

@ -161,7 +161,7 @@ nsresult txStylesheetCompiler::startElementInternal(
nsresult rv = NS_OK;
int32_t i;
for (i = mInScopeVariables.Length() - 1; i >= 0; --i) {
++mInScopeVariables[i].mLevel;
++mInScopeVariables[i]->mLevel;
}
// Update the elementcontext if we have special attributes
@ -213,6 +213,8 @@ nsresult txStylesheetCompiler::startElementInternal(
if (namespaceID == kNameSpaceID_Unknown)
return NS_ERROR_XSLT_PARSE_FAILURE;
// XXX(Bug 1631371) Check if this should use a fallible operation as it
// pretended earlier.
mElementContext->mInstructionNamespaces.AppendElement(namespaceID);
}
@ -272,7 +274,8 @@ nsresult txStylesheetCompiler::startElementInternal(
}
}
pushPtr(const_cast<txElementHandler*>(handler), eElementHandler);
rv = pushPtr(const_cast<txElementHandler*>(handler), eElementHandler);
NS_ENSURE_SUCCESS(rv, rv);
mElementContext->mDepth++;
@ -291,17 +294,20 @@ nsresult txStylesheetCompiler::endElement() {
int32_t i;
for (i = mInScopeVariables.Length() - 1; i >= 0; --i) {
txInScopeVariable& var = mInScopeVariables[i];
if (!--(var.mLevel)) {
addInstruction(MakeUnique<txRemoveVariable>(var.mName));
txInScopeVariable* var = mInScopeVariables[i];
if (!--(var->mLevel)) {
UniquePtr<txInstruction> instr(new txRemoveVariable(var->mName));
addInstruction(std::move(instr));
mInScopeVariables.RemoveElementAt(i);
delete var;
}
}
const txElementHandler* handler = const_cast<const txElementHandler*>(
static_cast<txElementHandler*>(popPtr(eElementHandler)));
(handler->mEndFunction)(*this);
rv = (handler->mEndFunction)(*this);
NS_ENSURE_SUCCESS(rv, rv);
if (!--mElementContext->mDepth) {
// this will delete the old object
@ -413,7 +419,10 @@ nsresult txStylesheetCompiler::ensureNewElementContext() {
}
UniquePtr<txElementContext> context(new txElementContext(*mElementContext));
pushObject(mElementContext.release());
nsresult rv = pushObject(mElementContext.get());
NS_ENSURE_SUCCESS(rv, rv);
Unused << mElementContext.release();
mElementContext = std::move(context);
return NS_OK;
@ -502,9 +511,11 @@ nsresult txStylesheetCompilerState::init(const nsAString& aStylesheetURI,
}
mElementContext = MakeUnique<txElementContext>(aStylesheetURI);
NS_ENSURE_TRUE(mElementContext->mMappings, NS_ERROR_OUT_OF_MEMORY);
// Push the "old" txElementContext
pushObject(nullptr);
rv = pushObject(0);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
@ -513,29 +524,47 @@ txStylesheetCompilerState::~txStylesheetCompilerState() {
while (!mObjectStack.isEmpty()) {
delete popObject();
}
int32_t i;
for (i = mInScopeVariables.Length() - 1; i >= 0; --i) {
delete mInScopeVariables[i];
}
}
void txStylesheetCompilerState::pushHandlerTable(txHandlerTable* aTable) {
pushPtr(mHandlerTable, eHandlerTable);
nsresult txStylesheetCompilerState::pushHandlerTable(txHandlerTable* aTable) {
nsresult rv = pushPtr(mHandlerTable, eHandlerTable);
NS_ENSURE_SUCCESS(rv, rv);
mHandlerTable = aTable;
return NS_OK;
}
void txStylesheetCompilerState::popHandlerTable() {
mHandlerTable = static_cast<txHandlerTable*>(popPtr(eHandlerTable));
}
void txStylesheetCompilerState::pushSorter(txPushNewContext* aSorter) {
pushPtr(mSorter, ePushNewContext);
nsresult txStylesheetCompilerState::pushSorter(txPushNewContext* aSorter) {
nsresult rv = pushPtr(mSorter, ePushNewContext);
NS_ENSURE_SUCCESS(rv, rv);
mSorter = aSorter;
return NS_OK;
}
void txStylesheetCompilerState::popSorter() {
mSorter = static_cast<txPushNewContext*>(popPtr(ePushNewContext));
}
void txStylesheetCompilerState::pushChooseGotoList() {
pushObject(mChooseGotoList.release());
nsresult txStylesheetCompilerState::pushChooseGotoList() {
nsresult rv = pushObject(mChooseGotoList.get());
NS_ENSURE_SUCCESS(rv, rv);
Unused << mChooseGotoList.release();
mChooseGotoList = MakeUnique<txList>();
return NS_OK;
}
void txStylesheetCompilerState::popChooseGotoList() {
@ -543,21 +572,21 @@ void txStylesheetCompilerState::popChooseGotoList() {
mChooseGotoList = WrapUnique(static_cast<txList*>(popObject()));
}
void txStylesheetCompilerState::pushObject(txObject* aObject) {
mObjectStack.push(aObject);
nsresult txStylesheetCompilerState::pushObject(txObject* aObject) {
return mObjectStack.push(aObject);
}
txObject* txStylesheetCompilerState::popObject() {
return static_cast<txObject*>(mObjectStack.pop());
}
void txStylesheetCompilerState::pushPtr(void* aPtr, enumStackType aType) {
nsresult txStylesheetCompilerState::pushPtr(void* aPtr, enumStackType aType) {
#ifdef TX_DEBUG_STACK
MOZ_LOG(txLog::xslt, LogLevel::Debug,
("pushPtr: 0x%x type %u\n", aPtr, aType));
#endif
mTypeStack.AppendElement(aType);
mOtherStack.push(aPtr);
return mOtherStack.push(aPtr);
}
void* txStylesheetCompilerState::popPtr(enumStackType aType) {
@ -598,7 +627,7 @@ void txStylesheetCompilerState::closeInstructionContainer() {
mNextInstrPtr = 0;
}
txInstruction* txStylesheetCompilerState::addInstruction(
void txStylesheetCompilerState::addInstruction(
UniquePtr<txInstruction>&& aInstruction) {
MOZ_ASSERT(mNextInstrPtr, "adding instruction outside container");
@ -612,8 +641,6 @@ txInstruction* txStylesheetCompilerState::addInstruction(
*mGotoTargetPointers[i] = newInstr;
}
mGotoTargetPointers.Clear();
return newInstr;
}
nsresult txStylesheetCompilerState::loadIncludedStylesheet(
@ -627,6 +654,7 @@ nsresult txStylesheetCompilerState::loadIncludedStylesheet(
NS_ENSURE_TRUE(mObserver, NS_ERROR_NOT_IMPLEMENTED);
UniquePtr<txToplevelItem> item(new txDummyItem);
NS_ENSURE_TRUE(item, NS_ERROR_OUT_OF_MEMORY);
mToplevelIterator.addBefore(item.release());
@ -637,10 +665,13 @@ nsresult txStylesheetCompilerState::loadIncludedStylesheet(
RefPtr<txStylesheetCompiler> compiler = new txStylesheetCompiler(
aURI, mStylesheet, &mToplevelIterator, mReferrerPolicy, observer);
NS_ENSURE_TRUE(compiler, NS_ERROR_OUT_OF_MEMORY);
// step forward before calling the observer in case of syncronous loading
mToplevelIterator.next();
// XXX(Bug 1631371) Check if this should use a fallible operation as it
// pretended earlier.
mChildCompilerList.AppendElement(compiler);
nsresult rv =
@ -669,7 +700,10 @@ nsresult txStylesheetCompilerState::loadImportedStylesheet(
RefPtr<txStylesheetCompiler> compiler = new txStylesheetCompiler(
aURI, mStylesheet, &iter, mReferrerPolicy, observer);
NS_ENSURE_TRUE(compiler, NS_ERROR_OUT_OF_MEMORY);
// XXX(Bug 1631371) Check if this should use a fallible operation as it
// pretended earlier.
mChildCompilerList.AppendElement(compiler);
nsresult rv =
@ -681,12 +715,20 @@ nsresult txStylesheetCompilerState::loadImportedStylesheet(
return rv;
}
void txStylesheetCompilerState::addGotoTarget(txInstruction** aTargetPointer) {
nsresult txStylesheetCompilerState::addGotoTarget(
txInstruction** aTargetPointer) {
// XXX(Bug 1631371) Check if this should use a fallible operation as it
// pretended earlier, or change the return type to void.
mGotoTargetPointers.AppendElement(aTargetPointer);
return NS_OK;
}
void txStylesheetCompilerState::addVariable(const txExpandedName& aName) {
mInScopeVariables.AppendElement(aName);
nsresult txStylesheetCompilerState::addVariable(const txExpandedName& aName) {
txInScopeVariable* var = new txInScopeVariable(aName);
// XXX(Bug 1631371) Check if this should use a fallible operation as it
// pretended earlier, or change the return type to void.
mInScopeVariables.AppendElement(var);
return NS_OK;
}
nsresult txStylesheetCompilerState::resolveNamespacePrefix(nsAtom* aPrefix,

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

@ -25,6 +25,7 @@ class txNamespaceMap;
class txToplevelItem;
class txPushNewContext;
class txStylesheetCompiler;
class txInScopeVariable;
class txElementContext : public txObject {
public:
@ -62,14 +63,6 @@ class txACompileObserver {
const char16_t* aErrorText = nullptr, \
const char16_t* aParam = nullptr) override;
class txInScopeVariable {
public:
explicit txInScopeVariable(const txExpandedName& aName)
: mName(aName), mLevel(1) {}
txExpandedName mName;
int32_t mLevel;
};
class txStylesheetCompilerState : public txIParseContext {
public:
explicit txStylesheetCompilerState(txACompileObserver* aObserver);
@ -94,34 +87,29 @@ class txStylesheetCompilerState : public txIParseContext {
eCheckParam,
ePushNullTemplateRule
};
void pushHandlerTable(txHandlerTable* aTable);
nsresult pushHandlerTable(txHandlerTable* aTable);
void popHandlerTable();
void pushSorter(txPushNewContext* aSorter);
nsresult pushSorter(txPushNewContext* aSorter);
void popSorter();
void pushChooseGotoList();
nsresult pushChooseGotoList();
void popChooseGotoList();
void pushObject(txObject* aObject);
nsresult pushObject(txObject* aObject);
txObject* popObject();
void pushPtr(void* aPtr, enumStackType aType);
nsresult pushPtr(void* aPtr, enumStackType aType);
void* popPtr(enumStackType aType);
// stylesheet functions
void addToplevelItem(txToplevelItem* aItem);
nsresult openInstructionContainer(txInstructionContainer* aContainer);
void closeInstructionContainer();
txInstruction* addInstruction(
mozilla::UniquePtr<txInstruction>&& aInstruction);
template <class T>
T* addInstruction(mozilla::UniquePtr<T> aInstruction) {
return static_cast<T*>(addInstruction(std::move(aInstruction)));
}
void addInstruction(mozilla::UniquePtr<txInstruction>&& aInstruction);
nsresult loadIncludedStylesheet(const nsAString& aURI);
nsresult loadImportedStylesheet(const nsAString& aURI,
txStylesheet::ImportFrame* aFrame);
// misc
void addGotoTarget(txInstruction** aTargetPointer);
void addVariable(const txExpandedName& aName);
nsresult addGotoTarget(txInstruction** aTargetPointer);
nsresult addVariable(const txExpandedName& aName);
// txIParseContext
nsresult resolveNamespacePrefix(nsAtom* aPrefix, int32_t& aID) override;
@ -155,7 +143,7 @@ class txStylesheetCompilerState : public txIParseContext {
protected:
RefPtr<txACompileObserver> mObserver;
nsTArray<txInScopeVariable> mInScopeVariables;
nsTArray<txInScopeVariable*> mInScopeVariables;
nsTArray<txStylesheetCompiler*> mChildCompilerList;
// embed info, target information is the ID
nsString mTarget;
@ -230,4 +218,12 @@ class txStylesheetCompiler final : private txStylesheetCompilerState,
nsresult mStatus;
};
class txInScopeVariable {
public:
explicit txInScopeVariable(const txExpandedName& aName)
: mName(aName), mLevel(1) {}
txExpandedName mName;
int32_t mLevel;
};
#endif

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

@ -27,8 +27,12 @@ txStripSpaceItem::~txStripSpaceItem() {
}
}
void txStripSpaceItem::addStripSpaceTest(txStripSpaceTest* aStripSpaceTest) {
nsresult txStripSpaceItem::addStripSpaceTest(
txStripSpaceTest* aStripSpaceTest) {
// XXX(Bug 1631371) Check if this should use a fallible operation as it
// pretended earlier, or change the return type to void.
mStripSpaceTests.AppendElement(aStripSpaceTest);
return NS_OK;
}
TX_IMPL_GETTYPE(txTemplateItem, txToplevelItem::templ)

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

@ -82,7 +82,7 @@ class txStripSpaceItem : public txToplevelItem {
TX_DECL_TOPLEVELITEM
void addStripSpaceTest(txStripSpaceTest* aStripSpaceTest);
nsresult addStripSpaceTest(txStripSpaceTest* aStripSpaceTest);
nsTArray<txStripSpaceTest*> mStripSpaceTests;
};

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

@ -92,10 +92,14 @@ void txUnionPattern::toString(nsAString& aDest) {
* (dealt with by the parser)
*/
void txLocPathPattern::addStep(txPattern* aPattern, bool isChild) {
nsresult txLocPathPattern::addStep(txPattern* aPattern, bool isChild) {
Step* step = mSteps.AppendElement();
if (!step) return NS_ERROR_OUT_OF_MEMORY;
step->pattern = WrapUnique(aPattern);
step->isChild = isChild;
return NS_OK;
}
nsresult txLocPathPattern::matches(const txXPathNode& aNode,

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

@ -102,8 +102,11 @@ class txPattern {
class txUnionPattern : public txPattern {
public:
void addPattern(txPattern* aPattern) {
nsresult addPattern(txPattern* aPattern) {
// XXX(Bug 1631371) Check if this should use a fallible operation as it
// pretended earlier, or change the return type to void.
mLocPathPatterns.AppendElement(aPattern);
return NS_OK;
}
TX_DECL_PATTERN;
@ -115,7 +118,7 @@ class txUnionPattern : public txPattern {
class txLocPathPattern : public txPattern {
public:
void addStep(txPattern* aPattern, bool isChild);
nsresult addStep(txPattern* aPattern, bool isChild);
TX_DECL_PATTERN;