txUnaryExpr.cpp (1288B)
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 9 /* 10 * Evaluates this Expr based on the given context node and processor state 11 * @param context the context node for evaluation of this Expr 12 * @param ps the ContextState containing the stack information needed 13 * for evaluation. 14 * @return the result of the evaluation. 15 */ 16 nsresult UnaryExpr::evaluate(txIEvalContext* aContext, 17 txAExprResult** aResult) { 18 *aResult = nullptr; 19 20 RefPtr<txAExprResult> exprRes; 21 nsresult rv = expr->evaluate(aContext, getter_AddRefs(exprRes)); 22 NS_ENSURE_SUCCESS(rv, rv); 23 24 double value = exprRes->numberValue(); 25 return aContext->recycler()->getNumberResult(-value, aResult); 26 } 27 28 TX_IMPL_EXPR_STUBS_1(UnaryExpr, NODESET_RESULT, expr) 29 30 bool UnaryExpr::isSensitiveTo(ContextSensitivity aContext) { 31 return expr->isSensitiveTo(aContext); 32 } 33 34 #ifdef TX_TO_STRING 35 void UnaryExpr::toString(nsAString& str) { 36 if (!expr) return; 37 str.Append(char16_t('-')); 38 expr->toString(str); 39 } 40 #endif