mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-14 02:31:59 +00:00
Bug 1029104 - Convert XPathExpression to WebIDL bindings, make XPathExpression hold a weak reference to the document. r=bz.
--HG-- rename : dom/xslt/xpath/nsXPathExpression.cpp => dom/xslt/xpath/XPathExpression.cpp extra : rebase_source : 3ab3a4babc5ec3c67f3aec3aeef422b8c3c526ef
This commit is contained in:
parent
dac9d591cd
commit
1f160b1d0d
@ -12,14 +12,6 @@
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_NATIVE_ADDREF(nsXMLBindingSet)
|
||||
NS_IMPL_CYCLE_COLLECTING_NATIVE_RELEASE(nsXMLBindingSet)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION(nsXMLBindingSet, mFirst)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsXMLBindingSet, AddRef)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsXMLBindingSet, Release)
|
||||
|
||||
nsXMLBindingSet::~nsXMLBindingSet()
|
||||
{}
|
||||
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
|
||||
class nsINode;
|
||||
@ -45,28 +44,6 @@ struct nsXMLBinding {
|
||||
}
|
||||
};
|
||||
|
||||
inline void
|
||||
ImplCycleCollectionUnlink(nsXMLBinding* aBinding)
|
||||
{
|
||||
while (aBinding) {
|
||||
aBinding->mExpr = nullptr;
|
||||
aBinding = aBinding->mNext;
|
||||
}
|
||||
}
|
||||
|
||||
inline void
|
||||
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
|
||||
nsXMLBinding* aBinding,
|
||||
const char* aName,
|
||||
uint32_t aFlags = 0)
|
||||
{
|
||||
while (aBinding) {
|
||||
CycleCollectionNoteChild(aCallback, aBinding->mExpr.get(),
|
||||
"nsXMLBinding::mExpr", aFlags);
|
||||
aBinding = aBinding->mNext;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* a collection of <binding> descriptors. This object is refcounted by
|
||||
* nsXMLBindingValues objects and the query processor.
|
||||
@ -76,20 +53,10 @@ class nsXMLBindingSet MOZ_FINAL
|
||||
~nsXMLBindingSet();
|
||||
|
||||
public:
|
||||
|
||||
// results hold a reference to a binding set in their
|
||||
// nsXMLBindingValues fields
|
||||
nsCycleCollectingAutoRefCnt mRefCnt;
|
||||
|
||||
// pointer to the first binding in a linked list
|
||||
nsAutoPtr<nsXMLBinding> mFirst;
|
||||
|
||||
public:
|
||||
|
||||
NS_METHOD_(MozExternalRefCountType) AddRef();
|
||||
NS_METHOD_(MozExternalRefCountType) Release();
|
||||
NS_DECL_OWNINGTHREAD
|
||||
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsXMLBindingSet)
|
||||
NS_INLINE_DECL_REFCOUNTING(nsXMLBindingSet);
|
||||
|
||||
/**
|
||||
* Add a binding to the set
|
||||
@ -105,6 +72,9 @@ public:
|
||||
*/
|
||||
int32_t
|
||||
LookupTargetIndex(nsIAtom* aTargetVariable, nsXMLBinding** aBinding);
|
||||
|
||||
private:
|
||||
~nsXMLBindingSet() {};
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -81,8 +81,6 @@ TraverseRuleToBindingsMap(nsISupports* aKey, nsXMLBindingSet* aMatch, void* aCon
|
||||
static_cast<nsCycleCollectionTraversalCallback*>(aContext);
|
||||
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*cb, "mRuleToBindingsMap key");
|
||||
cb->NoteXPCOMChild(aKey);
|
||||
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*cb, "mRuleToBindingsMap value");
|
||||
cb->NoteNativeChild(aMatch, NS_CYCLE_COLLECTION_PARTICIPANT(nsXMLBindingSet));
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
|
@ -51,12 +51,10 @@ private:
|
||||
nsRefPtr<txResultRecycler> mRecycler;
|
||||
};
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION(XPathExpression, mDocument)
|
||||
NS_IMPL_ADDREF(XPathExpression)
|
||||
NS_IMPL_RELEASE(XPathExpression)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(XPathExpression)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(XPathExpression)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(XPathExpression)
|
||||
NS_INTERFACE_MAP_BEGIN(XPathExpression)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMXPathExpression)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMNSXPathExpression)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMXPathExpression)
|
||||
@ -68,7 +66,8 @@ XPathExpression::XPathExpression(nsAutoPtr<Expr>&& aExpression,
|
||||
nsIDOMDocument *aDocument)
|
||||
: mExpression(Move(aExpression)),
|
||||
mRecycler(aRecycler),
|
||||
mDocument(aDocument)
|
||||
mDocument(do_GetWeakReference(aDocument)),
|
||||
mCheckDocument(aDocument != nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
@ -98,12 +97,15 @@ XPathExpression::EvaluateWithContext(nsIDOMNode *aContextNode,
|
||||
if (!nsContentUtils::CanCallerAccess(aContextNode))
|
||||
return NS_ERROR_DOM_SECURITY_ERR;
|
||||
|
||||
if (mDocument && mDocument != aContextNode) {
|
||||
nsCOMPtr<nsIDOMDocument> contextDocument;
|
||||
aContextNode->GetOwnerDocument(getter_AddRefs(contextDocument));
|
||||
if (mCheckDocument) {
|
||||
nsCOMPtr<nsIDOMDocument> doc = do_QueryReferent(mDocument);
|
||||
if (!doc || doc != aContextNode) {
|
||||
nsCOMPtr<nsIDOMDocument> contextDocument;
|
||||
aContextNode->GetOwnerDocument(getter_AddRefs(contextDocument));
|
||||
|
||||
if (mDocument != contextDocument) {
|
||||
return NS_ERROR_DOM_WRONG_DOCUMENT_ERR;
|
||||
if (doc != contextDocument) {
|
||||
return NS_ERROR_DOM_WRONG_DOCUMENT_ERR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "txResultRecycler.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsIWeakReferenceUtils.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
|
||||
class Expr;
|
||||
@ -30,9 +31,7 @@ public:
|
||||
nsIDOMDocument *aDocument);
|
||||
|
||||
// nsISupports interface
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(XPathExpression,
|
||||
nsIDOMXPathExpression)
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIDOMXPathExpression interface
|
||||
NS_DECL_NSIDOMXPATHEXPRESSION
|
||||
@ -45,7 +44,8 @@ private:
|
||||
|
||||
nsAutoPtr<Expr> mExpression;
|
||||
nsRefPtr<txResultRecycler> mRecycler;
|
||||
nsCOMPtr<nsIDOMDocument> mDocument;
|
||||
nsWeakPtr mDocument;
|
||||
bool mCheckDocument;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
Loading…
Reference in New Issue
Block a user