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 "mozilla/dom/TypedArray.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
,
44 JS::MutableHandle
<JS::Value
> _retval
) {
46 JS::Rooted
<JSObject
*> arrayBuffer(aCx
, ArrayBuffer::Create(aCx
, mData
, rv
));
47 RETURN_NSRESULT_ON_FAILURE(rv
);
49 _retval
.setObject(*arrayBuffer
);
53 } // namespace mozilla::dom