|
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/. */ |
|
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 |
|
17 UnaryExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult) |
|
18 { |
|
19 *aResult = nullptr; |
|
20 |
|
21 nsRefPtr<txAExprResult> exprRes; |
|
22 nsresult rv = expr->evaluate(aContext, getter_AddRefs(exprRes)); |
|
23 NS_ENSURE_SUCCESS(rv, rv); |
|
24 |
|
25 double value = exprRes->numberValue(); |
|
26 #ifdef HPUX |
|
27 /* |
|
28 * Negation of a zero doesn't produce a negative |
|
29 * zero on HPUX. Perform the operation by multiplying with |
|
30 * -1. |
|
31 */ |
|
32 return aContext->recycler()->getNumberResult(-1 * value, aResult); |
|
33 #else |
|
34 return aContext->recycler()->getNumberResult(-value, aResult); |
|
35 #endif |
|
36 } |
|
37 |
|
38 TX_IMPL_EXPR_STUBS_1(UnaryExpr, NODESET_RESULT, expr) |
|
39 |
|
40 bool |
|
41 UnaryExpr::isSensitiveTo(ContextSensitivity aContext) |
|
42 { |
|
43 return expr->isSensitiveTo(aContext); |
|
44 } |
|
45 |
|
46 #ifdef TX_TO_STRING |
|
47 void |
|
48 UnaryExpr::toString(nsAString& str) |
|
49 { |
|
50 if (!expr) |
|
51 return; |
|
52 str.Append(char16_t('-')); |
|
53 expr->toString(str); |
|
54 } |
|
55 #endif |