Bug 1853814 [wpt PR 42017] - LoAF: Expose script URL for promise resolvers, a=testonly
[gecko.git] / dom / simpledb / SDBResults.cpp
blobe17f437988894790ba5c532f9c36dc16280603d7
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 "nsContentUtils.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 JS::Rooted<JSObject*> arrayBuffer(aCx);
46 nsresult rv =
47 nsContentUtils::CreateArrayBuffer(aCx, mData, arrayBuffer.address());
48 if (NS_WARN_IF(NS_FAILED(rv))) {
49 return rv;
52 _retval.setObject(*arrayBuffer);
53 return NS_OK;
56 } // namespace mozilla::dom