dom/xslt/xpath/txPredicatedNodeTest.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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 "txExprResult.h"
michael@0 8 #include "txSingleNodeContext.h"
michael@0 9
michael@0 10 txPredicatedNodeTest::txPredicatedNodeTest(txNodeTest* aNodeTest,
michael@0 11 Expr* aPredicate)
michael@0 12 : mNodeTest(aNodeTest),
michael@0 13 mPredicate(aPredicate)
michael@0 14 {
michael@0 15 NS_ASSERTION(!mPredicate->isSensitiveTo(Expr::NODESET_CONTEXT),
michael@0 16 "predicate must not be context-nodeset-sensitive");
michael@0 17 }
michael@0 18
michael@0 19 bool
michael@0 20 txPredicatedNodeTest::matches(const txXPathNode& aNode,
michael@0 21 txIMatchContext* aContext)
michael@0 22 {
michael@0 23 if (!mNodeTest->matches(aNode, aContext)) {
michael@0 24 return false;
michael@0 25 }
michael@0 26
michael@0 27 txSingleNodeContext context(aNode, aContext);
michael@0 28 nsRefPtr<txAExprResult> res;
michael@0 29 nsresult rv = mPredicate->evaluate(&context, getter_AddRefs(res));
michael@0 30 NS_ENSURE_SUCCESS(rv, false);
michael@0 31
michael@0 32 return res->booleanValue();
michael@0 33 }
michael@0 34
michael@0 35 double
michael@0 36 txPredicatedNodeTest::getDefaultPriority()
michael@0 37 {
michael@0 38 return 0.5;
michael@0 39 }
michael@0 40
michael@0 41 bool
michael@0 42 txPredicatedNodeTest::isSensitiveTo(Expr::ContextSensitivity aContext)
michael@0 43 {
michael@0 44 return mNodeTest->isSensitiveTo(aContext) ||
michael@0 45 mPredicate->isSensitiveTo(aContext);
michael@0 46 }
michael@0 47
michael@0 48 #ifdef TX_TO_STRING
michael@0 49 void
michael@0 50 txPredicatedNodeTest::toString(nsAString& aDest)
michael@0 51 {
michael@0 52 mNodeTest->toString(aDest);
michael@0 53 aDest.Append(char16_t('['));
michael@0 54 mPredicate->toString(aDest);
michael@0 55 aDest.Append(char16_t(']'));
michael@0 56 }
michael@0 57 #endif

mercurial