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/. */
8 #include "txNodeSetContext.h"
11 * Represents an ordered list of Predicates,
12 * for use with Step and Filter Expressions
15 nsresult
PredicateList::evaluatePredicates(txNodeSet
* nodes
,
16 txIMatchContext
* aContext
) {
17 NS_ASSERTION(nodes
, "called evaluatePredicates with nullptr NodeSet");
20 uint32_t i
, len
= mPredicates
.Length();
21 for (i
= 0; i
< len
&& !nodes
->isEmpty(); ++i
) {
22 txNodeSetContext
predContext(nodes
, aContext
);
24 * add nodes to newNodes that match the expression
25 * or, if the result is a number, add the node with the right
29 while (predContext
.hasNext()) {
31 RefPtr
<txAExprResult
> exprResult
;
32 rv
= mPredicates
[i
]->evaluate(&predContext
, getter_AddRefs(exprResult
));
33 NS_ENSURE_SUCCESS(rv
, rv
);
35 // handle default, [position() == numberValue()]
36 if (exprResult
->getResultType() == txAExprResult::NUMBER
) {
37 if ((double)predContext
.position() == exprResult
->numberValue()) {
40 } else if (exprResult
->booleanValue()) {
45 // sweep the non-marked nodes
52 bool PredicateList::isSensitiveTo(Expr::ContextSensitivity aContext
) {
53 // We're creating a new node/nodeset so we can ignore those bits.
54 Expr::ContextSensitivity context
=
55 aContext
& ~(Expr::NODE_CONTEXT
| Expr::NODESET_CONTEXT
);
56 if (context
== Expr::NO_CONTEXT
) {
60 uint32_t i
, len
= mPredicates
.Length();
61 for (i
= 0; i
< len
; ++i
) {
62 if (mPredicates
[i
]->isSensitiveTo(context
)) {
71 void PredicateList::toString(nsAString
& dest
) {
72 for (uint32_t i
= 0; i
< mPredicates
.Length(); ++i
) {
73 dest
.Append(char16_t('['));
74 mPredicates
[i
]->toString(dest
);
75 dest
.Append(char16_t(']'));