tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

txPredicatedNodeTest.cpp (1674B)


      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/. */
      5 
      6 #include "txExpr.h"
      7 #include "txExprResult.h"
      8 #include "txSingleNodeContext.h"
      9 
     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");
     15 }
     16 
     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);
     22 
     23  if (!aMatched) {
     24    return NS_OK;
     25  }
     26 
     27  txSingleNodeContext context(aNode, aContext);
     28  RefPtr<txAExprResult> res;
     29  rv = mPredicate->evaluate(&context, getter_AddRefs(res));
     30  NS_ENSURE_SUCCESS(rv, rv);
     31 
     32  aMatched = res->booleanValue();
     33  return NS_OK;
     34 }
     35 
     36 double txPredicatedNodeTest::getDefaultPriority() { return 0.5; }
     37 
     38 bool txPredicatedNodeTest::isSensitiveTo(Expr::ContextSensitivity aContext) {
     39  return mNodeTest->isSensitiveTo(aContext) ||
     40         mPredicate->isSensitiveTo(aContext);
     41 }
     42 
     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(']'));
     49 }
     50 #endif