Wed, 31 Dec 2014 06:09:35 +0100
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 "txNodeSetAdaptor.h"
7 #include "txXPathTreeWalker.h"
9 txNodeSetAdaptor::txNodeSetAdaptor()
10 : txXPathObjectAdaptor(),
11 mWritable(true)
12 {
13 }
15 txNodeSetAdaptor::txNodeSetAdaptor(txNodeSet *aNodeSet)
16 : txXPathObjectAdaptor(aNodeSet),
17 mWritable(false)
18 {
19 }
21 NS_IMPL_ISUPPORTS_INHERITED(txNodeSetAdaptor, txXPathObjectAdaptor, txINodeSet)
23 nsresult
24 txNodeSetAdaptor::Init()
25 {
26 if (!mValue) {
27 mValue = new txNodeSet(nullptr);
28 }
30 return mValue ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
31 }
33 NS_IMETHODIMP
34 txNodeSetAdaptor::Item(uint32_t aIndex, nsIDOMNode **aResult)
35 {
36 *aResult = nullptr;
38 if (aIndex > (uint32_t)NodeSet()->size()) {
39 return NS_ERROR_ILLEGAL_VALUE;
40 }
42 return txXPathNativeNode::getNode(NodeSet()->get(aIndex), aResult);
43 }
45 NS_IMETHODIMP
46 txNodeSetAdaptor::ItemAsNumber(uint32_t aIndex, double *aResult)
47 {
48 if (aIndex > (uint32_t)NodeSet()->size()) {
49 return NS_ERROR_ILLEGAL_VALUE;
50 }
52 nsAutoString result;
53 txXPathNodeUtils::appendNodeValue(NodeSet()->get(aIndex), result);
55 *aResult = txDouble::toDouble(result);
57 return NS_OK;
58 }
60 NS_IMETHODIMP
61 txNodeSetAdaptor::ItemAsString(uint32_t aIndex, nsAString &aResult)
62 {
63 if (aIndex > (uint32_t)NodeSet()->size()) {
64 return NS_ERROR_ILLEGAL_VALUE;
65 }
67 txXPathNodeUtils::appendNodeValue(NodeSet()->get(aIndex), aResult);
69 return NS_OK;
70 }
72 NS_IMETHODIMP
73 txNodeSetAdaptor::GetLength(uint32_t *aLength)
74 {
75 *aLength = (uint32_t)NodeSet()->size();
77 return NS_OK;
78 }
80 NS_IMETHODIMP
81 txNodeSetAdaptor::Add(nsIDOMNode *aNode)
82 {
83 NS_ENSURE_TRUE(mWritable, NS_ERROR_FAILURE);
85 nsAutoPtr<txXPathNode> node(txXPathNativeNode::createXPathNode(aNode,
86 true));
88 return node ? NodeSet()->add(*node) : NS_ERROR_OUT_OF_MEMORY;
89 }