dom/xslt/xpath/txFilterExpr.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "txExpr.h"
michael@0 7 #include "txNodeSet.h"
michael@0 8 #include "txIXPathContext.h"
michael@0 9
michael@0 10 //-- Implementation of FilterExpr --/
michael@0 11
michael@0 12 //-----------------------------/
michael@0 13 //- Virtual methods from Expr -/
michael@0 14 //-----------------------------/
michael@0 15
michael@0 16 /**
michael@0 17 * Evaluates this Expr based on the given context node and processor state
michael@0 18 * @param context the context node for evaluation of this Expr
michael@0 19 * @param ps the ProcessorState containing the stack information needed
michael@0 20 * for evaluation
michael@0 21 * @return the result of the evaluation
michael@0 22 * @see Expr
michael@0 23 **/
michael@0 24 nsresult
michael@0 25 FilterExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
michael@0 26 {
michael@0 27 *aResult = nullptr;
michael@0 28
michael@0 29 nsRefPtr<txAExprResult> exprRes;
michael@0 30 nsresult rv = expr->evaluate(aContext, getter_AddRefs(exprRes));
michael@0 31 NS_ENSURE_SUCCESS(rv, rv);
michael@0 32
michael@0 33 NS_ENSURE_TRUE(exprRes->getResultType() == txAExprResult::NODESET,
michael@0 34 NS_ERROR_XSLT_NODESET_EXPECTED);
michael@0 35
michael@0 36 nsRefPtr<txNodeSet> nodes =
michael@0 37 static_cast<txNodeSet*>(static_cast<txAExprResult*>(exprRes));
michael@0 38 // null out exprRes so that we can test for shared-ness
michael@0 39 exprRes = nullptr;
michael@0 40
michael@0 41 nsRefPtr<txNodeSet> nonShared;
michael@0 42 rv = aContext->recycler()->getNonSharedNodeSet(nodes,
michael@0 43 getter_AddRefs(nonShared));
michael@0 44 NS_ENSURE_SUCCESS(rv, rv);
michael@0 45
michael@0 46 rv = evaluatePredicates(nonShared, aContext);
michael@0 47 NS_ENSURE_SUCCESS(rv, rv);
michael@0 48
michael@0 49 *aResult = nonShared;
michael@0 50 NS_ADDREF(*aResult);
michael@0 51
michael@0 52 return NS_OK;
michael@0 53 } //-- evaluate
michael@0 54
michael@0 55 TX_IMPL_EXPR_STUBS_BASE(FilterExpr, NODESET_RESULT)
michael@0 56
michael@0 57 Expr*
michael@0 58 FilterExpr::getSubExprAt(uint32_t aPos)
michael@0 59 {
michael@0 60 if (aPos == 0) {
michael@0 61 return expr;
michael@0 62 }
michael@0 63 return PredicateList::getSubExprAt(aPos - 1);
michael@0 64 }
michael@0 65
michael@0 66 void
michael@0 67 FilterExpr::setSubExprAt(uint32_t aPos, Expr* aExpr)
michael@0 68 {
michael@0 69 if (aPos == 0) {
michael@0 70 expr.forget();
michael@0 71 expr = aExpr;
michael@0 72 }
michael@0 73 else {
michael@0 74 PredicateList::setSubExprAt(aPos - 1, aExpr);
michael@0 75 }
michael@0 76 }
michael@0 77
michael@0 78 bool
michael@0 79 FilterExpr::isSensitiveTo(ContextSensitivity aContext)
michael@0 80 {
michael@0 81 return expr->isSensitiveTo(aContext) ||
michael@0 82 PredicateList::isSensitiveTo(aContext);
michael@0 83 }
michael@0 84
michael@0 85 #ifdef TX_TO_STRING
michael@0 86 void
michael@0 87 FilterExpr::toString(nsAString& str)
michael@0 88 {
michael@0 89 if ( expr ) expr->toString(str);
michael@0 90 else str.AppendLiteral("null");
michael@0 91 PredicateList::toString(str);
michael@0 92 }
michael@0 93 #endif
michael@0 94

mercurial