tor-browser

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

txUnionExpr.cpp (2544B)


      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 "txIXPathContext.h"
      8 #include "txNodeSet.h"
      9 
     10 #ifdef TX_TO_STRING
     11 #  include "nsReadableUtils.h"
     12 #endif
     13 
     14 //-------------/
     15 //- UnionExpr -/
     16 //-------------/
     17 
     18 //-----------------------------/
     19 //- Virtual methods from Expr -/
     20 //-----------------------------/
     21 
     22 /**
     23 * Evaluates this Expr based on the given context node and processor state
     24 * @param context the context node for evaluation of this Expr
     25 * @param ps the ContextState containing the stack information needed
     26 * for evaluation
     27 * @return the result of the evaluation
     28 **/
     29 nsresult UnionExpr::evaluate(txIEvalContext* aContext,
     30                             txAExprResult** aResult) {
     31  *aResult = nullptr;
     32  RefPtr<txNodeSet> nodes;
     33  nsresult rv = aContext->recycler()->getNodeSet(getter_AddRefs(nodes));
     34  NS_ENSURE_SUCCESS(rv, rv);
     35 
     36  uint32_t i, len = mExpressions.Length();
     37  for (i = 0; i < len; ++i) {
     38    RefPtr<txAExprResult> exprResult;
     39    rv = mExpressions[i]->evaluate(aContext, getter_AddRefs(exprResult));
     40    NS_ENSURE_SUCCESS(rv, rv);
     41 
     42    if (exprResult->getResultType() != txAExprResult::NODESET) {
     43      // XXX ErrorReport: report nonnodeset error
     44      return NS_ERROR_XSLT_NODESET_EXPECTED;
     45    }
     46 
     47    RefPtr<txNodeSet> resultSet, ownedSet;
     48    resultSet =
     49        static_cast<txNodeSet*>(static_cast<txAExprResult*>(exprResult));
     50    exprResult = nullptr;
     51    rv = aContext->recycler()->getNonSharedNodeSet(resultSet,
     52                                                   getter_AddRefs(ownedSet));
     53    NS_ENSURE_SUCCESS(rv, rv);
     54 
     55    rv = nodes->addAndTransfer(ownedSet);
     56    NS_ENSURE_SUCCESS(rv, rv);
     57  }
     58 
     59  *aResult = nodes;
     60  NS_ADDREF(*aResult);
     61 
     62  return NS_OK;
     63 }  //-- evaluate
     64 
     65 Expr::ExprType UnionExpr::getType() { return UNION_EXPR; }
     66 
     67 TX_IMPL_EXPR_STUBS_LIST(UnionExpr, NODESET_RESULT, mExpressions)
     68 
     69 bool UnionExpr::isSensitiveTo(ContextSensitivity aContext) {
     70  uint32_t i, len = mExpressions.Length();
     71  for (i = 0; i < len; ++i) {
     72    if (mExpressions[i]->isSensitiveTo(aContext)) {
     73      return true;
     74    }
     75  }
     76 
     77  return false;
     78 }
     79 
     80 #ifdef TX_TO_STRING
     81 void UnionExpr::toString(nsAString& aDest) {
     82  StringJoinAppend(aDest, u" | "_ns, mExpressions,
     83                   [](nsAString& dest, Expr* expr) { expr->toString(dest); });
     84 }
     85 #endif