diff --git a/dom/xslt/xpath/XPathExpression.cpp b/dom/xslt/xpath/XPathExpression.cpp index c35311a78cb0..201b22a8d630 100644 --- a/dom/xslt/xpath/XPathExpression.cpp +++ b/dom/xslt/xpath/XPathExpression.cpp @@ -164,7 +164,10 @@ already_AddRefed XPathExpression::EvaluateWithContext( xpathResult = new XPathResult(&aContextNode); } - aRv = xpathResult->SetExprResult(exprResult, resultType, &aContextNode); + xpathResult->SetExprResult(exprResult, resultType, &aContextNode, aRv); + if (aRv.Failed()) { + return nullptr; + } return xpathResult.forget(); } diff --git a/dom/xslt/xpath/XPathResult.cpp b/dom/xslt/xpath/XPathResult.cpp index f07a4b3010b4..c90defd9e110 100644 --- a/dom/xslt/xpath/XPathResult.cpp +++ b/dom/xslt/xpath/XPathResult.cpp @@ -79,7 +79,7 @@ void XPathResult::RemoveObserver() { nsINode* XPathResult::IterateNext(ErrorResult& aRv) { if (!isIterator()) { - aRv.Throw(NS_ERROR_DOM_TYPE_ERR); + aRv.ThrowTypeError(u"Result is not an iterator"); return nullptr; } @@ -88,7 +88,7 @@ nsINode* XPathResult::IterateNext(ErrorResult& aRv) { } if (mInvalidIteratorState) { - aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); + aRv.ThrowInvalidStateError("The document has been mutated since the result was returned"); return nullptr; } @@ -126,9 +126,9 @@ void XPathResult::ContentRemoved(nsIContent* aChild, Invalidate(aChild->GetParent()); } -nsresult XPathResult::SetExprResult(txAExprResult* aExprResult, - uint16_t aResultType, - nsINode* aContextNode) { +void XPathResult::SetExprResult(txAExprResult* aExprResult, + uint16_t aResultType, nsINode* aContextNode, + ErrorResult& aRv) { MOZ_ASSERT(aExprResult); if ((isSnapshot(aResultType) || isIterator(aResultType) || @@ -137,7 +137,8 @@ nsresult XPathResult::SetExprResult(txAExprResult* aExprResult, // 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. - return NS_ERROR_DOM_TYPE_ERR; + aRv.ThrowTypeError(u"Result type mismatch"); + return; } mResultType = aResultType; @@ -184,7 +185,7 @@ nsresult XPathResult::SetExprResult(txAExprResult* aExprResult, } if (!isIterator()) { - return NS_OK; + return; } mCurrentPos = 0; @@ -199,8 +200,6 @@ nsresult XPathResult::SetExprResult(txAExprResult* aExprResult, mDocument->AddMutationObserver(this); } } - - return NS_OK; } void XPathResult::Invalidate(const nsIContent* aChangeRoot) { diff --git a/dom/xslt/xpath/XPathResult.h b/dom/xslt/xpath/XPathResult.h index 4db8356685be..ba348d276273 100644 --- a/dom/xslt/xpath/XPathResult.h +++ b/dom/xslt/xpath/XPathResult.h @@ -31,9 +31,9 @@ class txAExprResult; class nsIXPathResult : public nsISupports { public: NS_DECLARE_STATIC_IID_ACCESSOR(NS_IXPATHRESULT_IID) - virtual nsresult SetExprResult(txAExprResult* aExprResult, - uint16_t aResultType, - nsINode* aContextNode) = 0; + virtual void SetExprResult(txAExprResult* aExprResult, uint16_t aResultType, + nsINode* aContextNode, + mozilla::ErrorResult& aRv) = 0; virtual nsresult GetExprResult(txAExprResult** aExprResult) = 0; virtual nsresult Clone(nsIXPathResult** aResult) = 0; }; @@ -83,7 +83,7 @@ class XPathResult final : public nsIXPathResult, uint16_t ResultType() const { return mResultType; } double GetNumberValue(ErrorResult& aRv) const { if (mResultType != NUMBER_TYPE) { - aRv.Throw(NS_ERROR_DOM_TYPE_ERR); + aRv.ThrowTypeError(u"Result is not a number"); return 0; } @@ -91,7 +91,7 @@ class XPathResult final : public nsIXPathResult, } void GetStringValue(nsAString& aStringValue, ErrorResult& aRv) const { if (mResultType != STRING_TYPE) { - aRv.Throw(NS_ERROR_DOM_TYPE_ERR); + aRv.ThrowTypeError(u"Result is not a string"); return; } @@ -99,7 +99,7 @@ class XPathResult final : public nsIXPathResult, } bool GetBooleanValue(ErrorResult& aRv) const { if (mResultType != BOOLEAN_TYPE) { - aRv.Throw(NS_ERROR_DOM_TYPE_ERR); + aRv.ThrowTypeError(u"Result is not a boolean"); return false; } @@ -107,7 +107,7 @@ class XPathResult final : public nsIXPathResult, } nsINode* GetSingleNodeValue(ErrorResult& aRv) const { if (!isNode()) { - aRv.Throw(NS_ERROR_DOM_TYPE_ERR); + aRv.ThrowTypeError(u"Result is not a node"); return nullptr; } @@ -118,7 +118,7 @@ class XPathResult final : public nsIXPathResult, } uint32_t GetSnapshotLength(ErrorResult& aRv) const { if (!isSnapshot()) { - aRv.Throw(NS_ERROR_DOM_TYPE_ERR); + aRv.ThrowTypeError(u"Result is not a snapshot"); return 0; } @@ -127,7 +127,7 @@ class XPathResult final : public nsIXPathResult, nsINode* IterateNext(ErrorResult& aRv); nsINode* SnapshotItem(uint32_t aIndex, ErrorResult& aRv) const { if (!isSnapshot()) { - aRv.Throw(NS_ERROR_DOM_TYPE_ERR); + aRv.ThrowTypeError(u"Result is not a snapshot"); return nullptr; } @@ -142,8 +142,8 @@ class XPathResult final : public nsIXPathResult, NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED - nsresult SetExprResult(txAExprResult* aExprResult, uint16_t aResultType, - nsINode* aContextNode) override; + void SetExprResult(txAExprResult* aExprResult, uint16_t aResultType, + nsINode* aContextNode, ErrorResult& aRv) override; nsresult GetExprResult(txAExprResult** aExprResult) override; nsresult Clone(nsIXPathResult** aResult) override; void RemoveObserver();