forked from mirrors/gecko-dev
Bug 1941002 - Make XPath tree walker hold a strong reference. r=smaug a=pascalc
Differential Revision: https://phabricator.services.mozilla.com/D237259
This commit is contained in:
parent
c876e3e97c
commit
1fa5bedc44
16 changed files with 149 additions and 224 deletions
|
|
@ -12,16 +12,15 @@
|
||||||
#include "nsNetUtil.h"
|
#include "nsNetUtil.h"
|
||||||
#include "nsIURI.h"
|
#include "nsIURI.h"
|
||||||
|
|
||||||
|
using namespace mozilla;
|
||||||
using namespace mozilla::dom;
|
using namespace mozilla::dom;
|
||||||
|
|
||||||
nsresult txParseDocumentFromURI(const nsAString& aHref,
|
Result<txXPathNode, nsresult> txParseDocumentFromURI(const nsAString& aHref,
|
||||||
const txXPathNode& aLoader, nsAString& aErrMsg,
|
const txXPathNode& aLoader,
|
||||||
txXPathNode** aResult) {
|
nsAString& aErrMsg) {
|
||||||
NS_ENSURE_ARG_POINTER(aResult);
|
|
||||||
*aResult = nullptr;
|
|
||||||
nsCOMPtr<nsIURI> documentURI;
|
nsCOMPtr<nsIURI> documentURI;
|
||||||
nsresult rv = NS_NewURI(getter_AddRefs(documentURI), aHref);
|
nsresult rv = NS_NewURI(getter_AddRefs(documentURI), aHref);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, Err(rv));
|
||||||
|
|
||||||
Document* loaderDocument = txXPathNativeNode::getDocument(aLoader);
|
Document* loaderDocument = txXPathNativeNode::getDocument(aLoader);
|
||||||
|
|
||||||
|
|
@ -32,7 +31,7 @@ nsresult txParseDocumentFromURI(const nsAString& aHref,
|
||||||
|
|
||||||
// Raw pointer, we want the resulting txXPathNode to hold a reference to
|
// Raw pointer, we want the resulting txXPathNode to hold a reference to
|
||||||
// the document.
|
// the document.
|
||||||
Document* theDocument = nullptr;
|
nsCOMPtr<Document> theDocument;
|
||||||
nsAutoSyncOperation sync(loaderDocument,
|
nsAutoSyncOperation sync(loaderDocument,
|
||||||
SyncOperationBehavior::eSuspendInput);
|
SyncOperationBehavior::eSuspendInput);
|
||||||
rv = nsSyncLoadService::LoadDocument(
|
rv = nsSyncLoadService::LoadDocument(
|
||||||
|
|
@ -40,20 +39,14 @@ nsresult txParseDocumentFromURI(const nsAString& aHref,
|
||||||
loaderDocument->NodePrincipal(),
|
loaderDocument->NodePrincipal(),
|
||||||
nsILoadInfo::SEC_REQUIRE_CORS_INHERITS_SEC_CONTEXT, loadGroup,
|
nsILoadInfo::SEC_REQUIRE_CORS_INHERITS_SEC_CONTEXT, loadGroup,
|
||||||
loaderDocument->CookieJarSettings(), true,
|
loaderDocument->CookieJarSettings(), true,
|
||||||
loaderDocument->GetReferrerPolicy(), &theDocument);
|
loaderDocument->GetReferrerPolicy(), getter_AddRefs(theDocument));
|
||||||
|
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
aErrMsg.AppendLiteral("Document load of ");
|
aErrMsg.AppendLiteral("Document load of ");
|
||||||
aErrMsg.Append(aHref);
|
aErrMsg.Append(aHref);
|
||||||
aErrMsg.AppendLiteral(" failed.");
|
aErrMsg.AppendLiteral(" failed.");
|
||||||
return NS_FAILED(rv) ? rv : NS_ERROR_FAILURE;
|
return Err(rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
*aResult = txXPathNativeNode::createXPathNode(theDocument);
|
return txXPathNode(theDocument);
|
||||||
if (!*aResult) {
|
|
||||||
NS_RELEASE(theDocument);
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,11 @@
|
||||||
|
|
||||||
class txXPathNode;
|
class txXPathNode;
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
template <typename V, typename E>
|
||||||
|
class Result;
|
||||||
|
} // namespace mozilla
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API to load XML files into DOM datastructures.
|
* API to load XML files into DOM datastructures.
|
||||||
* Parsing is either done by expat, or by expat via the syncloaderservice
|
* Parsing is either done by expat, or by expat via the syncloaderservice
|
||||||
|
|
@ -19,9 +24,7 @@ class txXPathNode;
|
||||||
* Parse a document from the aHref location, with referrer URI on behalf
|
* Parse a document from the aHref location, with referrer URI on behalf
|
||||||
* of the document aLoader.
|
* of the document aLoader.
|
||||||
*/
|
*/
|
||||||
extern "C" nsresult txParseDocumentFromURI(const nsAString& aHref,
|
mozilla::Result<txXPathNode, nsresult> txParseDocumentFromURI(
|
||||||
const txXPathNode& aLoader,
|
const nsAString& aHref, const txXPathNode& aLoader, nsAString& aErrMsg);
|
||||||
nsAString& aErrMsg,
|
|
||||||
txXPathNode** aResult);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
namespace mozilla::dom {
|
namespace mozilla::dom {
|
||||||
|
|
||||||
class EvalContextImpl : public txIEvalContext {
|
class MOZ_STACK_CLASS EvalContextImpl : public txIEvalContext {
|
||||||
public:
|
public:
|
||||||
EvalContextImpl(const txXPathNode& aContextNode, uint32_t aContextPosition,
|
EvalContextImpl(const txXPathNode& aContextNode, uint32_t aContextPosition,
|
||||||
uint32_t aContextSize, txResultRecycler* aRecycler)
|
uint32_t aContextSize, txResultRecycler* aRecycler)
|
||||||
|
|
@ -121,8 +121,8 @@ already_AddRefed<XPathResult> XPathExpression::EvaluateWithContext(
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
UniquePtr<txXPathNode> contextNode(
|
Maybe<txXPathNode> contextNode =
|
||||||
txXPathNativeNode::createXPathNode(&aContextNode));
|
txXPathNativeNode::createXPathNode(&aContextNode);
|
||||||
if (!contextNode) {
|
if (!contextNode) {
|
||||||
aRv.Throw(NS_ERROR_FAILURE);
|
aRv.Throw(NS_ERROR_FAILURE);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
||||||
|
|
@ -238,13 +238,13 @@ nsresult XPathResult::GetExprResult(txAExprResult** aExprResult) {
|
||||||
RefPtr<txNodeSet> nodeSet = new txNodeSet(nullptr);
|
RefPtr<txNodeSet> nodeSet = new txNodeSet(nullptr);
|
||||||
uint32_t i, count = mResultNodes.Length();
|
uint32_t i, count = mResultNodes.Length();
|
||||||
for (i = 0; i < count; ++i) {
|
for (i = 0; i < count; ++i) {
|
||||||
UniquePtr<txXPathNode> node(
|
Maybe<txXPathNode> node(
|
||||||
txXPathNativeNode::createXPathNode(mResultNodes[i]));
|
txXPathNativeNode::createXPathNode(mResultNodes[i]));
|
||||||
if (!node) {
|
if (!node) {
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeSet->append(*node);
|
nodeSet->append(node.extract());
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_ADDREF(*aExprResult = nodeSet);
|
NS_ADDREF(*aExprResult = nodeSet);
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
#include "txIXPathContext.h"
|
#include "txIXPathContext.h"
|
||||||
#include "txNodeSet.h"
|
#include "txNodeSet.h"
|
||||||
|
|
||||||
class txForwardContext : public txIEvalContext {
|
class MOZ_STACK_CLASS txForwardContext : public txIEvalContext {
|
||||||
public:
|
public:
|
||||||
txForwardContext(txIMatchContext* aContext, const txXPathNode& aContextNode,
|
txForwardContext(txIMatchContext* aContext, const txXPathNode& aContextNode,
|
||||||
txNodeSet* aContextNodeSet)
|
txNodeSet* aContextNodeSet)
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
using namespace mozilla;
|
||||||
using namespace mozilla::dom;
|
using namespace mozilla::dom;
|
||||||
using mozilla::Maybe;
|
|
||||||
|
|
||||||
txXPathTreeWalker::txXPathTreeWalker(const txXPathTreeWalker& aOther) = default;
|
txXPathTreeWalker::txXPathTreeWalker(const txXPathTreeWalker& aOther) = default;
|
||||||
|
|
||||||
|
|
@ -228,24 +228,6 @@ bool txXPathTreeWalker::moveToParent() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
txXPathNode::txXPathNode(const txXPathNode& aNode)
|
|
||||||
: mNode(aNode.mNode),
|
|
||||||
mRefCountRoot(aNode.mRefCountRoot),
|
|
||||||
mIndex(aNode.mIndex) {
|
|
||||||
MOZ_COUNT_CTOR(txXPathNode);
|
|
||||||
if (mRefCountRoot) {
|
|
||||||
NS_ADDREF(Root());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
txXPathNode::~txXPathNode() {
|
|
||||||
MOZ_COUNT_DTOR(txXPathNode);
|
|
||||||
if (mRefCountRoot) {
|
|
||||||
nsINode* root = Root();
|
|
||||||
NS_RELEASE(root);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
bool txXPathNodeUtils::getAttr(const txXPathNode& aNode, nsAtom* aLocalName,
|
bool txXPathNodeUtils::getAttr(const txXPathNode& aNode, nsAtom* aLocalName,
|
||||||
int32_t aNSID, nsAString& aValue) {
|
int32_t aNSID, nsAString& aValue) {
|
||||||
|
|
@ -443,8 +425,8 @@ bool txXPathNodeUtils::isWhitespace(const txXPathNode& aNode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
txXPathNode* txXPathNodeUtils::getOwnerDocument(const txXPathNode& aNode) {
|
txXPathNode txXPathNodeUtils::getOwnerDocument(const txXPathNode& aNode) {
|
||||||
return new txXPathNode(aNode.mNode->OwnerDoc());
|
return txXPathNode(aNode.mNode->OwnerDoc());
|
||||||
}
|
}
|
||||||
|
|
||||||
const char gPrintfFmt[] = "id0x%" PRIxPTR;
|
const char gPrintfFmt[] = "id0x%" PRIxPTR;
|
||||||
|
|
@ -454,7 +436,8 @@ const char gPrintfFmtAttr[] = "id0x%" PRIxPTR "-%010i";
|
||||||
nsresult txXPathNodeUtils::getXSLTId(const txXPathNode& aNode,
|
nsresult txXPathNodeUtils::getXSLTId(const txXPathNode& aNode,
|
||||||
const txXPathNode& aBase,
|
const txXPathNode& aBase,
|
||||||
nsAString& aResult) {
|
nsAString& aResult) {
|
||||||
uintptr_t nodeid = ((uintptr_t)aNode.mNode) - ((uintptr_t)aBase.mNode);
|
uintptr_t nodeid =
|
||||||
|
((uintptr_t)aNode.mNode.get()) - ((uintptr_t)aBase.mNode.get());
|
||||||
if (!aNode.isAttribute()) {
|
if (!aNode.isAttribute()) {
|
||||||
CopyASCIItoUTF16(nsPrintfCString(gPrintfFmt, nodeid), aResult);
|
CopyASCIItoUTF16(nsPrintfCString(gPrintfFmt, nodeid), aResult);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -585,16 +568,7 @@ int txXPathNodeUtils::comparePosition(const txXPathNode& aNode,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
txXPathNode* txXPathNativeNode::createXPathNode(nsIContent* aContent,
|
Maybe<txXPathNode> txXPathNativeNode::createXPathNode(nsINode* aNode) {
|
||||||
bool aKeepRootAlive) {
|
|
||||||
nsINode* root = aKeepRootAlive ? txXPathNode::RootOf(aContent) : nullptr;
|
|
||||||
|
|
||||||
return new txXPathNode(aContent, txXPathNode::eContent, root);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* static */
|
|
||||||
txXPathNode* txXPathNativeNode::createXPathNode(nsINode* aNode,
|
|
||||||
bool aKeepRootAlive) {
|
|
||||||
uint16_t nodeType = aNode->NodeType();
|
uint16_t nodeType = aNode->NodeType();
|
||||||
if (nodeType == nsINode::ATTRIBUTE_NODE) {
|
if (nodeType == nsINode::ATTRIBUTE_NODE) {
|
||||||
auto* attr = static_cast<Attr*>(aNode);
|
auto* attr = static_cast<Attr*>(aNode);
|
||||||
|
|
@ -602,42 +576,30 @@ txXPathNode* txXPathNativeNode::createXPathNode(nsINode* aNode,
|
||||||
NodeInfo* nodeInfo = attr->NodeInfo();
|
NodeInfo* nodeInfo = attr->NodeInfo();
|
||||||
Element* parent = attr->GetElement();
|
Element* parent = attr->GetElement();
|
||||||
if (!parent) {
|
if (!parent) {
|
||||||
return nullptr;
|
return Nothing();
|
||||||
}
|
}
|
||||||
|
|
||||||
nsINode* root = aKeepRootAlive ? txXPathNode::RootOf(parent) : nullptr;
|
|
||||||
|
|
||||||
uint32_t i, total = parent->GetAttrCount();
|
uint32_t i, total = parent->GetAttrCount();
|
||||||
for (i = 0; i < total; ++i) {
|
for (i = 0; i < total; ++i) {
|
||||||
const nsAttrName* name = parent->GetAttrNameAt(i);
|
const nsAttrName* name = parent->GetAttrNameAt(i);
|
||||||
if (nodeInfo->Equals(name->LocalName(), name->NamespaceID())) {
|
if (nodeInfo->Equals(name->LocalName(), name->NamespaceID())) {
|
||||||
return new txXPathNode(parent, i, root);
|
return Some(txXPathNode(parent, i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_ERROR("Couldn't find the attribute in its parent!");
|
NS_ERROR("Couldn't find the attribute in its parent!");
|
||||||
|
|
||||||
return nullptr;
|
return Nothing();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t index;
|
uint32_t index;
|
||||||
nsINode* root = aKeepRootAlive ? aNode : nullptr;
|
|
||||||
|
|
||||||
if (nodeType == nsINode::DOCUMENT_NODE) {
|
if (nodeType == nsINode::DOCUMENT_NODE) {
|
||||||
index = txXPathNode::eDocument;
|
index = txXPathNode::eDocument;
|
||||||
} else {
|
} else {
|
||||||
index = txXPathNode::eContent;
|
index = txXPathNode::eContent;
|
||||||
if (root) {
|
|
||||||
root = txXPathNode::RootOf(root);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new txXPathNode(aNode, index, root);
|
return Some(txXPathNode(aNode, index));
|
||||||
}
|
|
||||||
|
|
||||||
/* static */
|
|
||||||
txXPathNode* txXPathNativeNode::createXPathNode(Document* aDocument) {
|
|
||||||
return new txXPathNode(aDocument);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
|
|
|
||||||
|
|
@ -82,12 +82,12 @@ txNodeSet::~txNodeSet() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult txNodeSet::add(const txXPathNode& aNode) {
|
nsresult txNodeSet::add(txXPathNode&& aNode) {
|
||||||
NS_ASSERTION(mDirection == kForward,
|
NS_ASSERTION(mDirection == kForward,
|
||||||
"only append(aNode) is supported on reversed nodesets");
|
"only append(aNode) is supported on reversed nodesets");
|
||||||
|
|
||||||
if (isEmpty()) {
|
if (isEmpty()) {
|
||||||
return append(aNode);
|
return append(std::move(aNode));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dupe;
|
bool dupe;
|
||||||
|
|
@ -111,7 +111,7 @@ nsresult txNodeSet::add(const txXPathNode& aNode) {
|
||||||
memmove(pos + 1, pos, moveSize * sizeof(txXPathNode));
|
memmove(pos + 1, pos, moveSize * sizeof(txXPathNode));
|
||||||
}
|
}
|
||||||
|
|
||||||
new (pos) txXPathNode(aNode);
|
new (pos) txXPathNode(std::move(aNode));
|
||||||
++mEnd;
|
++mEnd;
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|
@ -293,19 +293,19 @@ nsresult txNodeSet::add(const txNodeSet& aNodes, transferOp aTransfer,
|
||||||
* order info operations will be performed.
|
* order info operations will be performed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
nsresult txNodeSet::append(const txXPathNode& aNode) {
|
nsresult txNodeSet::append(txXPathNode&& aNode) {
|
||||||
if (!ensureGrowSize(1)) {
|
if (!ensureGrowSize(1)) {
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mDirection == kForward) {
|
if (mDirection == kForward) {
|
||||||
new (mEnd) txXPathNode(aNode);
|
new (mEnd) txXPathNode(std::move(aNode));
|
||||||
++mEnd;
|
++mEnd;
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
new (--mStart) txXPathNode(aNode);
|
new (--mStart) txXPathNode(std::move(aNode));
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,8 @@ class txNodeSet : public txAExprResult {
|
||||||
* @param aNode the txXPathNode to add to the NodeSet
|
* @param aNode the txXPathNode to add to the NodeSet
|
||||||
* @return errorcode.
|
* @return errorcode.
|
||||||
*/
|
*/
|
||||||
nsresult add(const txXPathNode& aNode);
|
nsresult add(const txXPathNode& aNode) { return add(txXPathNode(aNode)); }
|
||||||
|
nsresult add(txXPathNode&& aNode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the nodes in specified NodeSet to this NodeSet. The resulting
|
* Adds the nodes in specified NodeSet to this NodeSet. The resulting
|
||||||
|
|
@ -72,7 +73,10 @@ class txNodeSet : public txAExprResult {
|
||||||
* @param aNode the Node to append to the NodeSet
|
* @param aNode the Node to append to the NodeSet
|
||||||
* @return errorcode.
|
* @return errorcode.
|
||||||
*/
|
*/
|
||||||
nsresult append(const txXPathNode& aNode);
|
nsresult append(const txXPathNode& aNode) {
|
||||||
|
return append(txXPathNode(aNode));
|
||||||
|
}
|
||||||
|
nsresult append(txXPathNode&& aNode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Appends the nodes in the specified NodeSet to the end of this NodeSet
|
* Appends the nodes in the specified NodeSet to the end of this NodeSet
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include "mozilla/Attributes.h"
|
#include "mozilla/Attributes.h"
|
||||||
#include "txIXPathContext.h"
|
#include "txIXPathContext.h"
|
||||||
|
#include "txXPathNode.h"
|
||||||
|
|
||||||
class txSingleNodeContext : public txIEvalContext {
|
class txSingleNodeContext : public txIEvalContext {
|
||||||
public:
|
public:
|
||||||
|
|
@ -57,7 +58,7 @@ class txSingleNodeContext : public txIEvalContext {
|
||||||
uint32_t position() override { return 1; }
|
uint32_t position() override { return 1; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const txXPathNode& mNode;
|
txXPathNode mNode;
|
||||||
txIMatchContext* mInner;
|
txIMatchContext* mInner;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,35 +13,70 @@
|
||||||
|
|
||||||
using txXPathNodeType = nsINode;
|
using txXPathNodeType = nsINode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* txXPathNode represents a node in XPath's data model (which is a bit different
|
||||||
|
* from the DOM's). While XPath 1.0 has 7 node types, we essentially deal with 3
|
||||||
|
* kinds: a document node, any other node type that is backed by an
|
||||||
|
* implementation of nsIContent in Gecko, and attribute nodes. Because we try to
|
||||||
|
* avoid creating actual node objects for attribute nodes in Gecko's DOM, we
|
||||||
|
* store attribute nodes as a pointer to their owner element and an index into
|
||||||
|
* that element's attribute node list. So to represent the 3 kinds of node we
|
||||||
|
* need to store:
|
||||||
|
*
|
||||||
|
* - a pointer to a document (a nsIDocument as a nsINode pointer)
|
||||||
|
* - a pointer to a nsIContent object (as a nsINode pointer)
|
||||||
|
* - a pointer to a nsIContent object (a nsIContent as a nsINode pointer) and
|
||||||
|
* an index
|
||||||
|
*
|
||||||
|
* So we make txXPathNode store a |nsCOMPtr<nsINode>| and a uint32_t for the
|
||||||
|
* index. To be able to distinguish between the attribute nodes and other nodes
|
||||||
|
* we store a flag value for the other nodes in the index. To be able to quickly
|
||||||
|
* cast from the nsINode pointer to a nsIDocument or nsIContent pointer we
|
||||||
|
* actually use 2 different flag values (see txXPathNode::PositionType).
|
||||||
|
*
|
||||||
|
* We provide 2 fast constructors for txXPathNode, one that takes a nsIContent
|
||||||
|
* and one that takes a nsIDocument, since for those kinds of nodes we can
|
||||||
|
* simply store the pointer and the relevant flag value. For attribute nodes, or
|
||||||
|
* if you have just a nsINode pointer, then there is a helper function
|
||||||
|
* (txXPathNativeNode::createXPathNode) that either picks the right flag value
|
||||||
|
* or the correct index (for attribute nodes) when creating the txXPathNode.
|
||||||
|
*/
|
||||||
class txXPathNode {
|
class txXPathNode {
|
||||||
public:
|
public:
|
||||||
|
explicit txXPathNode(const txXPathNode& aNode)
|
||||||
|
: mNode(aNode.mNode), mIndex(aNode.mIndex) {
|
||||||
|
MOZ_COUNT_CTOR(txXPathNode);
|
||||||
|
}
|
||||||
|
txXPathNode(txXPathNode&& aNode)
|
||||||
|
: mNode(std::move(aNode.mNode)), mIndex(aNode.mIndex) {
|
||||||
|
MOZ_COUNT_CTOR(txXPathNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit txXPathNode(mozilla::dom::Document* aDocument)
|
||||||
|
: mNode(aDocument), mIndex(eDocument) {
|
||||||
|
MOZ_COUNT_CTOR(txXPathNode);
|
||||||
|
}
|
||||||
|
explicit txXPathNode(nsIContent* aContent)
|
||||||
|
: mNode(aContent), mIndex(eContent) {
|
||||||
|
MOZ_COUNT_CTOR(txXPathNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
txXPathNode& operator=(txXPathNode&& aOther) = default;
|
||||||
bool operator==(const txXPathNode& aNode) const;
|
bool operator==(const txXPathNode& aNode) const;
|
||||||
bool operator!=(const txXPathNode& aNode) const { return !(*this == aNode); }
|
bool operator!=(const txXPathNode& aNode) const { return !(*this == aNode); }
|
||||||
~txXPathNode();
|
~txXPathNode() { MOZ_COUNT_DTOR(txXPathNode); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class txNodeSet;
|
|
||||||
friend class txXPathNativeNode;
|
friend class txXPathNativeNode;
|
||||||
friend class txXPathNodeUtils;
|
friend class txXPathNodeUtils;
|
||||||
friend class txXPathTreeWalker;
|
friend class txXPathTreeWalker;
|
||||||
|
|
||||||
txXPathNode(const txXPathNode& aNode);
|
txXPathNode(nsINode* aNode, uint32_t aIndex) : mNode(aNode), mIndex(aIndex) {
|
||||||
|
|
||||||
explicit txXPathNode(mozilla::dom::Document* aDocument)
|
|
||||||
: mNode(aDocument), mRefCountRoot(0), mIndex(eDocument) {
|
|
||||||
MOZ_COUNT_CTOR(txXPathNode);
|
MOZ_COUNT_CTOR(txXPathNode);
|
||||||
}
|
}
|
||||||
txXPathNode(nsINode* aNode, uint32_t aIndex, nsINode* aRoot)
|
|
||||||
: mNode(aNode), mRefCountRoot(aRoot ? 1 : 0), mIndex(aIndex) {
|
|
||||||
MOZ_COUNT_CTOR(txXPathNode);
|
|
||||||
if (aRoot) {
|
|
||||||
NS_ADDREF(aRoot);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static nsINode* RootOf(nsINode* aNode) { return aNode->SubtreeRoot(); }
|
static nsINode* RootOf(nsINode* aNode) { return aNode->SubtreeRoot(); }
|
||||||
nsINode* Root() const { return RootOf(mNode); }
|
nsINode* Root() const { return RootOf(mNode); }
|
||||||
nsINode* GetRootToAddRef() const { return mRefCountRoot ? Root() : nullptr; }
|
|
||||||
|
|
||||||
bool isDocument() const { return mIndex == eDocument; }
|
bool isDocument() const { return mIndex == eDocument; }
|
||||||
bool isContent() const { return mIndex == eContent; }
|
bool isContent() const { return mIndex == eContent; }
|
||||||
|
|
@ -49,18 +84,20 @@ class txXPathNode {
|
||||||
|
|
||||||
nsIContent* Content() const {
|
nsIContent* Content() const {
|
||||||
NS_ASSERTION(isContent() || isAttribute(), "wrong type");
|
NS_ASSERTION(isContent() || isAttribute(), "wrong type");
|
||||||
return static_cast<nsIContent*>(mNode);
|
return static_cast<nsIContent*>(mNode.get());
|
||||||
}
|
}
|
||||||
mozilla::dom::Document* Document() const {
|
mozilla::dom::Document* Document() const {
|
||||||
NS_ASSERTION(isDocument(), "wrong type");
|
NS_ASSERTION(isDocument(), "wrong type");
|
||||||
return static_cast<mozilla::dom::Document*>(mNode);
|
return static_cast<mozilla::dom::Document*>(mNode.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
enum PositionType { eDocument = (1 << 30), eContent = eDocument - 1 };
|
enum PositionType : uint32_t {
|
||||||
|
eDocument = UINT32_MAX,
|
||||||
|
eContent = eDocument - 1
|
||||||
|
};
|
||||||
|
|
||||||
nsINode* mNode;
|
nsCOMPtr<nsINode> mNode;
|
||||||
uint32_t mRefCountRoot : 1;
|
uint32_t mIndex;
|
||||||
uint32_t mIndex : 31;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class txNamespaceManager {
|
class txNamespaceManager {
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ class txXPathNodeUtils {
|
||||||
static uint16_t getNodeType(const txXPathNode& aNode);
|
static uint16_t getNodeType(const txXPathNode& aNode);
|
||||||
static void appendNodeValue(const txXPathNode& aNode, nsAString& aResult);
|
static void appendNodeValue(const txXPathNode& aNode, nsAString& aResult);
|
||||||
static bool isWhitespace(const txXPathNode& aNode);
|
static bool isWhitespace(const txXPathNode& aNode);
|
||||||
static txXPathNode* getOwnerDocument(const txXPathNode& aNode);
|
static txXPathNode getOwnerDocument(const txXPathNode& aNode);
|
||||||
static int32_t getUniqueIdentifier(const txXPathNode& aNode);
|
static int32_t getUniqueIdentifier(const txXPathNode& aNode);
|
||||||
static nsresult getXSLTId(const txXPathNode& aNode, const txXPathNode& aBase,
|
static nsresult getXSLTId(const txXPathNode& aNode, const txXPathNode& aBase,
|
||||||
nsAString& aResult);
|
nsAString& aResult);
|
||||||
|
|
@ -86,19 +86,10 @@ class txXPathNodeUtils {
|
||||||
|
|
||||||
class txXPathNativeNode {
|
class txXPathNativeNode {
|
||||||
public:
|
public:
|
||||||
static txXPathNode* createXPathNode(nsINode* aNode,
|
static mozilla::Maybe<txXPathNode> createXPathNode(nsINode* aNode);
|
||||||
bool aKeepRootAlive = false);
|
|
||||||
static txXPathNode* createXPathNode(nsIContent* aContent,
|
|
||||||
bool aKeepRootAlive = false);
|
|
||||||
static txXPathNode* createXPathNode(mozilla::dom::Document* aDocument);
|
|
||||||
static nsINode* getNode(const txXPathNode& aNode);
|
static nsINode* getNode(const txXPathNode& aNode);
|
||||||
static nsIContent* getContent(const txXPathNode& aNode);
|
static nsIContent* getContent(const txXPathNode& aNode);
|
||||||
static mozilla::dom::Document* getDocument(const txXPathNode& aNode);
|
static mozilla::dom::Document* getDocument(const txXPathNode& aNode);
|
||||||
static void addRef(const txXPathNode& aNode) { NS_ADDREF(aNode.mNode); }
|
|
||||||
static void release(const txXPathNode& aNode) {
|
|
||||||
nsINode* node = aNode.mNode;
|
|
||||||
NS_RELEASE(node);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline const txXPathNode& txXPathTreeWalker::getCurrentPosition() const {
|
inline const txXPathNode& txXPathTreeWalker::getCurrentPosition() const {
|
||||||
|
|
@ -123,21 +114,8 @@ inline void txXPathTreeWalker::getNodeName(nsAString& aName) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void txXPathTreeWalker::moveTo(const txXPathTreeWalker& aWalker) {
|
inline void txXPathTreeWalker::moveTo(const txXPathTreeWalker& aWalker) {
|
||||||
nsINode* root = nullptr;
|
|
||||||
if (mPosition.mRefCountRoot) {
|
|
||||||
root = mPosition.Root();
|
|
||||||
}
|
|
||||||
mPosition.mIndex = aWalker.mPosition.mIndex;
|
mPosition.mIndex = aWalker.mPosition.mIndex;
|
||||||
mPosition.mRefCountRoot = aWalker.mPosition.mRefCountRoot;
|
|
||||||
mPosition.mNode = aWalker.mPosition.mNode;
|
mPosition.mNode = aWalker.mPosition.mNode;
|
||||||
nsINode* newRoot = nullptr;
|
|
||||||
if (mPosition.mRefCountRoot) {
|
|
||||||
newRoot = mPosition.Root();
|
|
||||||
}
|
|
||||||
if (root != newRoot) {
|
|
||||||
NS_IF_ADDREF(newRoot);
|
|
||||||
NS_IF_RELEASE(root);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool txXPathTreeWalker::isOnNode(const txXPathNode& aNode) const {
|
inline bool txXPathTreeWalker::isOnNode(const txXPathNode& aNode) const {
|
||||||
|
|
@ -147,12 +125,7 @@ inline bool txXPathTreeWalker::isOnNode(const txXPathNode& aNode) const {
|
||||||
/* static */
|
/* static */
|
||||||
inline int32_t txXPathNodeUtils::getUniqueIdentifier(const txXPathNode& aNode) {
|
inline int32_t txXPathNodeUtils::getUniqueIdentifier(const txXPathNode& aNode) {
|
||||||
MOZ_ASSERT(!aNode.isAttribute(), "Not implemented for attributes.");
|
MOZ_ASSERT(!aNode.isAttribute(), "Not implemented for attributes.");
|
||||||
return NS_PTR_TO_INT32(aNode.mNode);
|
return NS_PTR_TO_INT32(aNode.mNode.get());
|
||||||
}
|
|
||||||
|
|
||||||
/* static */
|
|
||||||
inline void txXPathNodeUtils::release(txXPathNode* aNode) {
|
|
||||||
NS_RELEASE(aNode->mNode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
|
|
|
||||||
|
|
@ -73,11 +73,7 @@ static nsresult convertRtfToNode(txIEvalContext* aContext,
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
// The txResultTreeFragment will own this.
|
// The txResultTreeFragment will own this.
|
||||||
const txXPathNode* node =
|
aRtf->setNode(new txXPathNode(domFragment));
|
||||||
txXPathNativeNode::createXPathNode(domFragment, true);
|
|
||||||
NS_ENSURE_TRUE(node, NS_ERROR_OUT_OF_MEMORY);
|
|
||||||
|
|
||||||
aRtf->setNode(node);
|
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
@ -95,8 +91,7 @@ static nsresult createTextNode(txIEvalContext* aContext, nsString& aValue,
|
||||||
nsresult rv = text->SetText(aValue, false);
|
nsresult rv = text->SetText(aValue, false);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
*aResult = txXPathNativeNode::createXPathNode(text, true);
|
*aResult = new txXPathNode(text);
|
||||||
NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY);
|
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
@ -126,11 +121,10 @@ static nsresult createAndAddToResult(nsAtom* aName, const nsAString& aValue,
|
||||||
return error.StealNSResult();
|
return error.StealNSResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
UniquePtr<txXPathNode> xpathNode(
|
Maybe<txXPathNode> xpathNode(txXPathNativeNode::createXPathNode(elem));
|
||||||
txXPathNativeNode::createXPathNode(elem, true));
|
|
||||||
NS_ENSURE_TRUE(xpathNode, NS_ERROR_OUT_OF_MEMORY);
|
NS_ENSURE_TRUE(xpathNode, NS_ERROR_OUT_OF_MEMORY);
|
||||||
|
|
||||||
aResultSet->append(*xpathNode);
|
aResultSet->append(xpathNode.extract());
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
@ -705,8 +699,7 @@ nsresult txEXSLTRegExFunctionCall::evaluate(txIEvalContext* aContext,
|
||||||
UniquePtr<txXPathNode> node;
|
UniquePtr<txXPathNode> node;
|
||||||
for (nsIContent* result = docFrag->GetFirstChild(); result;
|
for (nsIContent* result = docFrag->GetFirstChild(); result;
|
||||||
result = result->GetNextSibling()) {
|
result = result->GetNextSibling()) {
|
||||||
node = WrapUnique(txXPathNativeNode::createXPathNode(result, true));
|
rv = resultSet->add(txXPathNode(result));
|
||||||
rv = resultSet->add(*node);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,14 +14,12 @@
|
||||||
#include "txURIUtils.h"
|
#include "txURIUtils.h"
|
||||||
#include "txXMLParser.h"
|
#include "txXMLParser.h"
|
||||||
|
|
||||||
using mozilla::UniquePtr;
|
using namespace mozilla;
|
||||||
using mozilla::Unused;
|
|
||||||
using mozilla::WrapUnique;
|
|
||||||
|
|
||||||
const int32_t txExecutionState::kMaxRecursionDepth = 20000;
|
const int32_t txExecutionState::kMaxRecursionDepth = 20000;
|
||||||
|
|
||||||
nsresult txLoadedDocumentsHash::init(const txXPathNode& aSource) {
|
nsresult txLoadedDocumentsHash::init(const txXPathNode& aSource) {
|
||||||
mSourceDocument = WrapUnique(txXPathNodeUtils::getOwnerDocument(aSource));
|
mSourceDocument = Some(txXPathNodeUtils::getOwnerDocument(aSource));
|
||||||
|
|
||||||
nsAutoString baseURI;
|
nsAutoString baseURI;
|
||||||
nsresult rv = txXPathNodeUtils::getBaseURI(*mSourceDocument, baseURI);
|
nsresult rv = txXPathNodeUtils::getBaseURI(*mSourceDocument, baseURI);
|
||||||
|
|
@ -39,24 +37,12 @@ nsresult txLoadedDocumentsHash::init(const txXPathNode& aSource) {
|
||||||
// txMozillaXSLTProcessor::TransformToFragment) it makes more sense to return
|
// txMozillaXSLTProcessor::TransformToFragment) it makes more sense to return
|
||||||
// the real root of the source tree, which is the node where the transform
|
// the real root of the source tree, which is the node where the transform
|
||||||
// started.
|
// started.
|
||||||
PutEntry(baseURI)->mDocument = WrapUnique(
|
WithEntryHandle(baseURI, [&aSource](auto&& entry) {
|
||||||
txXPathNativeNode::createXPathNode(txXPathNativeNode::getNode(aSource)));
|
entry.Insert(txLoadedDocumentEntry{txXPathNode(aSource)});
|
||||||
|
});
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
txLoadedDocumentsHash::~txLoadedDocumentsHash() {
|
|
||||||
if (mSourceDocument) {
|
|
||||||
nsAutoString baseURI;
|
|
||||||
nsresult rv = txXPathNodeUtils::getBaseURI(*mSourceDocument, baseURI);
|
|
||||||
if (NS_SUCCEEDED(rv)) {
|
|
||||||
txLoadedDocumentEntry* entry = GetEntry(baseURI);
|
|
||||||
if (entry) {
|
|
||||||
delete entry->mDocument.release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
txExecutionState::txExecutionState(txStylesheet* aStylesheet,
|
txExecutionState::txExecutionState(txStylesheet* aStylesheet,
|
||||||
bool aDisableLoads)
|
bool aDisableLoads)
|
||||||
: mOutputHandler(nullptr),
|
: mOutputHandler(nullptr),
|
||||||
|
|
@ -358,27 +344,24 @@ const txXPathNode* txExecutionState::retrieveDocument(const nsAString& aUri) {
|
||||||
("Retrieve Document %s", NS_LossyConvertUTF16toASCII(aUri).get()));
|
("Retrieve Document %s", NS_LossyConvertUTF16toASCII(aUri).get()));
|
||||||
|
|
||||||
// try to get already loaded document
|
// try to get already loaded document
|
||||||
txLoadedDocumentEntry* entry = mLoadedDocuments.PutEntry(aUri);
|
const Variant<txXPathNode, nsresult>& result =
|
||||||
if (!entry) {
|
mLoadedDocuments.LookupOrInsertWith(aUri, [&] {
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!entry->mDocument && !entry->LoadingFailed()) {
|
|
||||||
// open URI
|
// open URI
|
||||||
nsAutoString errMsg;
|
nsAutoString errMsg;
|
||||||
// XXX we should get the loader from the actual node
|
// XXX we should get the loader from the actual node
|
||||||
// triggering the load, but this will do for the time being
|
// triggering the load, but this will do for the time being
|
||||||
entry->mLoadResult =
|
Result<txXPathNode, nsresult> loadResult = txParseDocumentFromURI(
|
||||||
txParseDocumentFromURI(aUri, *mLoadedDocuments.mSourceDocument, errMsg,
|
aUri, *mLoadedDocuments.mSourceDocument, errMsg);
|
||||||
getter_Transfers(entry->mDocument));
|
|
||||||
|
|
||||||
if (entry->LoadingFailed()) {
|
if (loadResult.isErr()) {
|
||||||
receiveError(u"Couldn't load document '"_ns + aUri + u"': "_ns + errMsg,
|
nsresult rv = loadResult.unwrapErr();
|
||||||
entry->mLoadResult);
|
receiveError(
|
||||||
|
u"Couldn't load document '"_ns + aUri + u"': "_ns + errMsg, rv);
|
||||||
|
return txLoadedDocumentEntry(rv);
|
||||||
}
|
}
|
||||||
}
|
return txLoadedDocumentEntry(loadResult.unwrap());
|
||||||
|
});
|
||||||
return entry->mDocument.get();
|
return result.is<txXPathNode>() ? &result.as<txXPathNode>() : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult txExecutionState::getKeyNodes(const txExpandedName& aKeyName,
|
nsresult txExecutionState::getKeyNodes(const txExpandedName& aKeyName,
|
||||||
|
|
|
||||||
|
|
@ -23,41 +23,18 @@ class txAOutputHandlerFactory;
|
||||||
class txAXMLEventHandler;
|
class txAXMLEventHandler;
|
||||||
class txInstruction;
|
class txInstruction;
|
||||||
|
|
||||||
class txLoadedDocumentEntry : public nsStringHashKey {
|
using txLoadedDocumentEntry = mozilla::Variant<txXPathNode, nsresult>;
|
||||||
|
|
||||||
|
class txLoadedDocumentsHash
|
||||||
|
: public nsTHashMap<nsString, txLoadedDocumentEntry> {
|
||||||
public:
|
public:
|
||||||
explicit txLoadedDocumentEntry(KeyTypePointer aStr)
|
txLoadedDocumentsHash() : nsTHashMap<nsString, txLoadedDocumentEntry>(4) {}
|
||||||
: nsStringHashKey(aStr), mLoadResult(NS_OK) {}
|
|
||||||
txLoadedDocumentEntry(txLoadedDocumentEntry&& aOther)
|
|
||||||
: nsStringHashKey(std::move(aOther)),
|
|
||||||
mDocument(std::move(aOther.mDocument)),
|
|
||||||
mLoadResult(std::move(aOther.mLoadResult)) {
|
|
||||||
NS_ERROR("We're horked.");
|
|
||||||
}
|
|
||||||
~txLoadedDocumentEntry() {
|
|
||||||
if (mDocument) {
|
|
||||||
txXPathNodeUtils::release(mDocument.get());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bool LoadingFailed() {
|
|
||||||
NS_ASSERTION(NS_SUCCEEDED(mLoadResult) || !mDocument,
|
|
||||||
"Load failed but we still got a document?");
|
|
||||||
|
|
||||||
return NS_FAILED(mLoadResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
mozilla::UniquePtr<txXPathNode> mDocument;
|
|
||||||
nsresult mLoadResult;
|
|
||||||
};
|
|
||||||
|
|
||||||
class txLoadedDocumentsHash : public nsTHashtable<txLoadedDocumentEntry> {
|
|
||||||
public:
|
|
||||||
txLoadedDocumentsHash() : nsTHashtable<txLoadedDocumentEntry>(4) {}
|
|
||||||
~txLoadedDocumentsHash();
|
|
||||||
[[nodiscard]] nsresult init(const txXPathNode& aSource);
|
[[nodiscard]] nsresult init(const txXPathNode& aSource);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class txExecutionState;
|
friend class txExecutionState;
|
||||||
mozilla::UniquePtr<txXPathNode> mSourceDocument;
|
mozilla::Maybe<txXPathNode> mSourceDocument;
|
||||||
};
|
};
|
||||||
|
|
||||||
class txExecutionState : public txIMatchContext {
|
class txExecutionState : public txIMatchContext {
|
||||||
|
|
|
||||||
|
|
@ -326,7 +326,8 @@ txMozillaXSLTProcessor::AddXSLTParamNamespace(const nsString& aPrefix,
|
||||||
return mParamNamespaceMap.mapNamespace(pre, aNamespace);
|
return mParamNamespaceMap.mapNamespace(pre, aNamespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
class txXSLTParamContext : public txIParseContext, public txIEvalContext {
|
class MOZ_STACK_CLASS txXSLTParamContext : public txIParseContext,
|
||||||
|
public txIEvalContext {
|
||||||
public:
|
public:
|
||||||
txXSLTParamContext(txNamespaceMap* aResolver, const txXPathNode& aContext,
|
txXSLTParamContext(txNamespaceMap* aResolver, const txXPathNode& aContext,
|
||||||
txResultRecycler* aRecycler)
|
txResultRecycler* aRecycler)
|
||||||
|
|
@ -385,7 +386,7 @@ txMozillaXSLTProcessor::AddXSLTParam(const nsString& aName,
|
||||||
uint16_t resultType;
|
uint16_t resultType;
|
||||||
if (!aSelect.IsVoid()) {
|
if (!aSelect.IsVoid()) {
|
||||||
// Set up context
|
// Set up context
|
||||||
UniquePtr<txXPathNode> contextNode(
|
Maybe<txXPathNode> contextNode(
|
||||||
txXPathNativeNode::createXPathNode(aContext));
|
txXPathNativeNode::createXPathNode(aContext));
|
||||||
NS_ENSURE_TRUE(contextNode, NS_ERROR_OUT_OF_MEMORY);
|
NS_ENSURE_TRUE(contextNode, NS_ERROR_OUT_OF_MEMORY);
|
||||||
|
|
||||||
|
|
@ -655,8 +656,7 @@ XSLTProcessRequest::SetTRRMode(nsIRequest::TRRMode aTRRMode) {
|
||||||
|
|
||||||
nsresult txMozillaXSLTProcessor::TransformToDoc(Document** aResult,
|
nsresult txMozillaXSLTProcessor::TransformToDoc(Document** aResult,
|
||||||
bool aCreateDataDocument) {
|
bool aCreateDataDocument) {
|
||||||
UniquePtr<txXPathNode> sourceNode(
|
Maybe<txXPathNode> sourceNode(txXPathNativeNode::createXPathNode(mSource));
|
||||||
txXPathNativeNode::createXPathNode(mSource));
|
|
||||||
if (!sourceNode) {
|
if (!sourceNode) {
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
@ -754,7 +754,7 @@ already_AddRefed<DocumentFragment> txMozillaXSLTProcessor::TransformToFragment(
|
||||||
source = &aSource;
|
source = &aSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
UniquePtr<txXPathNode> sourceNode(txXPathNativeNode::createXPathNode(source));
|
Maybe<txXPathNode> sourceNode(txXPathNativeNode::createXPathNode(source));
|
||||||
if (!sourceNode) {
|
if (!sourceNode) {
|
||||||
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
@ -1185,7 +1185,7 @@ nsresult txVariable::convert(const OwningXSLTParameterValue& aUnionValue,
|
||||||
|
|
||||||
if (aUnionValue.IsNode()) {
|
if (aUnionValue.IsNode()) {
|
||||||
nsINode& node = aUnionValue.GetAsNode();
|
nsINode& node = aUnionValue.GetAsNode();
|
||||||
UniquePtr<txXPathNode> xpathNode(txXPathNativeNode::createXPathNode(&node));
|
Maybe<txXPathNode> xpathNode(txXPathNativeNode::createXPathNode(&node));
|
||||||
if (!xpathNode) {
|
if (!xpathNode) {
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
@ -1199,13 +1199,13 @@ nsresult txVariable::convert(const OwningXSLTParameterValue& aUnionValue,
|
||||||
const Sequence<OwningNonNull<nsINode>>& values =
|
const Sequence<OwningNonNull<nsINode>>& values =
|
||||||
aUnionValue.GetAsNodeSequence();
|
aUnionValue.GetAsNodeSequence();
|
||||||
for (const auto& node : values) {
|
for (const auto& node : values) {
|
||||||
UniquePtr<txXPathNode> xpathNode(
|
Maybe<txXPathNode> xpathNode(
|
||||||
txXPathNativeNode::createXPathNode(node.get()));
|
txXPathNativeNode::createXPathNode(node.get()));
|
||||||
if (!xpathNode) {
|
if (!xpathNode) {
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeSet->append(*xpathNode);
|
nodeSet->append(xpathNode.extract());
|
||||||
}
|
}
|
||||||
nodeSet.forget(aValue);
|
nodeSet.forget(aValue);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|
|
||||||
|
|
@ -329,12 +329,11 @@ void txIdPattern::toString(nsAString& aDest) {
|
||||||
nsresult txKeyPattern::matches(const txXPathNode& aNode,
|
nsresult txKeyPattern::matches(const txXPathNode& aNode,
|
||||||
txIMatchContext* aContext, bool& aMatched) {
|
txIMatchContext* aContext, bool& aMatched) {
|
||||||
txExecutionState* es = (txExecutionState*)aContext->getPrivateContext();
|
txExecutionState* es = (txExecutionState*)aContext->getPrivateContext();
|
||||||
UniquePtr<txXPathNode> contextDoc(txXPathNodeUtils::getOwnerDocument(aNode));
|
txXPathNode contextDoc(txXPathNodeUtils::getOwnerDocument(aNode));
|
||||||
NS_ENSURE_TRUE(contextDoc, NS_ERROR_FAILURE);
|
|
||||||
|
|
||||||
RefPtr<txNodeSet> nodes;
|
RefPtr<txNodeSet> nodes;
|
||||||
nsresult rv =
|
nsresult rv =
|
||||||
es->getKeyNodes(mName, *contextDoc, mValue, true, getter_AddRefs(nodes));
|
es->getKeyNodes(mName, contextDoc, mValue, true, getter_AddRefs(nodes));
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
aMatched = nodes->contains(aNode);
|
aMatched = nodes->contains(aNode);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue