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/. */
7 #include "txExprResult.h"
8 #include "txSingleNodeContext.h"
10 txPredicatedNodeTest::txPredicatedNodeTest(txNodeTest
* aNodeTest
,
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
,
20 nsresult rv
= mNodeTest
->matches(aNode
, aContext
, aMatched
);
21 NS_ENSURE_SUCCESS(rv
, rv
);
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();
36 double txPredicatedNodeTest::getDefaultPriority() { return 0.5; }
38 bool txPredicatedNodeTest::isSensitiveTo(Expr::ContextSensitivity aContext
) {
39 return mNodeTest
->isSensitiveTo(aContext
) ||
40 mPredicate
->isSensitiveTo(aContext
);
44 void txPredicatedNodeTest::toString(nsAString
& aDest
) {
45 mNodeTest
->toString(aDest
);
46 aDest
.Append(char16_t('['));
47 mPredicate
->toString(aDest
);
48 aDest
.Append(char16_t(']'));