From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- dom/indexedDB/IndexedDatabaseInlines.h | 182 +++++++++++++++++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 dom/indexedDB/IndexedDatabaseInlines.h (limited to 'dom/indexedDB/IndexedDatabaseInlines.h') diff --git a/dom/indexedDB/IndexedDatabaseInlines.h b/dom/indexedDB/IndexedDatabaseInlines.h new file mode 100644 index 0000000000..92782f3202 --- /dev/null +++ b/dom/indexedDB/IndexedDatabaseInlines.h @@ -0,0 +1,182 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef IndexedDatabaseInlines_h +#define IndexedDatabaseInlines_h + +#ifndef mozilla_dom_indexeddatabase_h__ +# error Must include IndexedDatabase.h first +#endif + +#include "DatabaseFileInfo.h" +#include "mozilla/dom/ToJSValue.h" +#include "mozilla/dom/indexedDB/PBackgroundIDBSharedTypes.h" +#include "mozilla/dom/DOMStringList.h" +#include "mozilla/dom/File.h" + +namespace mozilla::dom::indexedDB { + +#ifdef NS_BUILD_REFCNT_LOGGING +inline StructuredCloneFileChild::StructuredCloneFileChild( + StructuredCloneFileChild&& aOther) + : StructuredCloneFileBase{std::move(aOther)}, + mContents{std::move(aOther.mContents)} { + MOZ_COUNT_CTOR(StructuredCloneFileChild); +} +#endif + +inline StructuredCloneFileChild::~StructuredCloneFileChild() { + MOZ_COUNT_DTOR(StructuredCloneFileChild); +} + +inline StructuredCloneFileChild::StructuredCloneFileChild(FileType aType) + : StructuredCloneFileBase{aType}, mContents{Nothing()} { + MOZ_COUNT_CTOR(StructuredCloneFileChild); +} + +inline StructuredCloneFileChild::StructuredCloneFileChild( + FileType aType, RefPtr aBlob) + : StructuredCloneFileBase{aType}, mContents{std::move(aBlob)} { + MOZ_ASSERT(eBlob == aType || eStructuredClone == aType); + MOZ_ASSERT(mContents->as>()); + MOZ_COUNT_CTOR(StructuredCloneFileChild); +} + +inline StructuredCloneFileParent::StructuredCloneFileParent( + FileType aType, SafeRefPtr aFileInfo) + : StructuredCloneFileBase{aType}, mContents{Some(std::move(aFileInfo))} { + MOZ_ASSERT(**mContents); + MOZ_COUNT_CTOR(StructuredCloneFileParent); +} + +#ifdef NS_BUILD_REFCNT_LOGGING +inline StructuredCloneFileParent::StructuredCloneFileParent( + StructuredCloneFileParent&& aOther) + : StructuredCloneFileBase{std::move(aOther)}, + mContents{std::move(aOther.mContents)} { + MOZ_COUNT_CTOR(StructuredCloneFileParent); +} +#endif + +inline StructuredCloneFileParent::~StructuredCloneFileParent() { + MOZ_COUNT_DTOR(StructuredCloneFileParent); +} + +inline SafeRefPtr StructuredCloneFileParent::FileInfoPtr() + const { + return (*mContents)->clonePtr(); +} + +inline RefPtr StructuredCloneFileChild::BlobPtr() const { + return mContents->as>(); +} + +template +inline StructuredCloneReadInfo::StructuredCloneReadInfo( + JS::StructuredCloneScope aScope) + : StructuredCloneReadInfoBase(JSStructuredCloneData{aScope}) { + MOZ_COUNT_CTOR(StructuredCloneReadInfo); +} + +template +inline StructuredCloneReadInfo::StructuredCloneReadInfo() + : StructuredCloneReadInfo( + JS::StructuredCloneScope::DifferentProcessForIndexedDB) {} + +template +inline StructuredCloneReadInfo::StructuredCloneReadInfo( + JSStructuredCloneData&& aData, nsTArray aFiles) + : StructuredCloneReadInfoBase{std::move(aData)}, mFiles{std::move(aFiles)} { + MOZ_COUNT_CTOR(StructuredCloneReadInfo); +} + +#ifdef NS_BUILD_REFCNT_LOGGING +template +inline StructuredCloneReadInfo::StructuredCloneReadInfo( + StructuredCloneReadInfo&& aOther) noexcept + : StructuredCloneReadInfoBase{std::move(aOther)}, + mFiles{std::move(aOther.mFiles)} { + MOZ_COUNT_CTOR(StructuredCloneReadInfo); +} + +template +inline StructuredCloneReadInfo< + StructuredCloneFile>::~StructuredCloneReadInfo() { + MOZ_COUNT_DTOR(StructuredCloneReadInfo); +} + +#endif + +template +inline size_t StructuredCloneReadInfo::Size() const { + size_t size = Data().Size(); + + for (uint32_t i = 0, count = mFiles.Length(); i < count; ++i) { + // We don't want to calculate the size of files and so on, because are + // mainly file descriptors. + size += sizeof(uint64_t); + } + + return size; +} + +inline StructuredCloneReadInfoChild::StructuredCloneReadInfoChild( + JSStructuredCloneData&& aData, nsTArray aFiles, + IDBDatabase* aDatabase) + : StructuredCloneReadInfo{std::move(aData), std::move(aFiles)}, + mDatabase{aDatabase} {} + +template +RefPtr CreateSortedDOMStringList(const nsTArray& aArray, + const Map& aMap) { + auto list = MakeRefPtr(); + + if (!aArray.IsEmpty()) { + nsTArray& mapped = list->StringArray(); + mapped.SetCapacity(aArray.Length()); + + std::transform(aArray.cbegin(), aArray.cend(), MakeBackInserter(mapped), + aMap); + + mapped.Sort(); + } + + return list; +} + +template +JSObject* StructuredCloneReadCallback( + JSContext* const aCx, JSStructuredCloneReader* const aReader, + const JS::CloneDataPolicy& aCloneDataPolicy, const uint32_t aTag, + const uint32_t aData, void* const aClosure) { + auto* const database = [aClosure]() -> IDBDatabase* { + if constexpr (std::is_same_v) { + return static_cast(aClosure)->Database(); + } + Unused << aClosure; + return nullptr; + }(); + return CommonStructuredCloneReadCallback( + aCx, aReader, aCloneDataPolicy, aTag, aData, + static_cast(aClosure), database); +} + +template +bool WrapAsJSObject(JSContext* const aCx, T& aBaseObject, + JS::MutableHandle aResult) { + JS::Rooted wrappedValue(aCx); + if (!ToJSValue(aCx, aBaseObject, &wrappedValue)) { + return false; + } + + aResult.set(&wrappedValue.toObject()); + return true; +} + +} // namespace mozilla::dom::indexedDB + +#endif // IndexedDatabaseInlines_h -- cgit v1.2.3