Bug 1535397 - Part 5 - use native Maybe syntax in place of OptionalKeyRange in IDPL; r=baku
authorAlex Gaynor <agaynor@mozilla.com>
Fri, 15 Mar 2019 17:39:59 +0000
changeset 464645 11017d53d6bdf6e55c1ad181b930aee6589819da
parent 464644 533d85bbc15d7b58b523f337e8111ee013a720fa
child 464646 7a382dbe8dc831fa75b4f2ad011f35378068386f
push id112465
push useraciure@mozilla.com
push dateSun, 17 Mar 2019 09:50:10 +0000
treeherdermozilla-inbound@e0861be8d6c0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1535397
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1535397 - Part 5 - use native Maybe syntax in place of OptionalKeyRange in IDPL; r=baku Differential Revision: https://phabricator.services.mozilla.com/D23562
dom/indexedDB/ActorsParent.cpp
dom/indexedDB/IDBIndex.cpp
dom/indexedDB/IDBObjectStore.cpp
dom/indexedDB/PBackgroundIDBSharedTypes.ipdlh
--- a/dom/indexedDB/ActorsParent.cpp
+++ b/dom/indexedDB/ActorsParent.cpp
@@ -5401,17 +5401,17 @@ class DatabaseOperationBase : public Run
       const FallibleTArray<IndexDataValue>& aIndexValues);
 
   static nsresult DeleteIndexDataTableRows(
       DatabaseConnection* aConnection, const Key& aObjectStoreKey,
       const FallibleTArray<IndexDataValue>& aIndexValues);
 
   static nsresult DeleteObjectStoreDataTableRowsWithIndexes(
       DatabaseConnection* aConnection, const int64_t aObjectStoreId,
-      const OptionalKeyRange& aKeyRange);
+      const Maybe<SerializedKeyRange>& aKeyRange);
 
   static nsresult UpdateIndexValues(
       DatabaseConnection* aConnection, const int64_t aObjectStoreId,
       const Key& aObjectStoreKey,
       const FallibleTArray<IndexDataValue>& aIndexValues);
 
   static nsresult ObjectStoreHasIndexes(DatabaseConnection* aConnection,
                                         const int64_t aObjectStoreId,
@@ -6221,17 +6221,17 @@ class TransactionBase {
 
  private:
   bool VerifyRequestParams(const RequestParams& aParams) const;
 
   bool VerifyRequestParams(const SerializedKeyRange& aKeyRange) const;
 
   bool VerifyRequestParams(const ObjectStoreAddPutParams& aParams) const;
 
-  bool VerifyRequestParams(const OptionalKeyRange& aKeyRange) const;
+  bool VerifyRequestParams(const Maybe<SerializedKeyRange>& aKeyRange) const;
 
   void CommitOrAbort();
 };
 
 class TransactionBase::CommitOp final : public DatabaseOperationBase,
                                         public ConnectionPool::FinishCallback {
   friend class TransactionBase;
 
@@ -7242,17 +7242,17 @@ class ObjectStoreAddOrPutRequestOp::SCIn
   NS_DECL_NSIINPUTSTREAM
 };
 
 class ObjectStoreGetRequestOp final : public NormalTransactionOp {
   friend class TransactionBase;
 
   const uint32_t mObjectStoreId;
   RefPtr<Database> mDatabase;
-  const OptionalKeyRange mOptionalKeyRange;
+  const Maybe<SerializedKeyRange> mOptionalKeyRange;
   AutoTArray<StructuredCloneReadInfo, 1> mResponse;
   PBackgroundParent* mBackgroundParent;
   uint32_t mPreprocessInfoCount;
   const uint32_t mLimit;
   const bool mGetAll;
 
  private:
   // Only created by TransactionBase.
@@ -7272,17 +7272,17 @@ class ObjectStoreGetRequestOp final : pu
 
   void GetResponse(RequestResponse& aResponse, size_t* aResponseSize) override;
 };
 
 class ObjectStoreGetKeyRequestOp final : public NormalTransactionOp {
   friend class TransactionBase;
 
   const uint32_t mObjectStoreId;
-  const OptionalKeyRange mOptionalKeyRange;
+  const Maybe<SerializedKeyRange> mOptionalKeyRange;
   const uint32_t mLimit;
   const bool mGetAll;
   FallibleTArray<Key> mResponse;
 
  private:
   // Only created by TransactionBase.
   ObjectStoreGetKeyRequestOp(TransactionBase* aTransaction,
                              const RequestParams& aParams, bool aGetAll);
@@ -7373,17 +7373,17 @@ class IndexRequestOpBase : public Normal
   static already_AddRefed<FullIndexMetadata> IndexMetadataForParams(
       TransactionBase* aTransaction, const RequestParams& aParams);
 };
 
 class IndexGetRequestOp final : public IndexRequestOpBase {
   friend class TransactionBase;
 
   RefPtr<Database> mDatabase;
-  const OptionalKeyRange mOptionalKeyRange;
+  const Maybe<SerializedKeyRange> mOptionalKeyRange;
   AutoTArray<StructuredCloneReadInfo, 1> mResponse;
   PBackgroundParent* mBackgroundParent;
   const uint32_t mLimit;
   const bool mGetAll;
 
  private:
   // Only created by TransactionBase.
   IndexGetRequestOp(TransactionBase* aTransaction, const RequestParams& aParams,
@@ -7394,17 +7394,17 @@ class IndexGetRequestOp final : public I
   nsresult DoDatabaseWork(DatabaseConnection* aConnection) override;
 
   void GetResponse(RequestResponse& aResponse, size_t* aResponseSize) override;
 };
 
 class IndexGetKeyRequestOp final : public IndexRequestOpBase {
   friend class TransactionBase;
 
-  const OptionalKeyRange mOptionalKeyRange;
+  const Maybe<SerializedKeyRange> mOptionalKeyRange;
   AutoTArray<Key, 1> mResponse;
   const uint32_t mLimit;
   const bool mGetAll;
 
  private:
   // Only created by TransactionBase.
   IndexGetKeyRequestOp(TransactionBase* aTransaction,
                        const RequestParams& aParams, bool aGetAll);
@@ -7550,21 +7550,21 @@ class Cursor::CursorOpBase : public Tran
 
   nsresult PopulateResponseFromStatement(
       DatabaseConnection::CachedStatement& aStmt, bool aInitializeResponse);
 };
 
 class Cursor::OpenOp final : public Cursor::CursorOpBase {
   friend class Cursor;
 
-  const OptionalKeyRange mOptionalKeyRange;
+  const Maybe<SerializedKeyRange> mOptionalKeyRange;
 
  private:
   // Only created by Cursor.
-  OpenOp(Cursor* aCursor, const OptionalKeyRange& aOptionalKeyRange)
+  OpenOp(Cursor* aCursor, const Maybe<SerializedKeyRange>& aOptionalKeyRange)
       : CursorOpBase(aCursor), mOptionalKeyRange(aOptionalKeyRange) {}
 
   // Reference counted.
   ~OpenOp() override = default;
 
   void GetRangeKeyInfo(bool aLowerBound, Key* aKey, bool* aOpen);
 
   nsresult DoObjectStoreDatabaseWork(DatabaseConnection* aConnection);
@@ -13788,33 +13788,24 @@ bool TransactionBase::VerifyRequestParam
         MOZ_CRASH("Should never get here!");
     }
   }
 
   return true;
 }
 
 bool TransactionBase::VerifyRequestParams(
-    const OptionalKeyRange& aParams) const {
-  AssertIsOnBackgroundThread();
-  MOZ_ASSERT(aParams.type() != OptionalKeyRange::T__None);
-
-  switch (aParams.type()) {
-    case OptionalKeyRange::TSerializedKeyRange:
-      if (NS_WARN_IF(!VerifyRequestParams(aParams.get_SerializedKeyRange()))) {
-        ASSERT_UNLESS_FUZZING();
-        return false;
-      }
-      break;
-
-    case OptionalKeyRange::Tvoid_t:
-      break;
-
-    default:
-      MOZ_CRASH("Should never get here!");
+    const Maybe<SerializedKeyRange>& aParams) const {
+  AssertIsOnBackgroundThread();
+
+  if (aParams.isSome()) {
+    if (NS_WARN_IF(!VerifyRequestParams(aParams.ref()))) {
+      ASSERT_UNLESS_FUZZING();
+      return false;
+    }
   }
 
   return true;
 }
 
 void TransactionBase::NoteActiveRequest() {
   AssertIsOnBackgroundThread();
   MOZ_ASSERT(mActiveRequestCount < UINT64_MAX);
@@ -15036,17 +15027,17 @@ bool Cursor::Start(const OpenCursorParam
   MOZ_ASSERT(aParams.type() == mType);
   MOZ_ASSERT(!mActorDestroyed);
 
   if (NS_WARN_IF(mCurrentlyRunningOp)) {
     ASSERT_UNLESS_FUZZING();
     return false;
   }
 
-  const OptionalKeyRange& optionalKeyRange =
+  const Maybe<SerializedKeyRange>& optionalKeyRange =
       mType == OpenCursorParams::TObjectStoreOpenCursorParams
           ? aParams.get_ObjectStoreOpenCursorParams().optionalKeyRange()
           : mType == OpenCursorParams::TObjectStoreOpenKeyCursorParams
                 ? aParams.get_ObjectStoreOpenKeyCursorParams()
                       .optionalKeyRange()
                 : mType == OpenCursorParams::TIndexOpenCursorParams
                       ? aParams.get_IndexOpenCursorParams().optionalKeyRange()
                       : aParams.get_IndexOpenKeyCursorParams()
@@ -18525,17 +18516,17 @@ nsresult DatabaseOperationBase::DeleteIn
   }
 
   return NS_OK;
 }
 
 // static
 nsresult DatabaseOperationBase::DeleteObjectStoreDataTableRowsWithIndexes(
     DatabaseConnection* aConnection, const int64_t aObjectStoreId,
-    const OptionalKeyRange& aKeyRange) {
+    const Maybe<SerializedKeyRange>& aKeyRange) {
   MOZ_ASSERT(aConnection);
   aConnection->AssertIsOnConnectionThread();
   MOZ_ASSERT(aObjectStoreId);
 
 #ifdef DEBUG
   {
     bool hasIndexes = false;
     MOZ_ASSERT(NS_SUCCEEDED(
@@ -18543,19 +18534,17 @@ nsresult DatabaseOperationBase::DeleteOb
     MOZ_ASSERT(hasIndexes,
                "Don't use this slow method if there are no indexes!");
   }
 #endif
 
   AUTO_PROFILER_LABEL(
       "DatabaseOperationBase::DeleteObjectStoreDataTableRowsWithIndexes", DOM);
 
-  const bool singleRowOnly =
-      aKeyRange.type() == OptionalKeyRange::TSerializedKeyRange &&
-      aKeyRange.get_SerializedKeyRange().isOnly();
+  const bool singleRowOnly = aKeyRange.isSome() && aKeyRange.ref().isOnly();
 
   NS_NAMED_LITERAL_CSTRING(objectStoreIdString, "object_store_id");
   NS_NAMED_LITERAL_CSTRING(keyString, "key");
 
   nsresult rv;
   Key objectStoreKey;
   DatabaseConnection::CachedStatement selectStmt;
 
@@ -18565,41 +18554,40 @@ nsresult DatabaseOperationBase::DeleteOb
                            "FROM object_data "
                            "WHERE object_store_id = :object_store_id "
                            "AND key = :key;"),
         &selectStmt);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
 
-    objectStoreKey = aKeyRange.get_SerializedKeyRange().lower();
+    objectStoreKey = aKeyRange.ref().lower();
 
     rv = objectStoreKey.BindToStatement(selectStmt, keyString);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   } else {
     nsAutoCString keyRangeClause;
-    if (aKeyRange.type() == OptionalKeyRange::TSerializedKeyRange) {
-      GetBindingClauseForKeyRange(aKeyRange.get_SerializedKeyRange(), keyString,
-                                  keyRangeClause);
+    if (aKeyRange.isSome()) {
+      GetBindingClauseForKeyRange(aKeyRange.ref(), keyString, keyRangeClause);
     }
 
     rv = aConnection->GetCachedStatement(
         NS_LITERAL_CSTRING("SELECT index_data_values, key "
                            "FROM object_data "
                            "WHERE object_store_id = :") +
             objectStoreIdString + keyRangeClause + NS_LITERAL_CSTRING(";"),
         &selectStmt);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
 
-    if (aKeyRange.type() == OptionalKeyRange::TSerializedKeyRange) {
-      rv = BindKeyRangeToStatement(aKeyRange, selectStmt);
+    if (aKeyRange.isSome()) {
+      rv = BindKeyRangeToStatement(aKeyRange.ref(), selectStmt);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
     }
   }
 
   rv = selectStmt->BindInt64ByName(objectStoreIdString, aObjectStoreId);
   if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -22430,17 +22418,17 @@ nsresult DeleteObjectStoreOp::DoDatabase
     rv = ObjectStoreHasIndexes(aConnection, mMetadata->mCommonMetadata.id(),
                                &hasIndexes);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
 
     if (hasIndexes) {
       rv = DeleteObjectStoreDataTableRowsWithIndexes(
-          aConnection, mMetadata->mCommonMetadata.id(), void_t());
+          aConnection, mMetadata->mCommonMetadata.id(), Nothing());
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
 
       // Now clean up the object store index table.
       DatabaseConnection::CachedStatement stmt;
       rv = aConnection->GetCachedStatement(
           NS_LITERAL_CSTRING("DELETE FROM object_store_index "
@@ -24278,28 +24266,26 @@ ObjectStoreGetRequestOp::ObjectStoreGetR
                                                  bool aGetAll)
     : NormalTransactionOp(aTransaction),
       mObjectStoreId(aGetAll
                          ? aParams.get_ObjectStoreGetAllParams().objectStoreId()
                          : aParams.get_ObjectStoreGetParams().objectStoreId()),
       mDatabase(aTransaction->GetDatabase()),
       mOptionalKeyRange(
           aGetAll ? aParams.get_ObjectStoreGetAllParams().optionalKeyRange()
-                  : OptionalKeyRange(
-                        aParams.get_ObjectStoreGetParams().keyRange())),
+                  : Some(aParams.get_ObjectStoreGetParams().keyRange())),
       mBackgroundParent(aTransaction->GetBackgroundParent()),
       mPreprocessInfoCount(0),
       mLimit(aGetAll ? aParams.get_ObjectStoreGetAllParams().limit() : 1),
       mGetAll(aGetAll) {
   MOZ_ASSERT(aParams.type() == RequestParams::TObjectStoreGetParams ||
              aParams.type() == RequestParams::TObjectStoreGetAllParams);
   MOZ_ASSERT(mObjectStoreId);
   MOZ_ASSERT(mDatabase);
-  MOZ_ASSERT_IF(!aGetAll, mOptionalKeyRange.type() ==
-                              OptionalKeyRange::TSerializedKeyRange);
+  MOZ_ASSERT_IF(!aGetAll, mOptionalKeyRange.isSome());
   MOZ_ASSERT(mBackgroundParent);
 }
 
 template <typename T>
 void MoveData(StructuredCloneReadInfo& aInfo, T& aResult);
 
 template <>
 void MoveData<SerializedStructuredCloneReadInfo>(
@@ -24332,28 +24318,26 @@ nsresult ObjectStoreGetRequestOp::Conver
 
   return NS_OK;
 }
 
 nsresult ObjectStoreGetRequestOp::DoDatabaseWork(
     DatabaseConnection* aConnection) {
   MOZ_ASSERT(aConnection);
   aConnection->AssertIsOnConnectionThread();
-  MOZ_ASSERT_IF(!mGetAll, mOptionalKeyRange.type() ==
-                              OptionalKeyRange::TSerializedKeyRange);
+  MOZ_ASSERT_IF(!mGetAll, mOptionalKeyRange.isSome());
   MOZ_ASSERT_IF(!mGetAll, mLimit == 1);
 
   AUTO_PROFILER_LABEL("ObjectStoreGetRequestOp::DoDatabaseWork", DOM);
 
-  const bool hasKeyRange =
-      mOptionalKeyRange.type() == OptionalKeyRange::TSerializedKeyRange;
+  const bool hasKeyRange = mOptionalKeyRange.isSome();
 
   nsAutoCString keyRangeClause;
   if (hasKeyRange) {
-    GetBindingClauseForKeyRange(mOptionalKeyRange.get_SerializedKeyRange(),
+    GetBindingClauseForKeyRange(mOptionalKeyRange.ref(),
                                 NS_LITERAL_CSTRING("key"), keyRangeClause);
   }
 
   nsCString limitClause;
   if (mLimit) {
     limitClause.AssignLiteral(" LIMIT ");
     limitClause.AppendInt(mLimit);
   }
@@ -24372,18 +24356,17 @@ nsresult ObjectStoreGetRequestOp::DoData
   }
 
   rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("osid"), mObjectStoreId);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   if (hasKeyRange) {
-    rv = BindKeyRangeToStatement(mOptionalKeyRange.get_SerializedKeyRange(),
-                                 stmt);
+    rv = BindKeyRangeToStatement(mOptionalKeyRange.ref(), stmt);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
 
   bool hasResult;
   while (NS_SUCCEEDED((rv = stmt->ExecuteStep(&hasResult))) && hasResult) {
     StructuredCloneReadInfo* cloneInfo = mResponse.AppendElement(fallible);
@@ -24518,40 +24501,37 @@ void ObjectStoreGetRequestOp::GetRespons
 ObjectStoreGetKeyRequestOp::ObjectStoreGetKeyRequestOp(
     TransactionBase* aTransaction, const RequestParams& aParams, bool aGetAll)
     : NormalTransactionOp(aTransaction),
       mObjectStoreId(
           aGetAll ? aParams.get_ObjectStoreGetAllKeysParams().objectStoreId()
                   : aParams.get_ObjectStoreGetKeyParams().objectStoreId()),
       mOptionalKeyRange(
           aGetAll ? aParams.get_ObjectStoreGetAllKeysParams().optionalKeyRange()
-                  : OptionalKeyRange(
-                        aParams.get_ObjectStoreGetKeyParams().keyRange())),
+                  : Some(aParams.get_ObjectStoreGetKeyParams().keyRange())),
       mLimit(aGetAll ? aParams.get_ObjectStoreGetAllKeysParams().limit() : 1),
       mGetAll(aGetAll) {
   MOZ_ASSERT(aParams.type() == RequestParams::TObjectStoreGetKeyParams ||
              aParams.type() == RequestParams::TObjectStoreGetAllKeysParams);
   MOZ_ASSERT(mObjectStoreId);
-  MOZ_ASSERT_IF(!aGetAll, mOptionalKeyRange.type() ==
-                              OptionalKeyRange::TSerializedKeyRange);
+  MOZ_ASSERT_IF(!aGetAll, mOptionalKeyRange.isSome());
 }
 
 nsresult ObjectStoreGetKeyRequestOp::DoDatabaseWork(
     DatabaseConnection* aConnection) {
   MOZ_ASSERT(aConnection);
   aConnection->AssertIsOnConnectionThread();
 
   AUTO_PROFILER_LABEL("ObjectStoreGetKeyRequestOp::DoDatabaseWork", DOM);
 
-  const bool hasKeyRange =
-      mOptionalKeyRange.type() == OptionalKeyRange::TSerializedKeyRange;
+  const bool hasKeyRange = mOptionalKeyRange.isSome();
 
   nsAutoCString keyRangeClause;
   if (hasKeyRange) {
-    GetBindingClauseForKeyRange(mOptionalKeyRange.get_SerializedKeyRange(),
+    GetBindingClauseForKeyRange(mOptionalKeyRange.ref(),
                                 NS_LITERAL_CSTRING("key"), keyRangeClause);
   }
 
   nsAutoCString limitClause;
   if (mLimit) {
     limitClause.AssignLiteral(" LIMIT ");
     limitClause.AppendInt(mLimit);
   }
@@ -24570,18 +24550,17 @@ nsresult ObjectStoreGetKeyRequestOp::DoD
   }
 
   rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("osid"), mObjectStoreId);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   if (hasKeyRange) {
-    rv = BindKeyRangeToStatement(mOptionalKeyRange.get_SerializedKeyRange(),
-                                 stmt);
+    rv = BindKeyRangeToStatement(mOptionalKeyRange.ref(), stmt);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
 
   bool hasResult;
   while (NS_SUCCEEDED((rv = stmt->ExecuteStep(&hasResult))) && hasResult) {
     Key* key = mResponse.AppendElement(fallible);
@@ -24666,17 +24645,17 @@ nsresult ObjectStoreDeleteRequestOp::DoD
       ObjectStoreHasIndexes(this, aConnection, mParams.objectStoreId(),
                             mObjectStoreMayHaveIndexes, &objectStoreHasIndexes);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   if (objectStoreHasIndexes) {
     rv = DeleteObjectStoreDataTableRowsWithIndexes(
-        aConnection, mParams.objectStoreId(), mParams.keyRange());
+        aConnection, mParams.objectStoreId(), Some(mParams.keyRange()));
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   } else {
     NS_NAMED_LITERAL_CSTRING(objectStoreIdString, "object_store_id");
 
     nsAutoCString keyRangeClause;
     GetBindingClauseForKeyRange(mParams.keyRange(), NS_LITERAL_CSTRING("key"),
@@ -24749,17 +24728,17 @@ nsresult ObjectStoreClearRequestOp::DoDa
       ObjectStoreHasIndexes(this, aConnection, mParams.objectStoreId(),
                             mObjectStoreMayHaveIndexes, &objectStoreHasIndexes);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   if (objectStoreHasIndexes) {
     rv = DeleteObjectStoreDataTableRowsWithIndexes(
-        aConnection, mParams.objectStoreId(), void_t());
+        aConnection, mParams.objectStoreId(), Nothing());
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   } else {
     DatabaseConnection::CachedStatement stmt;
     rv = aConnection->GetCachedStatement(
         NS_LITERAL_CSTRING("DELETE FROM object_data "
                            "WHERE object_store_id = :object_store_id;"),
@@ -24790,24 +24769,22 @@ nsresult ObjectStoreClearRequestOp::DoDa
 
 nsresult ObjectStoreCountRequestOp::DoDatabaseWork(
     DatabaseConnection* aConnection) {
   MOZ_ASSERT(aConnection);
   aConnection->AssertIsOnConnectionThread();
 
   AUTO_PROFILER_LABEL("ObjectStoreCountRequestOp::DoDatabaseWork", DOM);
 
-  const bool hasKeyRange = mParams.optionalKeyRange().type() ==
-                           OptionalKeyRange::TSerializedKeyRange;
+  const bool hasKeyRange = mParams.optionalKeyRange().isSome();
 
   nsAutoCString keyRangeClause;
   if (hasKeyRange) {
-    GetBindingClauseForKeyRange(
-        mParams.optionalKeyRange().get_SerializedKeyRange(),
-        NS_LITERAL_CSTRING("key"), keyRangeClause);
+    GetBindingClauseForKeyRange(mParams.optionalKeyRange().ref(),
+                                NS_LITERAL_CSTRING("key"), keyRangeClause);
   }
 
   nsCString query = NS_LITERAL_CSTRING(
                         "SELECT count(*) "
                         "FROM object_data "
                         "WHERE object_store_id = :osid") +
                     keyRangeClause;
 
@@ -24819,18 +24796,17 @@ nsresult ObjectStoreCountRequestOp::DoDa
 
   rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("osid"),
                              mParams.objectStoreId());
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   if (hasKeyRange) {
-    rv = BindKeyRangeToStatement(
-        mParams.optionalKeyRange().get_SerializedKeyRange(), stmt);
+    rv = BindKeyRangeToStatement(mParams.optionalKeyRange().ref(), stmt);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
 
   bool hasResult;
   rv = stmt->ExecuteStep(&hasResult);
   if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -24919,52 +24895,49 @@ already_AddRefed<FullIndexMetadata> Inde
 
   return indexMetadata.forget();
 }
 
 IndexGetRequestOp::IndexGetRequestOp(TransactionBase* aTransaction,
                                      const RequestParams& aParams, bool aGetAll)
     : IndexRequestOpBase(aTransaction, aParams),
       mDatabase(aTransaction->GetDatabase()),
-      mOptionalKeyRange(
-          aGetAll ? aParams.get_IndexGetAllParams().optionalKeyRange()
-                  : OptionalKeyRange(aParams.get_IndexGetParams().keyRange())),
+      mOptionalKeyRange(aGetAll
+                            ? aParams.get_IndexGetAllParams().optionalKeyRange()
+                            : Some(aParams.get_IndexGetParams().keyRange())),
       mBackgroundParent(aTransaction->GetBackgroundParent()),
       mLimit(aGetAll ? aParams.get_IndexGetAllParams().limit() : 1),
       mGetAll(aGetAll) {
   MOZ_ASSERT(aParams.type() == RequestParams::TIndexGetParams ||
              aParams.type() == RequestParams::TIndexGetAllParams);
   MOZ_ASSERT(mDatabase);
-  MOZ_ASSERT_IF(!aGetAll, mOptionalKeyRange.type() ==
-                              OptionalKeyRange::TSerializedKeyRange);
+  MOZ_ASSERT_IF(!aGetAll, mOptionalKeyRange.isSome());
   MOZ_ASSERT(mBackgroundParent);
 }
 
 nsresult IndexGetRequestOp::DoDatabaseWork(DatabaseConnection* aConnection) {
   MOZ_ASSERT(aConnection);
   aConnection->AssertIsOnConnectionThread();
-  MOZ_ASSERT_IF(!mGetAll, mOptionalKeyRange.type() ==
-                              OptionalKeyRange::TSerializedKeyRange);
+  MOZ_ASSERT_IF(!mGetAll, mOptionalKeyRange.isSome());
   MOZ_ASSERT_IF(!mGetAll, mLimit == 1);
 
   AUTO_PROFILER_LABEL("IndexGetRequestOp::DoDatabaseWork", DOM);
 
-  const bool hasKeyRange =
-      mOptionalKeyRange.type() == OptionalKeyRange::TSerializedKeyRange;
+  const bool hasKeyRange = mOptionalKeyRange.isSome();
 
   nsCString indexTable;
   if (mMetadata->mCommonMetadata.unique()) {
     indexTable.AssignLiteral("unique_index_data ");
   } else {
     indexTable.AssignLiteral("index_data ");
   }
 
   nsAutoCString keyRangeClause;
   if (hasKeyRange) {
-    GetBindingClauseForKeyRange(mOptionalKeyRange.get_SerializedKeyRange(),
+    GetBindingClauseForKeyRange(mOptionalKeyRange.ref(),
                                 NS_LITERAL_CSTRING("value"), keyRangeClause);
   }
 
   nsCString limitClause;
   if (mLimit) {
     limitClause.AssignLiteral(" LIMIT ");
     limitClause.AppendInt(mLimit);
   }
@@ -24991,18 +24964,17 @@ nsresult IndexGetRequestOp::DoDatabaseWo
 
   rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("index_id"),
                              mMetadata->mCommonMetadata.id());
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   if (hasKeyRange) {
-    rv = BindKeyRangeToStatement(mOptionalKeyRange.get_SerializedKeyRange(),
-                                 stmt);
+    rv = BindKeyRangeToStatement(mOptionalKeyRange.ref(), stmt);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
 
   bool hasResult;
   while (NS_SUCCEEDED((rv = stmt->ExecuteStep(&hasResult))) && hasResult) {
     StructuredCloneReadInfo* cloneInfo = mResponse.AppendElement(fallible);
@@ -25107,49 +25079,45 @@ void IndexGetRequestOp::GetResponse(Requ
   }
 }
 
 IndexGetKeyRequestOp::IndexGetKeyRequestOp(TransactionBase* aTransaction,
                                            const RequestParams& aParams,
                                            bool aGetAll)
     : IndexRequestOpBase(aTransaction, aParams),
       mOptionalKeyRange(
-          aGetAll
-              ? aParams.get_IndexGetAllKeysParams().optionalKeyRange()
-              : OptionalKeyRange(aParams.get_IndexGetKeyParams().keyRange())),
+          aGetAll ? aParams.get_IndexGetAllKeysParams().optionalKeyRange()
+                  : Some(aParams.get_IndexGetKeyParams().keyRange())),
       mLimit(aGetAll ? aParams.get_IndexGetAllKeysParams().limit() : 1),
       mGetAll(aGetAll) {
   MOZ_ASSERT(aParams.type() == RequestParams::TIndexGetKeyParams ||
              aParams.type() == RequestParams::TIndexGetAllKeysParams);
-  MOZ_ASSERT_IF(!aGetAll, mOptionalKeyRange.type() ==
-                              OptionalKeyRange::TSerializedKeyRange);
+  MOZ_ASSERT_IF(!aGetAll, mOptionalKeyRange.isSome());
 }
 
 nsresult IndexGetKeyRequestOp::DoDatabaseWork(DatabaseConnection* aConnection) {
   MOZ_ASSERT(aConnection);
   aConnection->AssertIsOnConnectionThread();
-  MOZ_ASSERT_IF(!mGetAll, mOptionalKeyRange.type() ==
-                              OptionalKeyRange::TSerializedKeyRange);
+  MOZ_ASSERT_IF(!mGetAll, mOptionalKeyRange.isSome());
   MOZ_ASSERT_IF(!mGetAll, mLimit == 1);
 
   AUTO_PROFILER_LABEL("IndexGetKeyRequestOp::DoDatabaseWork", DOM);
 
-  const bool hasKeyRange =
-      mOptionalKeyRange.type() == OptionalKeyRange::TSerializedKeyRange;
+  const bool hasKeyRange = mOptionalKeyRange.isSome();
 
   nsCString indexTable;
   if (mMetadata->mCommonMetadata.unique()) {
     indexTable.AssignLiteral("unique_index_data ");
   } else {
     indexTable.AssignLiteral("index_data ");
   }
 
   nsAutoCString keyRangeClause;
   if (hasKeyRange) {
-    GetBindingClauseForKeyRange(mOptionalKeyRange.get_SerializedKeyRange(),
+    GetBindingClauseForKeyRange(mOptionalKeyRange.ref(),
                                 NS_LITERAL_CSTRING("value"), keyRangeClause);
   }
 
   nsCString limitClause;
   if (mLimit) {
     limitClause.AssignLiteral(" LIMIT ");
     limitClause.AppendInt(mLimit);
   }
@@ -25169,18 +25137,17 @@ nsresult IndexGetKeyRequestOp::DoDatabas
 
   rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("index_id"),
                              mMetadata->mCommonMetadata.id());
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   if (hasKeyRange) {
-    rv = BindKeyRangeToStatement(mOptionalKeyRange.get_SerializedKeyRange(),
-                                 stmt);
+    rv = BindKeyRangeToStatement(mOptionalKeyRange.ref(), stmt);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
 
   bool hasResult;
   while (NS_SUCCEEDED((rv = stmt->ExecuteStep(&hasResult))) && hasResult) {
     Key* key = mResponse.AppendElement(fallible);
@@ -25231,31 +25198,29 @@ void IndexGetKeyRequestOp::GetResponse(R
 }
 
 nsresult IndexCountRequestOp::DoDatabaseWork(DatabaseConnection* aConnection) {
   MOZ_ASSERT(aConnection);
   aConnection->AssertIsOnConnectionThread();
 
   AUTO_PROFILER_LABEL("IndexCountRequestOp::DoDatabaseWork", DOM);
 
-  const bool hasKeyRange = mParams.optionalKeyRange().type() ==
-                           OptionalKeyRange::TSerializedKeyRange;
+  const bool hasKeyRange = mParams.optionalKeyRange().isSome();
 
   nsCString indexTable;
   if (mMetadata->mCommonMetadata.unique()) {
     indexTable.AssignLiteral("unique_index_data ");
   } else {
     indexTable.AssignLiteral("index_data ");
   }
 
   nsAutoCString keyRangeClause;
   if (hasKeyRange) {
-    GetBindingClauseForKeyRange(
-        mParams.optionalKeyRange().get_SerializedKeyRange(),
-        NS_LITERAL_CSTRING("value"), keyRangeClause);
+    GetBindingClauseForKeyRange(mParams.optionalKeyRange().ref(),
+                                NS_LITERAL_CSTRING("value"), keyRangeClause);
   }
 
   nsCString query = NS_LITERAL_CSTRING(
                         "SELECT count(*) "
                         "FROM ") +
                     indexTable +
                     NS_LITERAL_CSTRING("WHERE index_id = :index_id") +
                     keyRangeClause;
@@ -25268,18 +25233,17 @@ nsresult IndexCountRequestOp::DoDatabase
 
   rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("index_id"),
                              mMetadata->mCommonMetadata.id());
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   if (hasKeyRange) {
-    rv = BindKeyRangeToStatement(
-        mParams.optionalKeyRange().get_SerializedKeyRange(), stmt);
+    rv = BindKeyRangeToStatement(mParams.optionalKeyRange().ref(), stmt);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
 
   bool hasResult;
   rv = stmt->ExecuteStep(&hasResult);
   if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -25458,19 +25422,18 @@ nsresult Cursor::CursorOpBase::PopulateR
 }
 
 void Cursor::OpenOp::GetRangeKeyInfo(bool aLowerBound, Key* aKey, bool* aOpen) {
   AssertIsOnConnectionThread();
   MOZ_ASSERT(aKey);
   MOZ_ASSERT(aKey->IsUnset());
   MOZ_ASSERT(aOpen);
 
-  if (mOptionalKeyRange.type() == OptionalKeyRange::TSerializedKeyRange) {
-    const SerializedKeyRange& range =
-        mOptionalKeyRange.get_SerializedKeyRange();
+  if (mOptionalKeyRange.isSome()) {
+    const SerializedKeyRange& range = mOptionalKeyRange.ref();
     if (range.isOnly()) {
       *aKey = range.lower();
       *aOpen = false;
       if (mCursor->IsLocaleAware()) {
         range.lower().ToLocaleBasedKey(*aKey, mCursor->mLocale);
       }
     } else {
       *aKey = aLowerBound ? range.lower() : range.upper();
@@ -25494,34 +25457,33 @@ nsresult Cursor::OpenOp::DoObjectStoreDa
   aConnection->AssertIsOnConnectionThread();
   MOZ_ASSERT(mCursor);
   MOZ_ASSERT(mCursor->mType == OpenCursorParams::TObjectStoreOpenCursorParams);
   MOZ_ASSERT(mCursor->mObjectStoreId);
   MOZ_ASSERT(mCursor->mFileManager);
 
   AUTO_PROFILER_LABEL("Cursor::OpenOp::DoObjectStoreDatabaseWork", DOM);
 
-  const bool usingKeyRange =
-      mOptionalKeyRange.type() == OptionalKeyRange::TSerializedKeyRange;
+  const bool usingKeyRange = mOptionalKeyRange.isSome();
 
   NS_NAMED_LITERAL_CSTRING(keyString, "key");
   NS_NAMED_LITERAL_CSTRING(id, "id");
   NS_NAMED_LITERAL_CSTRING(openLimit, " LIMIT ");
 
   nsCString queryStart = NS_LITERAL_CSTRING("SELECT ") + keyString +
                          NS_LITERAL_CSTRING(
                              ", file_ids, data "
                              "FROM object_data "
                              "WHERE object_store_id = :") +
                          id;
 
   nsAutoCString keyRangeClause;
   if (usingKeyRange) {
-    GetBindingClauseForKeyRange(mOptionalKeyRange.get_SerializedKeyRange(),
-                                keyString, keyRangeClause);
+    GetBindingClauseForKeyRange(mOptionalKeyRange.ref(), keyString,
+                                keyRangeClause);
   }
 
   nsAutoCString directionClause = NS_LITERAL_CSTRING(" ORDER BY ") + keyString;
   switch (mCursor->mDirection) {
     case IDBCursor::NEXT:
     case IDBCursor::NEXT_UNIQUE:
       directionClause.AppendLiteral(" ASC");
       break;
@@ -25547,18 +25509,17 @@ nsresult Cursor::OpenOp::DoObjectStoreDa
   }
 
   rv = stmt->BindInt64ByName(id, mCursor->mObjectStoreId);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   if (usingKeyRange) {
-    rv = BindKeyRangeToStatement(mOptionalKeyRange.get_SerializedKeyRange(),
-                                 stmt);
+    rv = BindKeyRangeToStatement(mOptionalKeyRange.ref(), stmt);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
 
   bool hasResult;
   rv = stmt->ExecuteStep(&hasResult);
   if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -25638,33 +25599,32 @@ nsresult Cursor::OpenOp::DoObjectStoreKe
   aConnection->AssertIsOnConnectionThread();
   MOZ_ASSERT(mCursor);
   MOZ_ASSERT(mCursor->mType ==
              OpenCursorParams::TObjectStoreOpenKeyCursorParams);
   MOZ_ASSERT(mCursor->mObjectStoreId);
 
   AUTO_PROFILER_LABEL("Cursor::OpenOp::DoObjectStoreKeyDatabaseWork", DOM);
 
-  const bool usingKeyRange =
-      mOptionalKeyRange.type() == OptionalKeyRange::TSerializedKeyRange;
+  const bool usingKeyRange = mOptionalKeyRange.isSome();
 
   NS_NAMED_LITERAL_CSTRING(keyString, "key");
   NS_NAMED_LITERAL_CSTRING(id, "id");
   NS_NAMED_LITERAL_CSTRING(openLimit, " LIMIT ");
 
   nsCString queryStart = NS_LITERAL_CSTRING("SELECT ") + keyString +
                          NS_LITERAL_CSTRING(
                              " FROM object_data "
                              "WHERE object_store_id = :") +
                          id;
 
   nsAutoCString keyRangeClause;
   if (usingKeyRange) {
-    GetBindingClauseForKeyRange(mOptionalKeyRange.get_SerializedKeyRange(),
-                                keyString, keyRangeClause);
+    GetBindingClauseForKeyRange(mOptionalKeyRange.ref(), keyString,
+                                keyRangeClause);
   }
 
   nsAutoCString directionClause = NS_LITERAL_CSTRING(" ORDER BY ") + keyString;
   switch (mCursor->mDirection) {
     case IDBCursor::NEXT:
     case IDBCursor::NEXT_UNIQUE:
       directionClause.AppendLiteral(" ASC");
       break;
@@ -25690,18 +25650,17 @@ nsresult Cursor::OpenOp::DoObjectStoreKe
   }
 
   rv = stmt->BindInt64ByName(id, mCursor->mObjectStoreId);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   if (usingKeyRange) {
-    rv = BindKeyRangeToStatement(mOptionalKeyRange.get_SerializedKeyRange(),
-                                 stmt);
+    rv = BindKeyRangeToStatement(mOptionalKeyRange.ref(), stmt);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
 
   bool hasResult;
   rv = stmt->ExecuteStep(&hasResult);
   if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -25779,18 +25738,17 @@ nsresult Cursor::OpenOp::DoIndexDatabase
   aConnection->AssertIsOnConnectionThread();
   MOZ_ASSERT(mCursor);
   MOZ_ASSERT(mCursor->mType == OpenCursorParams::TIndexOpenCursorParams);
   MOZ_ASSERT(mCursor->mObjectStoreId);
   MOZ_ASSERT(mCursor->mIndexId);
 
   AUTO_PROFILER_LABEL("Cursor::OpenOp::DoIndexDatabaseWork", DOM);
 
-  const bool usingKeyRange =
-      mOptionalKeyRange.type() == OptionalKeyRange::TSerializedKeyRange;
+  const bool usingKeyRange = mOptionalKeyRange.isSome();
 
   nsCString indexTable = mCursor->mUniqueIndex
                              ? NS_LITERAL_CSTRING("unique_index_data")
                              : NS_LITERAL_CSTRING("index_data");
 
   NS_NAMED_LITERAL_CSTRING(sortColumn, "sort_column");
   NS_NAMED_LITERAL_CSTRING(id, "id");
   NS_NAMED_LITERAL_CSTRING(openLimit, " LIMIT ");
@@ -25820,18 +25778,18 @@ nsresult Cursor::OpenOp::DoIndexDatabase
                                  "object_data.object_store_id "
                                  "AND index_table.object_data_key = "
                                  "object_data.key "
                                  "WHERE index_table.index_id = :") +
                              id;
 
   nsAutoCString keyRangeClause;
   if (usingKeyRange) {
-    GetBindingClauseForKeyRange(mOptionalKeyRange.get_SerializedKeyRange(),
-                                sortColumn, keyRangeClause);
+    GetBindingClauseForKeyRange(mOptionalKeyRange.ref(), sortColumn,
+                                keyRangeClause);
   }
 
   nsAutoCString directionClause = NS_LITERAL_CSTRING(" ORDER BY ") + sortColumn;
 
   switch (mCursor->mDirection) {
     case IDBCursor::NEXT:
     case IDBCursor::NEXT_UNIQUE:
       directionClause.AppendLiteral(" ASC, index_table.object_data_key ASC");
@@ -25862,21 +25820,20 @@ nsresult Cursor::OpenOp::DoIndexDatabase
 
   rv = stmt->BindInt64ByName(id, mCursor->mIndexId);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   if (usingKeyRange) {
     if (mCursor->IsLocaleAware()) {
-      rv = BindKeyRangeToStatement(mOptionalKeyRange.get_SerializedKeyRange(),
-                                   stmt, mCursor->mLocale);
-    } else {
-      rv = BindKeyRangeToStatement(mOptionalKeyRange.get_SerializedKeyRange(),
-                                   stmt);
+      rv = BindKeyRangeToStatement(mOptionalKeyRange.ref(), stmt,
+                                   mCursor->mLocale);
+    } else {
+      rv = BindKeyRangeToStatement(mOptionalKeyRange.ref(), stmt);
     }
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
 
   bool hasResult;
   rv = stmt->ExecuteStep(&hasResult);
@@ -26005,18 +25962,17 @@ nsresult Cursor::OpenOp::DoIndexKeyDatab
   aConnection->AssertIsOnConnectionThread();
   MOZ_ASSERT(mCursor);
   MOZ_ASSERT(mCursor->mType == OpenCursorParams::TIndexOpenKeyCursorParams);
   MOZ_ASSERT(mCursor->mObjectStoreId);
   MOZ_ASSERT(mCursor->mIndexId);
 
   AUTO_PROFILER_LABEL("Cursor::OpenOp::DoIndexKeyDatabaseWork", DOM);
 
-  const bool usingKeyRange =
-      mOptionalKeyRange.type() == OptionalKeyRange::TSerializedKeyRange;
+  const bool usingKeyRange = mOptionalKeyRange.isSome();
 
   nsCString table = mCursor->mUniqueIndex
                         ? NS_LITERAL_CSTRING("unique_index_data")
                         : NS_LITERAL_CSTRING("index_data");
 
   NS_NAMED_LITERAL_CSTRING(sortColumn, "sort_column");
   NS_NAMED_LITERAL_CSTRING(id, "id");
   NS_NAMED_LITERAL_CSTRING(openLimit, " LIMIT ");
@@ -26036,18 +25992,18 @@ nsresult Cursor::OpenOp::DoIndexKeyDatab
                              NS_LITERAL_CSTRING(
                                  "object_data_key "
                                  " FROM ") +
                              table + NS_LITERAL_CSTRING(" WHERE index_id = :") +
                              id;
 
   nsAutoCString keyRangeClause;
   if (usingKeyRange) {
-    GetBindingClauseForKeyRange(mOptionalKeyRange.get_SerializedKeyRange(),
-                                sortColumn, keyRangeClause);
+    GetBindingClauseForKeyRange(mOptionalKeyRange.ref(), sortColumn,
+                                keyRangeClause);
   }
 
   nsAutoCString directionClause = NS_LITERAL_CSTRING(" ORDER BY ") + sortColumn;
 
   switch (mCursor->mDirection) {
     case IDBCursor::NEXT:
     case IDBCursor::NEXT_UNIQUE:
       directionClause.AppendLiteral(" ASC, object_data_key ASC");
@@ -26078,21 +26034,20 @@ nsresult Cursor::OpenOp::DoIndexKeyDatab
 
   rv = stmt->BindInt64ByName(id, mCursor->mIndexId);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   if (usingKeyRange) {
     if (mCursor->IsLocaleAware()) {
-      rv = BindKeyRangeToStatement(mOptionalKeyRange.get_SerializedKeyRange(),
-                                   stmt, mCursor->mLocale);
-    } else {
-      rv = BindKeyRangeToStatement(mOptionalKeyRange.get_SerializedKeyRange(),
-                                   stmt);
+      rv = BindKeyRangeToStatement(mOptionalKeyRange.ref(), stmt,
+                                   mCursor->mLocale);
+    } else {
+      rv = BindKeyRangeToStatement(mOptionalKeyRange.ref(), stmt);
     }
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
 
   bool hasResult;
   rv = stmt->ExecuteStep(&hasResult);
--- a/dom/indexedDB/IDBIndex.cpp
+++ b/dom/indexedDB/IDBIndex.cpp
@@ -363,23 +363,21 @@ already_AddRefed<IDBRequest> IDBIndex::G
   aRv = IDBKeyRange::FromJSVal(aCx, aKey, getter_AddRefs(keyRange));
   if (NS_WARN_IF(aRv.Failed())) {
     return nullptr;
   }
 
   const int64_t objectStoreId = mObjectStore->Id();
   const int64_t indexId = Id();
 
-  OptionalKeyRange optionalKeyRange;
+  Maybe<SerializedKeyRange> optionalKeyRange;
   if (keyRange) {
     SerializedKeyRange serializedKeyRange;
     keyRange->ToSerialized(serializedKeyRange);
-    optionalKeyRange = serializedKeyRange;
-  } else {
-    optionalKeyRange = void_t();
+    optionalKeyRange.emplace(serializedKeyRange);
   }
 
   const uint32_t limit = aLimit.WasPassed() ? aLimit.Value() : 0;
 
   RequestParams params;
   if (aKeysOnly) {
     params =
         IndexGetAllKeysParams(objectStoreId, indexId, optionalKeyRange, limit);
@@ -441,25 +439,23 @@ already_AddRefed<IDBRequest> IDBIndex::O
   aRv = IDBKeyRange::FromJSVal(aCx, aRange, getter_AddRefs(keyRange));
   if (NS_WARN_IF(aRv.Failed())) {
     return nullptr;
   }
 
   int64_t objectStoreId = mObjectStore->Id();
   int64_t indexId = Id();
 
-  OptionalKeyRange optionalKeyRange;
+  Maybe<SerializedKeyRange> optionalKeyRange;
 
   if (keyRange) {
     SerializedKeyRange serializedKeyRange;
     keyRange->ToSerialized(serializedKeyRange);
 
-    optionalKeyRange = std::move(serializedKeyRange);
-  } else {
-    optionalKeyRange = void_t();
+    optionalKeyRange.emplace(std::move(serializedKeyRange));
   }
 
   IDBCursor::Direction direction = IDBCursor::ConvertDirection(aDirection);
 
   OpenCursorParams params;
   if (aKeysOnly) {
     IndexOpenKeyCursorParams openParams;
     openParams.objectStoreId() = objectStoreId;
@@ -540,19 +536,17 @@ already_AddRefed<IDBRequest> IDBIndex::C
 
   IndexCountParams params;
   params.objectStoreId() = mObjectStore->Id();
   params.indexId() = Id();
 
   if (keyRange) {
     SerializedKeyRange serializedKeyRange;
     keyRange->ToSerialized(serializedKeyRange);
-    params.optionalKeyRange() = serializedKeyRange;
-  } else {
-    params.optionalKeyRange() = void_t();
+    params.optionalKeyRange().emplace(serializedKeyRange);
   }
 
   RefPtr<IDBRequest> request = GenerateRequest(aCx, this);
   MOZ_ASSERT(request);
 
   IDB_LOG_MARK(
       "IndexedDB %s: Child  Transaction[%lld] Request[%llu]: "
       "database(%s).transaction(%s).objectStore(%s).index(%s)."
--- a/dom/indexedDB/IDBObjectStore.cpp
+++ b/dom/indexedDB/IDBObjectStore.cpp
@@ -1684,23 +1684,21 @@ already_AddRefed<IDBRequest> IDBObjectSt
   RefPtr<IDBKeyRange> keyRange;
   aRv = IDBKeyRange::FromJSVal(aCx, aKey, getter_AddRefs(keyRange));
   if (NS_WARN_IF(aRv.Failed())) {
     return nullptr;
   }
 
   const int64_t id = Id();
 
-  OptionalKeyRange optionalKeyRange;
+  Maybe<SerializedKeyRange> optionalKeyRange;
   if (keyRange) {
     SerializedKeyRange serializedKeyRange;
     keyRange->ToSerialized(serializedKeyRange);
-    optionalKeyRange = serializedKeyRange;
-  } else {
-    optionalKeyRange = void_t();
+    optionalKeyRange.emplace(serializedKeyRange);
   }
 
   const uint32_t limit = aLimit.WasPassed() ? aLimit.Value() : 0;
 
   RequestParams params;
   if (aKeysOnly) {
     params = ObjectStoreGetAllKeysParams(id, optionalKeyRange, limit);
   } else {
@@ -2226,19 +2224,17 @@ already_AddRefed<IDBRequest> IDBObjectSt
   }
 
   ObjectStoreCountParams params;
   params.objectStoreId() = Id();
 
   if (keyRange) {
     SerializedKeyRange serializedKeyRange;
     keyRange->ToSerialized(serializedKeyRange);
-    params.optionalKeyRange() = serializedKeyRange;
-  } else {
-    params.optionalKeyRange() = void_t();
+    params.optionalKeyRange().emplace(serializedKeyRange);
   }
 
   RefPtr<IDBRequest> request = GenerateRequest(aCx, this);
   MOZ_ASSERT(request);
 
   IDB_LOG_MARK(
       "IndexedDB %s: Child  Transaction[%lld] Request[%llu]: "
       "database(%s).transaction(%s).objectStore(%s).count(%s)",
@@ -2273,25 +2269,23 @@ already_AddRefed<IDBRequest> IDBObjectSt
   RefPtr<IDBKeyRange> keyRange;
   aRv = IDBKeyRange::FromJSVal(aCx, aRange, getter_AddRefs(keyRange));
   if (NS_WARN_IF(aRv.Failed())) {
     return nullptr;
   }
 
   int64_t objectStoreId = Id();
 
-  OptionalKeyRange optionalKeyRange;
+  Maybe<SerializedKeyRange> optionalKeyRange;
 
   if (keyRange) {
     SerializedKeyRange serializedKeyRange;
     keyRange->ToSerialized(serializedKeyRange);
 
-    optionalKeyRange = std::move(serializedKeyRange);
-  } else {
-    optionalKeyRange = void_t();
+    optionalKeyRange.emplace(std::move(serializedKeyRange));
   }
 
   IDBCursor::Direction direction = IDBCursor::ConvertDirection(aDirection);
 
   OpenCursorParams params;
   if (aKeysOnly) {
     ObjectStoreOpenKeyCursorParams openParams;
     openParams.objectStoreId() = objectStoreId;
--- a/dom/indexedDB/PBackgroundIDBSharedTypes.ipdlh
+++ b/dom/indexedDB/PBackgroundIDBSharedTypes.ipdlh
@@ -81,22 +81,16 @@ struct SerializedStructuredCloneWriteInf
 
 struct IndexUpdateInfo
 {
   int64_t indexId;
   Key value;
   Key localizedValue;
 };
 
-union OptionalKeyRange
-{
-  SerializedKeyRange;
-  void_t;
-};
-
 struct DatabaseMetadata
 {
   nsString name;
   uint64_t version;
   PersistenceType persistenceType;
 };
 
 struct ObjectStoreMetadata
@@ -128,40 +122,40 @@ struct ObjectStoreSpec
 {
   ObjectStoreMetadata metadata;
   IndexMetadata[] indexes;
 };
 
 struct ObjectStoreOpenCursorParams
 {
   int64_t objectStoreId;
-  OptionalKeyRange optionalKeyRange;
+  SerializedKeyRange? optionalKeyRange;
   Direction direction;
 };
 
 struct ObjectStoreOpenKeyCursorParams
 {
   int64_t objectStoreId;
-  OptionalKeyRange optionalKeyRange;
+  SerializedKeyRange? optionalKeyRange;
   Direction direction;
 };
 
 struct IndexOpenCursorParams
 {
   int64_t objectStoreId;
   int64_t indexId;
-  OptionalKeyRange optionalKeyRange;
+  SerializedKeyRange? optionalKeyRange;
   Direction direction;
 };
 
 struct IndexOpenKeyCursorParams
 {
   int64_t objectStoreId;
   int64_t indexId;
-  OptionalKeyRange optionalKeyRange;
+  SerializedKeyRange? optionalKeyRange;
   Direction direction;
 };
 
 union OpenCursorParams
 {
   ObjectStoreOpenCursorParams;
   ObjectStoreOpenKeyCursorParams;
   IndexOpenCursorParams;
@@ -209,24 +203,24 @@ struct ObjectStoreGetKeyParams
 {
   int64_t objectStoreId;
   SerializedKeyRange keyRange;
 };
 
 struct ObjectStoreGetAllParams
 {
   int64_t objectStoreId;
-  OptionalKeyRange optionalKeyRange;
+  SerializedKeyRange? optionalKeyRange;
   uint32_t limit;
 };
 
 struct ObjectStoreGetAllKeysParams
 {
   int64_t objectStoreId;
-  OptionalKeyRange optionalKeyRange;
+  SerializedKeyRange? optionalKeyRange;
   uint32_t limit;
 };
 
 struct ObjectStoreDeleteParams
 {
   int64_t objectStoreId;
   SerializedKeyRange keyRange;
 };
@@ -234,17 +228,17 @@ struct ObjectStoreDeleteParams
 struct ObjectStoreClearParams
 {
   int64_t objectStoreId;
 };
 
 struct ObjectStoreCountParams
 {
   int64_t objectStoreId;
-  OptionalKeyRange optionalKeyRange;
+  SerializedKeyRange? optionalKeyRange;
 };
 
 struct IndexGetParams
 {
   int64_t objectStoreId;
   int64_t indexId;
   SerializedKeyRange keyRange;
 };
@@ -255,33 +249,33 @@ struct IndexGetKeyParams
   int64_t indexId;
   SerializedKeyRange keyRange;
 };
 
 struct IndexGetAllParams
 {
   int64_t objectStoreId;
   int64_t indexId;
-  OptionalKeyRange optionalKeyRange;
+  SerializedKeyRange? optionalKeyRange;
   uint32_t limit;
 };
 
 struct IndexGetAllKeysParams
 {
   int64_t objectStoreId;
   int64_t indexId;
-  OptionalKeyRange optionalKeyRange;
+  SerializedKeyRange? optionalKeyRange;
   uint32_t limit;
 };
 
 struct IndexCountParams
 {
   int64_t objectStoreId;
   int64_t indexId;
-  OptionalKeyRange optionalKeyRange;
+  SerializedKeyRange? optionalKeyRange;
 };
 
 union RequestParams
 {
   ObjectStoreAddParams;
   ObjectStorePutParams;
   ObjectStoreGetParams;
   ObjectStoreGetKeyParams;