summaryrefslogtreecommitdiffstats
path: root/dom/xslt/xpath/txNodeSetAdaptor.cpp
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/xslt/xpath/txNodeSetAdaptor.cpp
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/xslt/xpath/txNodeSetAdaptor.cpp')
-rw-r--r--dom/xslt/xpath/txNodeSetAdaptor.cpp88
1 files changed, 88 insertions, 0 deletions
diff --git a/dom/xslt/xpath/txNodeSetAdaptor.cpp b/dom/xslt/xpath/txNodeSetAdaptor.cpp
new file mode 100644
index 000000000..2656c8dde
--- /dev/null
+++ b/dom/xslt/xpath/txNodeSetAdaptor.cpp
@@ -0,0 +1,88 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "txNodeSetAdaptor.h"
+#include "txXPathTreeWalker.h"
+
+txNodeSetAdaptor::txNodeSetAdaptor()
+ : txXPathObjectAdaptor(),
+ mWritable(true)
+{
+}
+
+txNodeSetAdaptor::txNodeSetAdaptor(txNodeSet *aNodeSet)
+ : txXPathObjectAdaptor(aNodeSet),
+ mWritable(false)
+{
+}
+
+NS_IMPL_ISUPPORTS_INHERITED(txNodeSetAdaptor, txXPathObjectAdaptor, txINodeSet)
+
+nsresult
+txNodeSetAdaptor::Init()
+{
+ if (!mValue) {
+ mValue = new txNodeSet(nullptr);
+ }
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+txNodeSetAdaptor::Item(uint32_t aIndex, nsIDOMNode **aResult)
+{
+ *aResult = nullptr;
+
+ if (aIndex > (uint32_t)NodeSet()->size()) {
+ return NS_ERROR_ILLEGAL_VALUE;
+ }
+
+ return txXPathNativeNode::getNode(NodeSet()->get(aIndex), aResult);
+}
+
+NS_IMETHODIMP
+txNodeSetAdaptor::ItemAsNumber(uint32_t aIndex, double *aResult)
+{
+ if (aIndex > (uint32_t)NodeSet()->size()) {
+ return NS_ERROR_ILLEGAL_VALUE;
+ }
+
+ nsAutoString result;
+ txXPathNodeUtils::appendNodeValue(NodeSet()->get(aIndex), result);
+
+ *aResult = txDouble::toDouble(result);
+
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+txNodeSetAdaptor::ItemAsString(uint32_t aIndex, nsAString &aResult)
+{
+ if (aIndex > (uint32_t)NodeSet()->size()) {
+ return NS_ERROR_ILLEGAL_VALUE;
+ }
+
+ txXPathNodeUtils::appendNodeValue(NodeSet()->get(aIndex), aResult);
+
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+txNodeSetAdaptor::GetLength(uint32_t *aLength)
+{
+ *aLength = (uint32_t)NodeSet()->size();
+
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+txNodeSetAdaptor::Add(nsIDOMNode *aNode)
+{
+ NS_ENSURE_TRUE(mWritable, NS_ERROR_FAILURE);
+
+ nsAutoPtr<txXPathNode> node(txXPathNativeNode::createXPathNode(aNode,
+ true));
+
+ return node ? NodeSet()->add(*node) : NS_ERROR_OUT_OF_MEMORY;
+}