Bug 1874684 - Part 4: Prefer const references instead of copying Instant values....
[gecko.git] / dom / xslt / xpath / txPredicatedNodeTest.cpp
blob6c3fd33cf5eb362264373cfce171c3b7a8fdad42
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "txExpr.h"
7 #include "txExprResult.h"
8 #include "txSingleNodeContext.h"
10 txPredicatedNodeTest::txPredicatedNodeTest(txNodeTest* aNodeTest,
11 Expr* aPredicate)
12 : mNodeTest(aNodeTest), mPredicate(aPredicate) {
13 NS_ASSERTION(!mPredicate->isSensitiveTo(Expr::NODESET_CONTEXT),
14 "predicate must not be context-nodeset-sensitive");
17 nsresult txPredicatedNodeTest::matches(const txXPathNode& aNode,
18 txIMatchContext* aContext,
19 bool& aMatched) {
20 nsresult rv = mNodeTest->matches(aNode, aContext, aMatched);
21 NS_ENSURE_SUCCESS(rv, rv);
23 if (!aMatched) {
24 return NS_OK;
27 txSingleNodeContext context(aNode, aContext);
28 RefPtr<txAExprResult> res;
29 rv = mPredicate->evaluate(&context, getter_AddRefs(res));
30 NS_ENSURE_SUCCESS(rv, rv);
32 aMatched = res->booleanValue();
33 return NS_OK;
36 double txPredicatedNodeTest::getDefaultPriority() { return 0.5; }
38 bool txPredicatedNodeTest::isSensitiveTo(Expr::ContextSensitivity aContext) {
39 return mNodeTest->isSensitiveTo(aContext) ||
40 mPredicate->isSensitiveTo(aContext);
43 #ifdef TX_TO_STRING
44 void txPredicatedNodeTest::toString(nsAString& aDest) {
45 mNodeTest->toString(aDest);
46 aDest.Append(char16_t('['));
47 mPredicate->toString(aDest);
48 aDest.Append(char16_t(']'));
50 #endif