Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/simpledb/SDBResults.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "SDBResults.h"
8
9
#include "nsContentUtils.h"
10
11
namespace mozilla {
12
namespace dom {
13
14
SDBResult::SDBResult(const nsACString& aData)
15
  : mData(aData)
16
0
{
17
0
}
18
19
NS_IMPL_ISUPPORTS(SDBResult,
20
                  nsISDBResult)
21
22
NS_IMETHODIMP
23
SDBResult::GetAsArray(uint32_t* aDataLen, uint8_t** aData)
24
0
{
25
0
  MOZ_ASSERT(aDataLen);
26
0
  MOZ_ASSERT(aData);
27
0
28
0
  if (mData.IsEmpty()) {
29
0
    *aDataLen = 0;
30
0
    *aData = nullptr;
31
0
    return NS_OK;
32
0
  }
33
0
34
0
  uint32_t length = mData.Length();
35
0
36
0
  uint8_t* data = static_cast<uint8_t*>(moz_xmalloc(length * sizeof(uint8_t)));
37
0
38
0
  memcpy(data, mData.BeginReading(), length * sizeof(uint8_t));
39
0
40
0
  *aDataLen = length;
41
0
  *aData = data;
42
0
  return NS_OK;
43
0
}
44
45
NS_IMETHODIMP
46
SDBResult::GetAsArrayBuffer(JSContext* aCx, JS::MutableHandleValue _retval)
47
0
{
48
0
  JS::Rooted<JSObject*> arrayBuffer(aCx);
49
0
  nsresult rv =
50
0
    nsContentUtils::CreateArrayBuffer(aCx, mData, arrayBuffer.address());
51
0
  if (NS_WARN_IF(NS_FAILED(rv))) {
52
0
    return rv;
53
0
  }
54
0
55
0
  _retval.setObject(*arrayBuffer);
56
0
  return NS_OK;
57
0
}
58
59
} // namespace dom
60
} // namespace mozilla