2010-11-11 02:26:00 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 22:32:37 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2010-11-11 02:26:00 +03:00
|
|
|
|
|
|
|
#ifndef mozilla_dom_indexeddb_key_h__
|
|
|
|
#define mozilla_dom_indexeddb_key_h__
|
|
|
|
|
2019-07-29 12:05:44 +03:00
|
|
|
#include "mozilla/dom/indexedDB/IDBResult.h"
|
|
|
|
|
2019-12-11 09:17:44 +03:00
|
|
|
#include "js/Array.h" // JS::GetArrayLength
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "js/RootingAPI.h"
|
2019-07-29 12:05:44 +03:00
|
|
|
#include "jsapi.h"
|
|
|
|
#include "mozilla/ErrorResult.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "nsString.h"
|
2010-11-11 02:26:00 +03:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
class mozIStorageStatement;
|
2015-02-16 20:48:14 +03:00
|
|
|
class mozIStorageValueArray;
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-18 03:36:01 +04:00
|
|
|
namespace IPC {
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
template <typename>
|
|
|
|
struct ParamTraits;
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
} // namespace IPC
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
namespace indexedDB {
|
2010-11-11 02:26:00 +03:00
|
|
|
|
|
|
|
class Key {
|
2012-06-01 21:21:12 +04:00
|
|
|
friend struct IPC::ParamTraits<Key>;
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
nsCString mBuffer;
|
|
|
|
|
2010-11-11 02:26:00 +03:00
|
|
|
public:
|
2015-02-16 20:48:14 +03:00
|
|
|
enum {
|
|
|
|
eTerminator = 0,
|
|
|
|
eFloat = 0x10,
|
|
|
|
eDate = 0x20,
|
|
|
|
eString = 0x30,
|
2016-08-12 10:03:59 +03:00
|
|
|
eBinary = 0x40,
|
2015-02-16 20:48:14 +03:00
|
|
|
eArray = 0x50,
|
|
|
|
eMaxType = eArray
|
|
|
|
};
|
|
|
|
|
|
|
|
static const uint8_t kMaxArrayCollapse = uint8_t(3);
|
|
|
|
static const uint8_t kMaxRecursionDepth = uint8_t(64);
|
|
|
|
|
2011-11-03 19:57:30 +04:00
|
|
|
Key() { Unset(); }
|
2010-11-11 02:26:00 +03:00
|
|
|
|
2020-01-06 17:16:33 +03:00
|
|
|
explicit Key(nsCString aBuffer) : mBuffer(std::move(aBuffer)) {}
|
2015-02-16 20:48:14 +03:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
Key& operator=(int64_t aInt) {
|
2011-11-03 19:57:30 +04:00
|
|
|
SetFromInteger(aInt);
|
2010-11-11 02:26:00 +03:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
bool operator==(const Key& aOther) const {
|
2019-09-18 09:41:23 +03:00
|
|
|
MOZ_ASSERT(!mBuffer.IsVoid());
|
|
|
|
MOZ_ASSERT(!aOther.mBuffer.IsVoid());
|
2011-11-03 19:57:30 +04:00
|
|
|
|
2011-12-20 14:58:44 +04:00
|
|
|
return mBuffer.Equals(aOther.mBuffer);
|
2010-11-11 02:26:00 +03:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
bool operator!=(const Key& aOther) const {
|
2019-09-18 09:41:23 +03:00
|
|
|
MOZ_ASSERT(!mBuffer.IsVoid());
|
|
|
|
MOZ_ASSERT(!aOther.mBuffer.IsVoid());
|
2011-12-20 14:58:44 +04:00
|
|
|
|
|
|
|
return !mBuffer.Equals(aOther.mBuffer);
|
2010-11-11 02:26:00 +03:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
bool operator<(const Key& aOther) const {
|
2019-09-18 09:41:23 +03:00
|
|
|
MOZ_ASSERT(!mBuffer.IsVoid());
|
|
|
|
MOZ_ASSERT(!aOther.mBuffer.IsVoid());
|
2011-11-03 05:57:48 +04:00
|
|
|
|
2011-12-20 14:58:44 +04:00
|
|
|
return Compare(mBuffer, aOther.mBuffer) < 0;
|
2010-11-11 02:26:00 +03:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
bool operator>(const Key& aOther) const {
|
2019-09-18 09:41:23 +03:00
|
|
|
MOZ_ASSERT(!mBuffer.IsVoid());
|
|
|
|
MOZ_ASSERT(!aOther.mBuffer.IsVoid());
|
2011-12-20 14:58:44 +04:00
|
|
|
|
|
|
|
return Compare(mBuffer, aOther.mBuffer) > 0;
|
2010-11-11 02:26:00 +03:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
bool operator<=(const Key& aOther) const {
|
2019-09-18 09:41:23 +03:00
|
|
|
MOZ_ASSERT(!mBuffer.IsVoid());
|
|
|
|
MOZ_ASSERT(!aOther.mBuffer.IsVoid());
|
2011-12-20 14:58:44 +04:00
|
|
|
|
|
|
|
return Compare(mBuffer, aOther.mBuffer) <= 0;
|
2010-12-10 05:15:00 +03:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
bool operator>=(const Key& aOther) const {
|
2019-09-18 09:41:23 +03:00
|
|
|
MOZ_ASSERT(!mBuffer.IsVoid());
|
|
|
|
MOZ_ASSERT(!aOther.mBuffer.IsVoid());
|
2011-12-20 14:58:44 +04:00
|
|
|
|
|
|
|
return Compare(mBuffer, aOther.mBuffer) >= 0;
|
2010-12-10 05:15:00 +03:00
|
|
|
}
|
|
|
|
|
2011-12-20 14:58:44 +04:00
|
|
|
void Unset() { mBuffer.SetIsVoid(true); }
|
|
|
|
|
|
|
|
bool IsUnset() const { return mBuffer.IsVoid(); }
|
2011-11-03 19:57:30 +04:00
|
|
|
|
2015-02-16 20:48:14 +03:00
|
|
|
bool IsFloat() const { return !IsUnset() && *BufferStart() == eFloat; }
|
2013-03-16 10:58:50 +04:00
|
|
|
|
2015-02-16 20:48:14 +03:00
|
|
|
bool IsDate() const { return !IsUnset() && *BufferStart() == eDate; }
|
2013-03-16 10:58:50 +04:00
|
|
|
|
2015-02-16 20:48:14 +03:00
|
|
|
bool IsString() const { return !IsUnset() && *BufferStart() == eString; }
|
2013-03-16 10:58:50 +04:00
|
|
|
|
2016-08-12 10:03:59 +03:00
|
|
|
bool IsBinary() const { return !IsUnset() && *BufferStart() == eBinary; }
|
|
|
|
|
2015-02-16 20:48:14 +03:00
|
|
|
bool IsArray() const { return !IsUnset() && *BufferStart() >= eArray; }
|
2011-11-03 19:57:30 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
double ToFloat() const {
|
2019-09-18 09:41:23 +03:00
|
|
|
MOZ_ASSERT(IsFloat());
|
2019-07-30 17:52:04 +03:00
|
|
|
const EncodedDataType* pos = BufferStart();
|
2011-12-20 14:58:44 +04:00
|
|
|
double res = DecodeNumber(pos, BufferEnd());
|
2019-09-18 09:41:23 +03:00
|
|
|
MOZ_ASSERT(pos >= BufferEnd());
|
2011-12-20 14:58:44 +04:00
|
|
|
return res;
|
2011-11-03 19:57:30 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
double ToDateMsec() const {
|
2019-09-18 09:41:23 +03:00
|
|
|
MOZ_ASSERT(IsDate());
|
2019-07-30 17:52:04 +03:00
|
|
|
const EncodedDataType* pos = BufferStart();
|
2013-03-16 10:58:50 +04:00
|
|
|
double res = DecodeNumber(pos, BufferEnd());
|
2019-09-18 09:41:23 +03:00
|
|
|
MOZ_ASSERT(pos >= BufferEnd());
|
2013-03-16 10:58:50 +04:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void ToString(nsString& aString) const {
|
2019-09-18 09:41:23 +03:00
|
|
|
MOZ_ASSERT(IsString());
|
2019-07-30 17:52:04 +03:00
|
|
|
const EncodedDataType* pos = BufferStart();
|
2013-03-16 10:58:50 +04:00
|
|
|
DecodeString(pos, BufferEnd(), aString);
|
2019-09-18 09:41:23 +03:00
|
|
|
MOZ_ASSERT(pos >= BufferEnd());
|
2013-03-16 10:58:50 +04:00
|
|
|
}
|
|
|
|
|
2019-07-29 12:05:44 +03:00
|
|
|
IDBResult<void, IDBSpecialValue::Invalid> SetFromString(
|
|
|
|
const nsAString& aString, ErrorResult& aRv);
|
2011-12-20 14:58:44 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void SetFromInteger(int64_t aInt) {
|
2011-12-20 14:58:44 +04:00
|
|
|
mBuffer.Truncate();
|
|
|
|
EncodeNumber(double(aInt), eFloat);
|
|
|
|
TrimBuffer();
|
2011-11-03 19:57:30 +04:00
|
|
|
}
|
|
|
|
|
2019-07-29 12:05:44 +03:00
|
|
|
// This function implements the standard algorithm "convert a value to a key".
|
|
|
|
// A key return value is indicated by returning `true` whereas `false` means
|
|
|
|
// either invalid (if `aRv.Failed()` is `false`) or an exception (otherwise).
|
|
|
|
IDBResult<void, IDBSpecialValue::Invalid> SetFromJSVal(
|
|
|
|
JSContext* aCx, JS::Handle<JS::Value> aVal, ErrorResult& aRv);
|
2011-12-20 14:58:44 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
nsresult ToJSVal(JSContext* aCx, JS::MutableHandle<JS::Value> aVal) const;
|
2011-12-20 14:58:44 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
nsresult ToJSVal(JSContext* aCx, JS::Heap<JS::Value>& aVal) const;
|
2010-11-11 02:26:00 +03:00
|
|
|
|
2019-07-29 12:05:44 +03:00
|
|
|
// See SetFromJSVal() for the meaning of values returned by this function.
|
|
|
|
IDBResult<void, IDBSpecialValue::Invalid> AppendItem(
|
|
|
|
JSContext* aCx, bool aFirstOfArray, JS::Handle<JS::Value> aVal,
|
|
|
|
ErrorResult& aRv);
|
2013-06-18 14:00:37 +04:00
|
|
|
|
2019-09-18 09:41:35 +03:00
|
|
|
IDBResult<void, IDBSpecialValue::Invalid> ToLocaleAwareKey(
|
2019-07-29 12:05:44 +03:00
|
|
|
Key& aTarget, const nsCString& aLocale, ErrorResult& aRv) const;
|
2014-08-05 00:59:57 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void FinishArray() { TrimBuffer(); }
|
2011-12-20 14:59:07 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
const nsCString& GetBuffer() const { return mBuffer; }
|
2010-11-11 02:26:00 +03:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
nsresult BindToStatement(mozIStorageStatement* aStatement,
|
|
|
|
const nsACString& aParamName) const;
|
2011-11-03 19:57:30 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
nsresult SetFromStatement(mozIStorageStatement* aStatement, uint32_t aIndex);
|
2011-11-03 19:57:30 +04:00
|
|
|
|
2015-02-16 20:48:14 +03:00
|
|
|
nsresult SetFromValueArray(mozIStorageValueArray* aValues, uint32_t aIndex);
|
|
|
|
|
2016-02-27 00:58:47 +03:00
|
|
|
static int16_t CompareKeys(const Key& aFirst, const Key& aSecond) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t result = Compare(aFirst.mBuffer, aSecond.mBuffer);
|
2011-11-03 19:57:30 +04:00
|
|
|
|
2011-12-20 14:58:44 +04:00
|
|
|
if (result < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2011-11-03 19:57:30 +04:00
|
|
|
|
2011-12-20 14:58:44 +04:00
|
|
|
if (result > 0) {
|
|
|
|
return 1;
|
2011-11-03 19:57:30 +04:00
|
|
|
}
|
|
|
|
|
2011-12-20 14:58:44 +04:00
|
|
|
return 0;
|
2010-11-11 02:26:00 +03:00
|
|
|
}
|
|
|
|
|
2019-07-29 12:05:44 +03:00
|
|
|
// Implementation of the array branch of step 3 of
|
|
|
|
// https://w3c.github.io/IndexedDB/#convert-value-to-key
|
|
|
|
template <typename ArrayConversionPolicy>
|
|
|
|
static IDBResult<void, IDBSpecialValue::Invalid> ConvertArrayValueToKey(
|
|
|
|
JSContext* const aCx, JS::HandleObject aObject,
|
|
|
|
ArrayConversionPolicy&& aPolicy, ErrorResult& aRv) {
|
|
|
|
// 1. Let `len` be ? ToLength( ? Get(`input`, "length")).
|
|
|
|
uint32_t len;
|
2019-12-11 09:17:44 +03:00
|
|
|
if (!JS::GetArrayLength(aCx, aObject, &len)) {
|
2019-07-29 12:05:44 +03:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
return Exception;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 2. Add `input` to `seen`.
|
|
|
|
aPolicy.AddToSeenSet(aCx, aObject);
|
|
|
|
|
|
|
|
// 3. Let `keys` be a new empty list.
|
|
|
|
aPolicy.BeginSubkeyList();
|
|
|
|
|
|
|
|
// 4. Let `index` be 0.
|
|
|
|
uint32_t index = 0;
|
|
|
|
|
|
|
|
// 5. While `index` is less than `len`:
|
|
|
|
while (index < len) {
|
|
|
|
JS::RootedId indexId(aCx);
|
|
|
|
if (!JS_IndexToId(aCx, index, &indexId)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
return Exception;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 1. Let `hop` be ? HasOwnProperty(`input`, `index`).
|
|
|
|
bool hop;
|
|
|
|
if (!JS_HasOwnPropertyById(aCx, aObject, indexId, &hop)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
return Exception;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 2. If `hop` is false, return invalid.
|
|
|
|
if (!hop) {
|
|
|
|
return Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 3. Let `entry` be ? Get(`input`, `index`).
|
|
|
|
JS::RootedValue entry(aCx);
|
|
|
|
if (!JS_GetPropertyById(aCx, aObject, indexId, &entry)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
return Exception;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 4. Let `key` be the result of running the steps to convert a value to a
|
|
|
|
// key with arguments `entry` and `seen`.
|
|
|
|
// 5. ReturnIfAbrupt(`key`).
|
|
|
|
// 6. If `key` is invalid abort these steps and return invalid.
|
|
|
|
// 7. Append `key` to `keys`.
|
|
|
|
auto result = aPolicy.ConvertSubkey(aCx, entry, index, aRv);
|
|
|
|
if (!result.Is(Ok, aRv)) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 8. Increase `index` by 1.
|
|
|
|
index += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 6. Return a new array key with value `keys`.
|
|
|
|
aPolicy.EndSubkeyList();
|
|
|
|
return Ok();
|
|
|
|
}
|
|
|
|
|
2011-12-20 14:58:44 +04:00
|
|
|
private:
|
2019-07-29 12:05:44 +03:00
|
|
|
class MOZ_STACK_CLASS ArrayValueEncoder;
|
|
|
|
|
2019-07-30 17:52:04 +03:00
|
|
|
using EncodedDataType = unsigned char;
|
|
|
|
|
|
|
|
const EncodedDataType* BufferStart() const {
|
|
|
|
// TODO it would be nicer if mBuffer was also using EncodedDataType
|
|
|
|
return reinterpret_cast<const EncodedDataType*>(mBuffer.BeginReading());
|
2010-11-11 02:26:00 +03:00
|
|
|
}
|
|
|
|
|
2019-07-30 17:52:04 +03:00
|
|
|
const EncodedDataType* BufferEnd() const {
|
|
|
|
return reinterpret_cast<const EncodedDataType*>(mBuffer.EndReading());
|
2011-12-20 14:58:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Encoding helper. Trims trailing zeros off of mBuffer as a post-processing
|
|
|
|
// step.
|
2014-09-27 03:21:57 +04:00
|
|
|
void TrimBuffer() {
|
2011-12-20 14:58:44 +04:00
|
|
|
const char* end = mBuffer.EndReading() - 1;
|
|
|
|
while (!*end) {
|
|
|
|
--end;
|
|
|
|
}
|
2011-11-03 19:57:30 +04:00
|
|
|
|
2011-12-20 14:58:44 +04:00
|
|
|
mBuffer.Truncate(end + 1 - mBuffer.BeginReading());
|
|
|
|
}
|
2011-11-03 19:57:30 +04:00
|
|
|
|
2011-12-20 14:58:44 +04:00
|
|
|
// Encoding functions. These append the encoded value to the end of mBuffer
|
2019-07-29 12:05:44 +03:00
|
|
|
IDBResult<void, IDBSpecialValue::Invalid> EncodeJSVal(
|
|
|
|
JSContext* aCx, JS::Handle<JS::Value> aVal, uint8_t aTypeOffset,
|
|
|
|
ErrorResult& aRv);
|
2012-05-11 21:47:27 +04:00
|
|
|
|
2019-07-29 12:05:44 +03:00
|
|
|
IDBResult<void, IDBSpecialValue::Invalid> EncodeString(
|
|
|
|
const nsAString& aString, uint8_t aTypeOffset, ErrorResult& aRv);
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-08-05 00:59:57 +04:00
|
|
|
template <typename T>
|
2019-07-29 12:05:44 +03:00
|
|
|
IDBResult<void, IDBSpecialValue::Invalid> EncodeString(const T* aStart,
|
|
|
|
const T* aEnd,
|
|
|
|
uint8_t aTypeOffset,
|
|
|
|
ErrorResult& aRv);
|
2014-08-05 00:59:57 +04:00
|
|
|
|
2016-08-12 10:03:59 +03:00
|
|
|
template <typename T>
|
2019-07-29 12:05:44 +03:00
|
|
|
IDBResult<void, IDBSpecialValue::Invalid> EncodeAsString(const T* aStart,
|
|
|
|
const T* aEnd,
|
|
|
|
uint8_t aType,
|
|
|
|
ErrorResult& aRv);
|
2016-08-12 10:03:59 +03:00
|
|
|
|
2019-07-29 12:05:44 +03:00
|
|
|
IDBResult<void, IDBSpecialValue::Invalid> EncodeLocaleString(
|
|
|
|
const nsDependentString& aString, uint8_t aTypeOffset,
|
|
|
|
const nsCString& aLocale, ErrorResult& aRv);
|
2014-08-05 00:59:57 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void EncodeNumber(double aFloat, uint8_t aType);
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2019-07-29 12:05:44 +03:00
|
|
|
IDBResult<void, IDBSpecialValue::Invalid> EncodeBinary(JSObject* aObject,
|
|
|
|
bool aIsViewObject,
|
|
|
|
uint8_t aTypeOffset,
|
|
|
|
ErrorResult& aRv);
|
2016-08-12 10:03:59 +03:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// Decoding functions. aPos points into mBuffer and is adjusted to point
|
2019-07-30 17:51:40 +03:00
|
|
|
// past the consumed value. (Note: this may be beyond aEnd).
|
2019-07-30 17:52:04 +03:00
|
|
|
static nsresult DecodeJSVal(const EncodedDataType*& aPos,
|
|
|
|
const EncodedDataType* aEnd, JSContext* aCx,
|
2014-09-27 03:21:57 +04:00
|
|
|
JS::MutableHandle<JS::Value> aVal);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-30 17:52:04 +03:00
|
|
|
static void DecodeString(const EncodedDataType*& aPos,
|
|
|
|
const EncodedDataType* aEnd, nsString& aString);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-30 17:52:04 +03:00
|
|
|
static double DecodeNumber(const EncodedDataType*& aPos,
|
|
|
|
const EncodedDataType* aEnd);
|
2019-07-29 12:26:46 +03:00
|
|
|
|
2019-07-30 17:52:04 +03:00
|
|
|
static JSObject* DecodeBinary(const EncodedDataType*& aPos,
|
|
|
|
const EncodedDataType* aEnd, JSContext* aCx);
|
2019-07-29 12:26:46 +03:00
|
|
|
|
2019-07-30 17:51:40 +03:00
|
|
|
// Returns the size of the decoded data for stringy (string or binary),
|
|
|
|
// excluding a null terminator.
|
|
|
|
// On return, aOutSectionEnd points to the last byte behind the current
|
|
|
|
// encoded section, i.e. either aEnd, or the eTerminator.
|
|
|
|
// T is the base type for the decoded data.
|
|
|
|
template <typename T>
|
|
|
|
static uint32_t CalcDecodedStringySize(
|
2019-07-30 17:52:04 +03:00
|
|
|
const EncodedDataType* aBegin, const EncodedDataType* aEnd,
|
|
|
|
const EncodedDataType** aOutEncodedSectionEnd);
|
2019-07-30 17:51:40 +03:00
|
|
|
|
2019-07-30 17:52:18 +03:00
|
|
|
static uint32_t LengthOfEncodedBinary(const EncodedDataType* aPos,
|
|
|
|
const EncodedDataType* aEnd);
|
|
|
|
|
2019-07-30 17:51:40 +03:00
|
|
|
template <typename T>
|
2019-07-30 17:52:04 +03:00
|
|
|
static void DecodeAsStringy(const EncodedDataType* aEncodedSectionBegin,
|
|
|
|
const EncodedDataType* aEncodedSectionEnd,
|
2019-07-30 17:51:40 +03:00
|
|
|
uint32_t aDecodedLength, T* aOut);
|
|
|
|
|
2019-07-30 17:52:04 +03:00
|
|
|
template <EncodedDataType TypeMask, typename T, typename AcquireBuffer,
|
2019-07-30 17:51:40 +03:00
|
|
|
typename AcquireEmpty>
|
2019-07-30 17:52:04 +03:00
|
|
|
static void DecodeStringy(const EncodedDataType*& aPos,
|
|
|
|
const EncodedDataType* aEnd,
|
2019-07-30 17:51:40 +03:00
|
|
|
const AcquireBuffer& acquireBuffer,
|
|
|
|
const AcquireEmpty& acquireEmpty);
|
|
|
|
|
2019-07-29 12:05:44 +03:00
|
|
|
IDBResult<void, IDBSpecialValue::Invalid> EncodeJSValInternal(
|
|
|
|
JSContext* aCx, JS::Handle<JS::Value> aVal, uint8_t aTypeOffset,
|
|
|
|
uint16_t aRecursionDepth, ErrorResult& aRv);
|
2019-07-26 19:14:15 +03:00
|
|
|
|
2019-07-30 17:52:04 +03:00
|
|
|
static nsresult DecodeJSValInternal(const EncodedDataType*& aPos,
|
|
|
|
const EncodedDataType* aEnd,
|
|
|
|
JSContext* aCx, uint8_t aTypeOffset,
|
2014-09-27 03:21:57 +04:00
|
|
|
JS::MutableHandle<JS::Value> aVal,
|
|
|
|
uint16_t aRecursionDepth);
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2015-02-16 20:48:14 +03:00
|
|
|
template <typename T>
|
|
|
|
nsresult SetFromSource(T* aSource, uint32_t aIndex);
|
2010-11-11 02:26:00 +03:00
|
|
|
};
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
} // namespace indexedDB
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2010-11-11 02:26:00 +03:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
#endif // mozilla_dom_indexeddb_key_h__
|