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"
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 "nsContentUtils.h"
24 namespace mozilla::dom
{
26 SDBResult::SDBResult(const nsACString
& aData
) : mData(aData
) {}
28 NS_IMPL_ISUPPORTS(SDBResult
, nsISDBResult
)
31 SDBResult::GetAsArray(nsTArray
<uint8_t>& aData
) {
32 uint32_t length
= mData
.Length();
33 aData
.SetLength(length
);
36 memcpy(aData
.Elements(), mData
.BeginReading(), length
* sizeof(uint8_t));
43 SDBResult::GetAsArrayBuffer(JSContext
* aCx
, JS::MutableHandleValue _retval
) {
44 JS::Rooted
<JSObject
*> arrayBuffer(aCx
);
46 nsContentUtils::CreateArrayBuffer(aCx
, mData
, arrayBuffer
.address());
47 if (NS_WARN_IF(NS_FAILED(rv
))) {
51 _retval
.setObject(*arrayBuffer
);
55 } // namespace mozilla::dom