dom/xslt/xpath/txFilterExpr.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     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/. */
     6 #include "txExpr.h"
     7 #include "txNodeSet.h"
     8 #include "txIXPathContext.h"
    10 //-- Implementation of FilterExpr --/
    12   //-----------------------------/
    13  //- Virtual methods from Expr -/
    14 //-----------------------------/
    16 /**
    17  * Evaluates this Expr based on the given context node and processor state
    18  * @param context the context node for evaluation of this Expr
    19  * @param ps the ProcessorState containing the stack information needed
    20  * for evaluation
    21  * @return the result of the evaluation
    22  * @see Expr
    23 **/
    24 nsresult
    25 FilterExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
    26 {
    27     *aResult = nullptr;
    29     nsRefPtr<txAExprResult> exprRes;
    30     nsresult rv = expr->evaluate(aContext, getter_AddRefs(exprRes));
    31     NS_ENSURE_SUCCESS(rv, rv);
    33     NS_ENSURE_TRUE(exprRes->getResultType() == txAExprResult::NODESET,
    34                    NS_ERROR_XSLT_NODESET_EXPECTED);
    36     nsRefPtr<txNodeSet> nodes =
    37         static_cast<txNodeSet*>(static_cast<txAExprResult*>(exprRes));
    38     // null out exprRes so that we can test for shared-ness
    39     exprRes = nullptr;
    41     nsRefPtr<txNodeSet> nonShared;
    42     rv = aContext->recycler()->getNonSharedNodeSet(nodes,
    43                                                    getter_AddRefs(nonShared));
    44     NS_ENSURE_SUCCESS(rv, rv);
    46     rv = evaluatePredicates(nonShared, aContext);
    47     NS_ENSURE_SUCCESS(rv, rv);
    49     *aResult = nonShared;
    50     NS_ADDREF(*aResult);
    52     return NS_OK;
    53 } //-- evaluate
    55 TX_IMPL_EXPR_STUBS_BASE(FilterExpr, NODESET_RESULT)
    57 Expr*
    58 FilterExpr::getSubExprAt(uint32_t aPos)
    59 {
    60     if (aPos == 0) {
    61       return expr;
    62     }
    63     return PredicateList::getSubExprAt(aPos - 1);
    64 }
    66 void
    67 FilterExpr::setSubExprAt(uint32_t aPos, Expr* aExpr)
    68 {
    69     if (aPos == 0) {
    70       expr.forget();
    71       expr = aExpr;
    72     }
    73     else {
    74       PredicateList::setSubExprAt(aPos - 1, aExpr);
    75     }
    76 }
    78 bool
    79 FilterExpr::isSensitiveTo(ContextSensitivity aContext)
    80 {
    81     return expr->isSensitiveTo(aContext) ||
    82            PredicateList::isSensitiveTo(aContext);
    83 }
    85 #ifdef TX_TO_STRING
    86 void
    87 FilterExpr::toString(nsAString& str)
    88 {
    89     if ( expr ) expr->toString(str);
    90     else str.AppendLiteral("null");
    91     PredicateList::toString(str);
    92 }
    93 #endif

mercurial