no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / dom / simpledb / SDBResults.cpp
blob9acac0fdc7bbdd56d4ffe0c3139bab11ce84ec05
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/. */
7 #include "SDBResults.h"
9 #include <cstdint>
10 #include <cstring>
11 #include <new>
12 #include <utility>
13 #include "ErrorList.h"
14 #include "js/RootingAPI.h"
15 #include "js/TypeDecls.h"
16 #include "mozilla/Assertions.h"
17 #include "mozilla/MacroForEach.h"
18 #include "mozilla/dom/TypedArray.h"
19 #include "nsDebug.h"
20 #include "nsError.h"
21 #include "nsTArray.h"
22 #include "nscore.h"
24 namespace mozilla::dom {
26 SDBResult::SDBResult(const nsACString& aData) : mData(aData) {}
28 NS_IMPL_ISUPPORTS(SDBResult, nsISDBResult)
30 NS_IMETHODIMP
31 SDBResult::GetAsArray(nsTArray<uint8_t>& aData) {
32 uint32_t length = mData.Length();
33 aData.SetLength(length);
35 if (length != 0) {
36 memcpy(aData.Elements(), mData.BeginReading(), length * sizeof(uint8_t));
39 return NS_OK;
42 NS_IMETHODIMP
43 SDBResult::GetAsArrayBuffer(JSContext* aCx,
44 JS::MutableHandle<JS::Value> _retval) {
45 ErrorResult rv;
46 JS::Rooted<JSObject*> arrayBuffer(aCx, ArrayBuffer::Create(aCx, mData, rv));
47 ENSURE_SUCCESS(rv, rv.StealNSResult());
49 _retval.setObject(*arrayBuffer);
50 return NS_OK;
53 } // namespace mozilla::dom