2005-11-02 10:35:22 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2005-11-02 10:35:22 +03:00
|
|
|
|
2013-07-04 19:39:28 +04:00
|
|
|
#include "XPathResult.h"
|
2005-11-02 20:34:14 +03:00
|
|
|
#include "txExprResult.h"
|
2005-11-02 10:41:38 +03:00
|
|
|
#include "txNodeSet.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2014-04-10 20:09:50 +04:00
|
|
|
#include "mozilla/dom/Attr.h"
|
2010-08-24 11:05:56 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2011-10-03 23:11:31 +04:00
|
|
|
#include "nsDOMClassInfoID.h"
|
2005-11-02 10:38:20 +03:00
|
|
|
#include "nsIDOMNode.h"
|
2005-11-02 10:39:01 +03:00
|
|
|
#include "nsIDOMDocument.h"
|
2005-11-02 10:41:59 +03:00
|
|
|
#include "nsDOMString.h"
|
2006-04-01 06:12:15 +04:00
|
|
|
#include "txXPathTreeWalker.h"
|
2007-09-26 22:20:24 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2013-07-04 19:40:06 +04:00
|
|
|
#include "mozilla/dom/XPathResultBinding.h"
|
2010-08-24 11:05:56 +04:00
|
|
|
|
2013-07-04 19:39:28 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2013-07-04 19:40:06 +04:00
|
|
|
XPathResult::XPathResult(nsINode* aParent)
|
|
|
|
: mParent(aParent),
|
|
|
|
mDocument(nullptr),
|
|
|
|
mCurrentPos(0),
|
|
|
|
mResultType(ANY_TYPE),
|
|
|
|
mInvalidIteratorState(true),
|
|
|
|
mBooleanResult(false),
|
|
|
|
mNumberResult(0)
|
2005-11-02 10:35:22 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-07-04 19:39:28 +04:00
|
|
|
XPathResult::XPathResult(const XPathResult &aResult)
|
2013-07-04 19:40:06 +04:00
|
|
|
: mParent(aResult.mParent),
|
|
|
|
mResult(aResult.mResult),
|
2007-11-03 03:01:04 +03:00
|
|
|
mResultNodes(aResult.mResultNodes),
|
|
|
|
mDocument(aResult.mDocument),
|
2013-07-04 19:40:06 +04:00
|
|
|
mContextNode(aResult.mContextNode),
|
2007-11-03 03:01:04 +03:00
|
|
|
mCurrentPos(0),
|
|
|
|
mResultType(aResult.mResultType),
|
|
|
|
mInvalidIteratorState(aResult.mInvalidIteratorState)
|
|
|
|
{
|
|
|
|
if (mDocument) {
|
|
|
|
mDocument->AddMutationObserver(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-04 19:39:28 +04:00
|
|
|
XPathResult::~XPathResult()
|
2007-09-26 22:20:24 +04:00
|
|
|
{
|
|
|
|
RemoveObserver();
|
|
|
|
}
|
|
|
|
|
2013-07-04 19:39:28 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(XPathResult)
|
2013-08-02 05:29:05 +04:00
|
|
|
|
2013-07-04 19:40:06 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(XPathResult)
|
2013-07-04 19:39:28 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(XPathResult)
|
2013-07-04 19:40:06 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mParent)
|
2007-09-26 22:20:24 +04:00
|
|
|
{
|
|
|
|
tmp->RemoveObserver();
|
|
|
|
}
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocument)
|
2007-09-26 22:20:24 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2013-07-04 19:39:28 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(XPathResult)
|
2013-07-04 19:40:06 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParent)
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocument)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mResultNodes)
|
2007-09-26 22:20:24 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2013-07-04 19:39:28 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(XPathResult)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(XPathResult)
|
2010-01-12 16:08:43 +03:00
|
|
|
|
2013-07-04 19:39:28 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(XPathResult)
|
2013-07-04 19:40:06 +04:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2007-09-26 22:20:24 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIMutationObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIXPathResult)
|
2013-07-04 19:40:06 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXPathResult)
|
2007-09-26 22:20:24 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2013-07-04 19:40:06 +04:00
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
XPathResult::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-07-04 19:40:06 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return XPathResultBinding::Wrap(aCx, this, aGivenProto);
|
2013-07-04 19:40:06 +04:00
|
|
|
}
|
|
|
|
|
2007-09-26 22:20:24 +04:00
|
|
|
void
|
2013-07-04 19:39:28 +04:00
|
|
|
XPathResult::RemoveObserver()
|
2005-11-02 10:35:22 +03:00
|
|
|
{
|
2005-11-02 10:43:00 +03:00
|
|
|
if (mDocument) {
|
2006-07-02 11:23:10 +04:00
|
|
|
mDocument->RemoveMutationObserver(this);
|
2005-11-02 10:43:00 +03:00
|
|
|
}
|
2005-11-02 10:35:22 +03:00
|
|
|
}
|
|
|
|
|
2013-07-04 19:40:06 +04:00
|
|
|
nsINode*
|
|
|
|
XPathResult::IterateNext(ErrorResult& aRv)
|
2005-11-02 10:35:22 +03:00
|
|
|
{
|
2005-11-02 10:43:00 +03:00
|
|
|
if (!isIterator()) {
|
2013-07-04 19:40:06 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
|
|
|
|
return nullptr;
|
2005-11-02 10:43:00 +03:00
|
|
|
}
|
2005-11-02 10:35:22 +03:00
|
|
|
|
2005-11-02 10:43:00 +03:00
|
|
|
if (mDocument) {
|
2017-01-05 10:31:56 +03:00
|
|
|
mDocument->FlushPendingNotifications(FlushType::Content);
|
2005-11-02 10:43:00 +03:00
|
|
|
}
|
2005-11-02 10:35:22 +03:00
|
|
|
|
2005-11-02 10:43:00 +03:00
|
|
|
if (mInvalidIteratorState) {
|
2013-07-04 19:40:06 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return nullptr;
|
2005-11-02 10:43:00 +03:00
|
|
|
}
|
2005-11-02 10:35:22 +03:00
|
|
|
|
2013-07-04 19:40:06 +04:00
|
|
|
return mResultNodes.SafeObjectAt(mCurrentPos++);
|
2005-11-02 10:35:22 +03:00
|
|
|
}
|
|
|
|
|
2006-07-02 11:23:10 +04:00
|
|
|
void
|
2013-07-04 19:39:28 +04:00
|
|
|
XPathResult::NodeWillBeDestroyed(const nsINode* aNode)
|
2006-07-02 11:23:10 +04:00
|
|
|
{
|
2010-07-21 19:33:32 +04:00
|
|
|
nsCOMPtr<nsIMutationObserver> kungFuDeathGrip(this);
|
2006-07-02 11:23:10 +04:00
|
|
|
// Set to null to avoid unregistring unnecessarily
|
2012-07-30 18:20:58 +04:00
|
|
|
mDocument = nullptr;
|
2007-08-20 09:53:02 +04:00
|
|
|
Invalidate(aNode->IsNodeOfType(nsINode::eCONTENT) ?
|
2012-07-30 18:20:58 +04:00
|
|
|
static_cast<const nsIContent*>(aNode) : nullptr);
|
2006-07-02 11:23:10 +04:00
|
|
|
}
|
2005-11-02 10:38:33 +03:00
|
|
|
|
2005-11-02 10:41:50 +03:00
|
|
|
void
|
2013-07-04 19:39:28 +04:00
|
|
|
XPathResult::CharacterDataChanged(nsIDocument* aDocument,
|
|
|
|
nsIContent *aContent,
|
|
|
|
CharacterDataChangeInfo* aInfo)
|
2005-11-02 10:35:22 +03:00
|
|
|
{
|
2007-08-20 09:53:02 +04:00
|
|
|
Invalidate(aContent);
|
2005-11-02 10:35:22 +03:00
|
|
|
}
|
|
|
|
|
2005-11-02 10:41:50 +03:00
|
|
|
void
|
2013-07-04 19:39:28 +04:00
|
|
|
XPathResult::AttributeChanged(nsIDocument* aDocument,
|
|
|
|
Element* aElement,
|
|
|
|
int32_t aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
2015-07-25 09:01:19 +03:00
|
|
|
int32_t aModType,
|
|
|
|
const nsAttrValue* aOldValue)
|
2005-11-02 10:35:22 +03:00
|
|
|
{
|
2010-08-24 11:05:56 +04:00
|
|
|
Invalidate(aElement);
|
2005-11-02 10:35:22 +03:00
|
|
|
}
|
|
|
|
|
2005-11-02 10:41:50 +03:00
|
|
|
void
|
2013-07-04 19:39:28 +04:00
|
|
|
XPathResult::ContentAppended(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aFirstNewContent,
|
|
|
|
int32_t aNewIndexInContainer)
|
2005-11-02 10:35:22 +03:00
|
|
|
{
|
2007-08-20 09:53:02 +04:00
|
|
|
Invalidate(aContainer);
|
2005-11-02 10:35:22 +03:00
|
|
|
}
|
|
|
|
|
2005-11-02 10:41:50 +03:00
|
|
|
void
|
2013-07-04 19:39:28 +04:00
|
|
|
XPathResult::ContentInserted(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
int32_t aIndexInContainer)
|
2005-11-02 10:35:22 +03:00
|
|
|
{
|
2007-08-20 09:53:02 +04:00
|
|
|
Invalidate(aContainer);
|
2005-11-02 10:35:22 +03:00
|
|
|
}
|
|
|
|
|
2005-11-02 10:41:50 +03:00
|
|
|
void
|
2013-07-04 19:39:28 +04:00
|
|
|
XPathResult::ContentRemoved(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
int32_t aIndexInContainer,
|
|
|
|
nsIContent* aPreviousSibling)
|
2005-11-02 10:35:22 +03:00
|
|
|
{
|
2007-08-20 09:53:02 +04:00
|
|
|
Invalidate(aContainer);
|
2005-11-02 10:35:22 +03:00
|
|
|
}
|
|
|
|
|
2005-11-02 10:43:00 +03:00
|
|
|
nsresult
|
2013-07-04 19:39:28 +04:00
|
|
|
XPathResult::SetExprResult(txAExprResult* aExprResult, uint16_t aResultType,
|
|
|
|
nsINode* aContextNode)
|
2005-11-02 10:35:22 +03:00
|
|
|
{
|
2013-11-26 16:48:44 +04:00
|
|
|
MOZ_ASSERT(aExprResult);
|
|
|
|
|
2007-11-05 11:06:48 +03:00
|
|
|
if ((isSnapshot(aResultType) || isIterator(aResultType) ||
|
|
|
|
isNode(aResultType)) &&
|
2006-01-27 12:58:43 +03:00
|
|
|
aExprResult->getResultType() != txAExprResult::NODESET) {
|
2007-11-05 11:06:48 +03:00
|
|
|
// The DOM spec doesn't really say what should happen when reusing an
|
|
|
|
// XPathResult and an error is thrown. Let's not touch the XPathResult
|
|
|
|
// in that case.
|
2006-01-27 12:58:43 +03:00
|
|
|
return NS_ERROR_DOM_TYPE_ERR;
|
|
|
|
}
|
|
|
|
|
2007-11-05 11:06:48 +03:00
|
|
|
mResultType = aResultType;
|
|
|
|
mContextNode = do_GetWeakReference(aContextNode);
|
|
|
|
|
2005-11-02 10:43:00 +03:00
|
|
|
if (mDocument) {
|
2006-07-02 11:23:10 +04:00
|
|
|
mDocument->RemoveMutationObserver(this);
|
2012-07-30 18:20:58 +04:00
|
|
|
mDocument = nullptr;
|
2005-11-02 10:43:00 +03:00
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2007-11-03 03:01:04 +03:00
|
|
|
mResultNodes.Clear();
|
|
|
|
|
|
|
|
// XXX This will keep the recycler alive, should we clear it?
|
|
|
|
mResult = aExprResult;
|
2013-11-26 16:48:44 +04:00
|
|
|
switch (mResultType) {
|
|
|
|
case BOOLEAN_TYPE:
|
|
|
|
{
|
|
|
|
mBooleanResult = mResult->booleanValue();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NUMBER_TYPE:
|
|
|
|
{
|
|
|
|
mNumberResult = mResult->numberValue();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case STRING_TYPE:
|
|
|
|
{
|
|
|
|
mResult->stringValue(mStringResult);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(isNode() || isIterator() || isSnapshot());
|
|
|
|
}
|
|
|
|
}
|
2007-11-03 03:01:04 +03:00
|
|
|
|
2013-11-26 16:48:44 +04:00
|
|
|
if (aExprResult->getResultType() == txAExprResult::NODESET) {
|
2007-11-03 03:01:04 +03:00
|
|
|
txNodeSet *nodeSet = static_cast<txNodeSet*>(aExprResult);
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t i, count = nodeSet->size();
|
2007-11-03 03:01:04 +03:00
|
|
|
for (i = 0; i < count; ++i) {
|
2013-07-04 19:40:06 +04:00
|
|
|
nsINode* node = txXPathNativeNode::getNode(nodeSet->get(i));
|
|
|
|
mResultNodes.AppendObject(node);
|
2007-11-03 03:01:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (count > 0) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mResult = nullptr;
|
2007-11-03 03:01:04 +03:00
|
|
|
}
|
|
|
|
}
|
2005-11-02 10:35:22 +03:00
|
|
|
|
2005-11-02 10:43:00 +03:00
|
|
|
if (!isIterator()) {
|
2005-11-02 10:35:22 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mInvalidIteratorState = false;
|
2005-11-02 10:43:00 +03:00
|
|
|
|
2007-11-03 03:01:04 +03:00
|
|
|
if (mResultNodes.Count() > 0) {
|
2005-11-02 10:43:00 +03:00
|
|
|
// If we support the document() function in DOM-XPath we need to
|
|
|
|
// observe all documents that we have resultnodes in.
|
2013-07-04 19:40:06 +04:00
|
|
|
mDocument = mResultNodes[0]->OwnerDoc();
|
2005-11-02 10:43:00 +03:00
|
|
|
NS_ASSERTION(mDocument, "We need a document!");
|
|
|
|
if (mDocument) {
|
2006-07-02 11:23:10 +04:00
|
|
|
mDocument->AddMutationObserver(this);
|
2005-11-02 10:35:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-02 10:43:00 +03:00
|
|
|
return NS_OK;
|
2005-11-02 10:35:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-07-04 19:39:28 +04:00
|
|
|
XPathResult::Invalidate(const nsIContent* aChangeRoot)
|
2005-11-02 10:35:22 +03:00
|
|
|
{
|
2007-08-20 09:53:02 +04:00
|
|
|
nsCOMPtr<nsINode> contextNode = do_QueryReferent(mContextNode);
|
|
|
|
if (contextNode && aChangeRoot && aChangeRoot->GetBindingParent()) {
|
|
|
|
// If context node is in anonymous content, changes to
|
|
|
|
// non-anonymous content need to invalidate the XPathResult. If
|
|
|
|
// the changes are happening in a different anonymous trees, no
|
|
|
|
// invalidation should happen.
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIContent* ctxBindingParent = nullptr;
|
2007-08-20 09:53:02 +04:00
|
|
|
if (contextNode->IsNodeOfType(nsINode::eCONTENT)) {
|
|
|
|
ctxBindingParent =
|
|
|
|
static_cast<nsIContent*>(contextNode.get())
|
|
|
|
->GetBindingParent();
|
|
|
|
} else if (contextNode->IsNodeOfType(nsINode::eATTRIBUTE)) {
|
2014-04-10 20:09:50 +04:00
|
|
|
Element* parent =
|
|
|
|
static_cast<Attr*>(contextNode.get())->GetElement();
|
2007-08-20 09:53:02 +04:00
|
|
|
if (parent) {
|
|
|
|
ctxBindingParent = parent->GetBindingParent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ctxBindingParent != aChangeRoot->GetBindingParent()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mInvalidIteratorState = true;
|
2010-07-21 19:33:32 +04:00
|
|
|
// Make sure nulling out mDocument is the last thing we do.
|
2005-11-02 10:35:22 +03:00
|
|
|
if (mDocument) {
|
2006-07-02 11:23:10 +04:00
|
|
|
mDocument->RemoveMutationObserver(this);
|
2012-07-30 18:20:58 +04:00
|
|
|
mDocument = nullptr;
|
2005-11-02 10:35:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-02 10:43:00 +03:00
|
|
|
nsresult
|
2013-07-04 19:39:28 +04:00
|
|
|
XPathResult::GetExprResult(txAExprResult** aExprResult)
|
2005-11-02 10:35:22 +03:00
|
|
|
{
|
2005-11-02 10:43:00 +03:00
|
|
|
if (isIterator() && mInvalidIteratorState) {
|
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
|
|
|
}
|
2005-11-02 10:35:22 +03:00
|
|
|
|
2007-11-03 03:01:04 +03:00
|
|
|
if (mResult) {
|
|
|
|
NS_ADDREF(*aExprResult = mResult);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mResultNodes.Count() == 0) {
|
2005-11-02 10:43:00 +03:00
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
2005-11-02 10:35:22 +03:00
|
|
|
}
|
2005-11-02 10:43:00 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<txNodeSet> nodeSet = new txNodeSet(nullptr);
|
2007-11-03 03:01:04 +03:00
|
|
|
if (!nodeSet) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i, count = mResultNodes.Count();
|
2007-11-03 03:01:04 +03:00
|
|
|
for (i = 0; i < count; ++i) {
|
|
|
|
nsAutoPtr<txXPathNode> node(txXPathNativeNode::createXPathNode(mResultNodes[i]));
|
|
|
|
if (!node) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
nodeSet->append(*node);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(*aExprResult = nodeSet);
|
2005-11-02 10:43:00 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-07-04 19:39:28 +04:00
|
|
|
XPathResult::Clone(nsIXPathResult **aResult)
|
2005-11-02 10:43:00 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aResult = nullptr;
|
2005-11-02 10:43:00 +03:00
|
|
|
|
|
|
|
if (isIterator() && mInvalidIteratorState) {
|
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
2005-11-02 10:35:22 +03:00
|
|
|
}
|
2005-11-02 10:43:00 +03:00
|
|
|
|
2013-07-04 19:40:06 +04:00
|
|
|
NS_ADDREF(*aResult = new XPathResult(*this));
|
2005-11-02 10:43:00 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-07-04 19:39:28 +04:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|