1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/xslt/xpath/txUnionExpr.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,94 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "txExpr.h" 1.10 +#include "txIXPathContext.h" 1.11 +#include "txNodeSet.h" 1.12 + 1.13 + //-------------/ 1.14 + //- UnionExpr -/ 1.15 +//-------------/ 1.16 + 1.17 + //-----------------------------/ 1.18 + //- Virtual methods from Expr -/ 1.19 +//-----------------------------/ 1.20 + 1.21 +/** 1.22 + * Evaluates this Expr based on the given context node and processor state 1.23 + * @param context the context node for evaluation of this Expr 1.24 + * @param ps the ContextState containing the stack information needed 1.25 + * for evaluation 1.26 + * @return the result of the evaluation 1.27 +**/ 1.28 +nsresult 1.29 +UnionExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult) 1.30 +{ 1.31 + *aResult = nullptr; 1.32 + nsRefPtr<txNodeSet> nodes; 1.33 + nsresult rv = aContext->recycler()->getNodeSet(getter_AddRefs(nodes)); 1.34 + NS_ENSURE_SUCCESS(rv, rv); 1.35 + 1.36 + uint32_t i, len = mExpressions.Length(); 1.37 + for (i = 0; i < len; ++i) { 1.38 + nsRefPtr<txAExprResult> exprResult; 1.39 + rv = mExpressions[i]->evaluate(aContext, getter_AddRefs(exprResult)); 1.40 + NS_ENSURE_SUCCESS(rv, rv); 1.41 + 1.42 + if (exprResult->getResultType() != txAExprResult::NODESET) { 1.43 + //XXX ErrorReport: report nonnodeset error 1.44 + return NS_ERROR_XSLT_NODESET_EXPECTED; 1.45 + } 1.46 + 1.47 + nsRefPtr<txNodeSet> resultSet, ownedSet; 1.48 + resultSet = static_cast<txNodeSet*> 1.49 + (static_cast<txAExprResult*>(exprResult)); 1.50 + exprResult = nullptr; 1.51 + rv = aContext->recycler()-> 1.52 + getNonSharedNodeSet(resultSet, getter_AddRefs(ownedSet)); 1.53 + NS_ENSURE_SUCCESS(rv, rv); 1.54 + 1.55 + rv = nodes->addAndTransfer(ownedSet); 1.56 + NS_ENSURE_SUCCESS(rv, rv); 1.57 + } 1.58 + 1.59 + *aResult = nodes; 1.60 + NS_ADDREF(*aResult); 1.61 + 1.62 + return NS_OK; 1.63 +} //-- evaluate 1.64 + 1.65 +Expr::ExprType 1.66 +UnionExpr::getType() 1.67 +{ 1.68 + return UNION_EXPR; 1.69 +} 1.70 + 1.71 +TX_IMPL_EXPR_STUBS_LIST(UnionExpr, NODESET_RESULT, mExpressions) 1.72 + 1.73 +bool 1.74 +UnionExpr::isSensitiveTo(ContextSensitivity aContext) 1.75 +{ 1.76 + uint32_t i, len = mExpressions.Length(); 1.77 + for (i = 0; i < len; ++i) { 1.78 + if (mExpressions[i]->isSensitiveTo(aContext)) { 1.79 + return true; 1.80 + } 1.81 + } 1.82 + 1.83 + return false; 1.84 +} 1.85 + 1.86 +#ifdef TX_TO_STRING 1.87 +void 1.88 +UnionExpr::toString(nsAString& dest) 1.89 +{ 1.90 + uint32_t i; 1.91 + for (i = 0; i < mExpressions.Length(); ++i) { 1.92 + if (i > 0) 1.93 + dest.AppendLiteral(" | "); 1.94 + mExpressions[i]->toString(dest); 1.95 + } 1.96 +} 1.97 +#endif