mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-01 17:23:59 +00:00
Bug 871846 - API changes for locale aware indexes. r=janv r=sicking
This commit is contained in:
parent
dd7ac5dc3c
commit
e493377d61
@ -64,6 +64,14 @@ IDBCursor::IDBCursor(Type aType,
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ENABLE_INTL_API
|
||||
bool
|
||||
IDBCursor::IsLocaleAware() const
|
||||
{
|
||||
return mSourceIndex && !mSourceIndex->Locale().IsEmpty();
|
||||
}
|
||||
#endif
|
||||
|
||||
IDBCursor::~IDBCursor()
|
||||
{
|
||||
AssertIsOnOwningThread();
|
||||
@ -117,6 +125,7 @@ IDBCursor::Create(BackgroundCursorChild* aBackgroundActor,
|
||||
already_AddRefed<IDBCursor>
|
||||
IDBCursor::Create(BackgroundCursorChild* aBackgroundActor,
|
||||
const Key& aKey,
|
||||
const Key& aSortKey,
|
||||
const Key& aPrimaryKey,
|
||||
StructuredCloneReadInfo&& aCloneInfo)
|
||||
{
|
||||
@ -130,6 +139,7 @@ IDBCursor::Create(BackgroundCursorChild* aBackgroundActor,
|
||||
nsRefPtr<IDBCursor> cursor =
|
||||
new IDBCursor(Type_Index, aBackgroundActor, aKey);
|
||||
|
||||
cursor->mSortKey = Move(aSortKey);
|
||||
cursor->mPrimaryKey = Move(aPrimaryKey);
|
||||
cursor->mCloneInfo = Move(aCloneInfo);
|
||||
|
||||
@ -140,6 +150,7 @@ IDBCursor::Create(BackgroundCursorChild* aBackgroundActor,
|
||||
already_AddRefed<IDBCursor>
|
||||
IDBCursor::Create(BackgroundCursorChild* aBackgroundActor,
|
||||
const Key& aKey,
|
||||
const Key& aSortKey,
|
||||
const Key& aPrimaryKey)
|
||||
{
|
||||
MOZ_ASSERT(aBackgroundActor);
|
||||
@ -152,6 +163,7 @@ IDBCursor::Create(BackgroundCursorChild* aBackgroundActor,
|
||||
nsRefPtr<IDBCursor> cursor =
|
||||
new IDBCursor(Type_IndexKey, aBackgroundActor, aKey);
|
||||
|
||||
cursor->mSortKey = Move(aSortKey);
|
||||
cursor->mPrimaryKey = Move(aPrimaryKey);
|
||||
|
||||
return cursor.forget();
|
||||
@ -309,7 +321,6 @@ IDBCursor::GetKey(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
AssertIsOnOwningThread();
|
||||
|
||||
MOZ_ASSERT(!mKey.IsUnset() || !mHaveValue);
|
||||
|
||||
if (!mHaveValue) {
|
||||
@ -428,11 +439,26 @@ IDBCursor::Continue(JSContext* aCx,
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_INTL_API
|
||||
if (IsLocaleAware() && !key.IsUnset()) {
|
||||
Key tmp;
|
||||
aRv = key.ToLocaleBasedKey(tmp, mSourceIndex->Locale());
|
||||
if (aRv.Failed()) {
|
||||
return;
|
||||
}
|
||||
key = tmp;
|
||||
}
|
||||
|
||||
const Key& sortKey = IsLocaleAware() ? mSortKey : mKey;
|
||||
#else
|
||||
const Key& sortKey = mKey;
|
||||
#endif
|
||||
|
||||
if (!key.IsUnset()) {
|
||||
switch (mDirection) {
|
||||
case NEXT:
|
||||
case NEXT_UNIQUE:
|
||||
if (key <= mKey) {
|
||||
if (key <= sortKey) {
|
||||
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
|
||||
return;
|
||||
}
|
||||
@ -440,7 +466,7 @@ IDBCursor::Continue(JSContext* aCx,
|
||||
|
||||
case PREV:
|
||||
case PREV_UNIQUE:
|
||||
if (key >= mKey) {
|
||||
if (key >= sortKey) {
|
||||
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
|
||||
return;
|
||||
}
|
||||
@ -781,6 +807,7 @@ IDBCursor::Reset(Key&& aKey)
|
||||
|
||||
void
|
||||
IDBCursor::Reset(Key&& aKey,
|
||||
Key&& aSortKey,
|
||||
Key&& aPrimaryKey,
|
||||
StructuredCloneReadInfo&& aValue)
|
||||
{
|
||||
@ -790,6 +817,7 @@ IDBCursor::Reset(Key&& aKey,
|
||||
Reset();
|
||||
|
||||
mKey = Move(aKey);
|
||||
mSortKey = Move(aSortKey);
|
||||
mPrimaryKey = Move(aPrimaryKey);
|
||||
mCloneInfo = Move(aValue);
|
||||
|
||||
@ -797,7 +825,9 @@ IDBCursor::Reset(Key&& aKey,
|
||||
}
|
||||
|
||||
void
|
||||
IDBCursor::Reset(Key&& aKey, Key&& aPrimaryKey)
|
||||
IDBCursor::Reset(Key&& aKey,
|
||||
Key&& aSortKey,
|
||||
Key&& aPrimaryKey)
|
||||
{
|
||||
AssertIsOnOwningThread();
|
||||
MOZ_ASSERT(mType == Type_IndexKey);
|
||||
@ -805,6 +835,7 @@ IDBCursor::Reset(Key&& aKey, Key&& aPrimaryKey)
|
||||
Reset();
|
||||
|
||||
mKey = Move(aKey);
|
||||
mSortKey = Move(aSortKey);
|
||||
mPrimaryKey = Move(aPrimaryKey);
|
||||
|
||||
mHaveValue = !mKey.IsUnset();
|
||||
|
@ -76,6 +76,7 @@ private:
|
||||
JS::Heap<JS::Value> mCachedValue;
|
||||
|
||||
Key mKey;
|
||||
Key mSortKey;
|
||||
Key mPrimaryKey;
|
||||
StructuredCloneReadInfo mCloneInfo;
|
||||
|
||||
@ -102,12 +103,14 @@ public:
|
||||
static already_AddRefed<IDBCursor>
|
||||
Create(BackgroundCursorChild* aBackgroundActor,
|
||||
const Key& aKey,
|
||||
const Key& aSortKey,
|
||||
const Key& aPrimaryKey,
|
||||
StructuredCloneReadInfo&& aCloneInfo);
|
||||
|
||||
static already_AddRefed<IDBCursor>
|
||||
Create(BackgroundCursorChild* aBackgroundActor,
|
||||
const Key& aKey,
|
||||
const Key& aSortKey,
|
||||
const Key& aPrimaryKey);
|
||||
|
||||
static Direction
|
||||
@ -169,10 +172,10 @@ public:
|
||||
Reset(Key&& aKey);
|
||||
|
||||
void
|
||||
Reset(Key&& aKey, Key&& aPrimaryKey, StructuredCloneReadInfo&& aValue);
|
||||
Reset(Key&& aKey, Key&& aSortKey, Key&& aPrimaryKey, StructuredCloneReadInfo&& aValue);
|
||||
|
||||
void
|
||||
Reset(Key&& aKey, Key&& aPrimaryKey);
|
||||
Reset(Key&& aKey, Key&& aSortKey, Key&& aPrimaryKey);
|
||||
|
||||
void
|
||||
ClearBackgroundActor()
|
||||
@ -196,6 +199,12 @@ private:
|
||||
|
||||
~IDBCursor();
|
||||
|
||||
#ifdef ENABLE_INTL_API
|
||||
// Checks if this is a locale aware cursor (ie. the index's sortKey is unset)
|
||||
bool
|
||||
IsLocaleAware() const;
|
||||
#endif
|
||||
|
||||
void
|
||||
DropJSObjects();
|
||||
|
||||
|
@ -168,6 +168,15 @@ IDBIndex::MultiEntry() const
|
||||
return mMetadata->multiEntry();
|
||||
}
|
||||
|
||||
bool
|
||||
IDBIndex::LocaleAware() const
|
||||
{
|
||||
AssertIsOnOwningThread();
|
||||
MOZ_ASSERT(mMetadata);
|
||||
|
||||
return mMetadata->locale().IsEmpty();
|
||||
}
|
||||
|
||||
const KeyPath&
|
||||
IDBIndex::GetKeyPath() const
|
||||
{
|
||||
@ -177,6 +186,37 @@ IDBIndex::GetKeyPath() const
|
||||
return mMetadata->keyPath();
|
||||
}
|
||||
|
||||
void
|
||||
IDBIndex::GetLocale(nsString& aLocale) const
|
||||
{
|
||||
AssertIsOnOwningThread();
|
||||
MOZ_ASSERT(mMetadata);
|
||||
|
||||
if (mMetadata->locale().IsEmpty()) {
|
||||
SetDOMStringToNull(aLocale);
|
||||
} else {
|
||||
aLocale.AssignWithConversion(mMetadata->locale());
|
||||
}
|
||||
}
|
||||
|
||||
const nsCString&
|
||||
IDBIndex::Locale() const
|
||||
{
|
||||
AssertIsOnOwningThread();
|
||||
MOZ_ASSERT(mMetadata);
|
||||
|
||||
return mMetadata->locale();
|
||||
}
|
||||
|
||||
bool
|
||||
IDBIndex::IsAutoLocale() const
|
||||
{
|
||||
AssertIsOnOwningThread();
|
||||
MOZ_ASSERT(mMetadata);
|
||||
|
||||
return mMetadata->autoLocale();
|
||||
}
|
||||
|
||||
nsPIDOMWindow*
|
||||
IDBIndex::GetParentObject() const
|
||||
{
|
||||
@ -249,21 +289,15 @@ IDBIndex::GetInternal(bool aKeyOnly,
|
||||
const int64_t objectStoreId = mObjectStore->Id();
|
||||
const int64_t indexId = Id();
|
||||
|
||||
OptionalKeyRange optionalKeyRange;
|
||||
if (keyRange) {
|
||||
SerializedKeyRange serializedKeyRange;
|
||||
keyRange->ToSerialized(serializedKeyRange);
|
||||
optionalKeyRange = serializedKeyRange;
|
||||
} else {
|
||||
optionalKeyRange = void_t();
|
||||
}
|
||||
SerializedKeyRange serializedKeyRange;
|
||||
keyRange->ToSerialized(serializedKeyRange);
|
||||
|
||||
RequestParams params;
|
||||
|
||||
if (aKeyOnly) {
|
||||
params = IndexGetKeyParams(objectStoreId, indexId, optionalKeyRange);
|
||||
params = IndexGetKeyParams(objectStoreId, indexId, serializedKeyRange);
|
||||
} else {
|
||||
params = IndexGetParams(objectStoreId, indexId, optionalKeyRange);
|
||||
params = IndexGetParams(objectStoreId, indexId, serializedKeyRange);
|
||||
}
|
||||
|
||||
nsRefPtr<IDBRequest> request = GenerateRequest(this);
|
||||
|
@ -76,9 +76,21 @@ public:
|
||||
bool
|
||||
MultiEntry() const;
|
||||
|
||||
bool
|
||||
LocaleAware() const;
|
||||
|
||||
const KeyPath&
|
||||
GetKeyPath() const;
|
||||
|
||||
void
|
||||
GetLocale(nsString& aLocale) const;
|
||||
|
||||
const nsCString&
|
||||
Locale() const;
|
||||
|
||||
bool
|
||||
IsAutoLocale() const;
|
||||
|
||||
IDBObjectStore*
|
||||
ObjectStore() const
|
||||
{
|
||||
|
@ -606,8 +606,13 @@ nsresult
|
||||
Key::BindToStatement(mozIStorageStatement* aStatement,
|
||||
const nsACString& aParamName) const
|
||||
{
|
||||
nsresult rv = aStatement->BindBlobByName(aParamName,
|
||||
reinterpret_cast<const uint8_t*>(mBuffer.get()), mBuffer.Length());
|
||||
nsresult rv;
|
||||
if (IsUnset()) {
|
||||
rv = aStatement->BindNullByName(aParamName);
|
||||
} else {
|
||||
rv = aStatement->BindBlobByName(aParamName,
|
||||
reinterpret_cast<const uint8_t*>(mBuffer.get()), mBuffer.Length());
|
||||
}
|
||||
|
||||
return NS_SUCCEEDED(rv) ? NS_OK : NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
||||
}
|
||||
|
@ -10,6 +10,12 @@
|
||||
dictionary IDBIndexParameters {
|
||||
boolean unique = false;
|
||||
boolean multiEntry = false;
|
||||
// <null>: Not locale-aware, uses normal JS sorting.
|
||||
// <string>: Always sorted based on the rules of the specified
|
||||
// locale (e.g. "en-US", etc.).
|
||||
// "auto": Sorted by the platform default, may change based on
|
||||
// user agent options.
|
||||
DOMString? locale = null;
|
||||
};
|
||||
|
||||
[Exposed=(Window,Worker)]
|
||||
@ -23,6 +29,15 @@ interface IDBIndex {
|
||||
readonly attribute boolean multiEntry;
|
||||
readonly attribute boolean unique;
|
||||
|
||||
// <null>: Not locale-aware, uses normal JS sorting.
|
||||
// <string>: Sorted based on the rules of the specified locale.
|
||||
// Note: never returns "auto", only the current locale.
|
||||
[Func="mozilla::dom::indexedDB::IndexedDatabaseManager::ExperimentalFeaturesEnabled"]
|
||||
readonly attribute DOMString? locale;
|
||||
|
||||
[Func="mozilla::dom::indexedDB::IndexedDatabaseManager::ExperimentalFeaturesEnabled"]
|
||||
readonly attribute boolean isAutoLocale;
|
||||
|
||||
[Throws]
|
||||
IDBRequest openCursor (optional any range, optional IDBCursorDirection direction = "next");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user