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/KeyPath.h | 120 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 dom/indexedDB/KeyPath.h (limited to 'dom/indexedDB/KeyPath.h') diff --git a/dom/indexedDB/KeyPath.h b/dom/indexedDB/KeyPath.h new file mode 100644 index 0000000000..4e1042650f --- /dev/null +++ b/dom/indexedDB/KeyPath.h @@ -0,0 +1,120 @@ +/* -*- 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 mozilla_dom_indexeddb_keypath_h__ +#define mozilla_dom_indexeddb_keypath_h__ + +#include +#include +#include "js/TypeDecls.h" +#include "mozilla/Result.h" +#include "mozilla/ipc/IPCForwards.h" +#include "nsISupports.h" +#include "nsError.h" +#include "nsString.h" +#include "nsTArray.h" + +namespace JS { +template +class Heap; +} + +namespace mozilla::dom { + +class OwningStringOrStringSequence; +template +class Sequence; +template +struct Nullable; + +namespace indexedDB { + +class IndexMetadata; +class Key; +class ObjectStoreMetadata; + +class KeyPath { + // This private constructor is only to be used by IPDL-generated classes. + friend class IndexMetadata; + friend class ObjectStoreMetadata; + ALLOW_DEPRECATED_READPARAM + + KeyPath() : mType(KeyPathType::NonExistent) { MOZ_COUNT_CTOR(KeyPath); } + + public: + enum class KeyPathType { NonExistent, String, Array, EndGuard }; + + void SetType(KeyPathType aType); + + bool AppendStringWithValidation(const nsAString& aString); + + explicit KeyPath(int aDummy) : mType(KeyPathType::NonExistent) { + MOZ_COUNT_CTOR(KeyPath); + } + + KeyPath(KeyPath&& aOther) { + MOZ_COUNT_CTOR(KeyPath); + *this = std::move(aOther); + } + KeyPath& operator=(KeyPath&&) = default; + + KeyPath(const KeyPath& aOther) { + MOZ_COUNT_CTOR(KeyPath); + *this = aOther; + } + KeyPath& operator=(const KeyPath&) = default; + + MOZ_COUNTED_DTOR(KeyPath) + + static Result Parse(const nsAString& aString); + + static Result Parse(const Sequence& aStrings); + + static Result Parse( + const Nullable& aValue); + + nsresult ExtractKey(JSContext* aCx, const JS::Value& aValue, Key& aKey) const; + + nsresult ExtractKeyAsJSVal(JSContext* aCx, const JS::Value& aValue, + JS::Value* aOutVal) const; + + using ExtractOrCreateKeyCallback = nsresult (*)(JSContext*, void*); + + nsresult ExtractOrCreateKey(JSContext* aCx, const JS::Value& aValue, + Key& aKey, ExtractOrCreateKeyCallback aCallback, + void* aClosure) const; + + inline bool IsValid() const { return mType != KeyPathType::NonExistent; } + + inline bool IsArray() const { return mType == KeyPathType::Array; } + + inline bool IsString() const { return mType == KeyPathType::String; } + + inline bool IsEmpty() const { + return mType == KeyPathType::String && mStrings[0].IsEmpty(); + } + + bool operator==(const KeyPath& aOther) const { + return mType == aOther.mType && mStrings == aOther.mStrings; + } + + nsAutoString SerializeToString() const; + static KeyPath DeserializeFromString(const nsAString& aString); + + nsresult ToJSVal(JSContext* aCx, JS::MutableHandle aValue) const; + nsresult ToJSVal(JSContext* aCx, JS::Heap& aValue) const; + + bool IsAllowedForObjectStore(bool aAutoIncrement) const; + + KeyPathType mType; + + CopyableTArray mStrings; +}; + +} // namespace indexedDB +} // namespace mozilla::dom + +#endif // mozilla_dom_indexeddb_keypath_h__ -- cgit v1.2.3