Bug 1257422 part 1. Add a way to do IDBObjectStore::OpenCursor without a JSContext if we are not passing a keyrange. r=khuey
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 17 Mar 2016 23:23:55 -0400
changeset 289254 20c9fb1e81bace4582d27311c93fc0c005ab8eb0
parent 289253 a1a7da507e4e2deb751179875b28e3b84ddd381a
child 289255 67aa8f1fca8ee61c98edfdb404b549bc15382f91
push id73768
push userbzbarsky@mozilla.com
push dateFri, 18 Mar 2016 03:24:54 +0000
treeherdermozilla-inbound@67aa8f1fca8e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs1257422
milestone48.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 1257422 part 1. Add a way to do IDBObjectStore::OpenCursor without a JSContext if we are not passing a keyrange. r=khuey
dom/datastore/DataStoreService.cpp
dom/indexedDB/IDBKeyRange.cpp
dom/indexedDB/IDBKeyRange.h
dom/indexedDB/IDBObjectStore.cpp
dom/indexedDB/IDBObjectStore.h
--- a/dom/datastore/DataStoreService.cpp
+++ b/dom/datastore/DataStoreService.cpp
@@ -405,19 +405,17 @@ public:
       mTxn = aDb->Transaction();
 
       RefPtr<IDBObjectStore> store =
       mTxn->ObjectStore(NS_LITERAL_STRING(DATASTOREDB_REVISION), error);
       if (NS_WARN_IF(error.Failed())) {
         return;
       }
 
-      AutoSafeJSContext cx;
-      mRequest = store->OpenCursor(cx, JS::UndefinedHandleValue,
-                                   IDBCursorDirection::Prev, error);
+      mRequest = store->OpenCursor(IDBCursorDirection::Prev, error);
       if (NS_WARN_IF(error.Failed())) {
         return;
       }
 
       nsresult rv;
       rv = mRequest->EventTarget::AddEventListener(NS_LITERAL_STRING("success"),
                                                    this, false);
       if (NS_FAILED(rv)) {
--- a/dom/indexedDB/IDBKeyRange.cpp
+++ b/dom/indexedDB/IDBKeyRange.cpp
@@ -94,16 +94,18 @@ IDBKeyRange::AssertIsOnOwningThread() co
 #endif // DEBUG
 
 // static
 nsresult
 IDBKeyRange::FromJSVal(JSContext* aCx,
                        JS::Handle<JS::Value> aVal,
                        IDBKeyRange** aKeyRange)
 {
+  MOZ_ASSERT_IF(!aCx, aVal.isUndefined());
+
   RefPtr<IDBKeyRange> keyRange;
 
   if (aVal.isNullOrUndefined()) {
     // undefined and null returns no IDBKeyRange.
     keyRange.forget(aKeyRange);
     return NS_OK;
   }
 
--- a/dom/indexedDB/IDBKeyRange.h
+++ b/dom/indexedDB/IDBKeyRange.h
@@ -52,16 +52,17 @@ protected:
 #ifdef DEBUG
   PRThread* mOwningThread;
 #endif
 
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBKeyRange)
 
+  // aCx is allowed to be null, but only if aVal.isUndefined().
   static nsresult
   FromJSVal(JSContext* aCx,
             JS::Handle<JS::Value> aVal,
             IDBKeyRange** aKeyRange);
 
   static already_AddRefed<IDBKeyRange>
   FromSerialized(const indexedDB::SerializedKeyRange& aKeyRange);
 
--- a/dom/indexedDB/IDBObjectStore.cpp
+++ b/dom/indexedDB/IDBObjectStore.cpp
@@ -2084,16 +2084,17 @@ IDBObjectStore::Count(JSContext* aCx,
 already_AddRefed<IDBRequest>
 IDBObjectStore::OpenCursorInternal(bool aKeysOnly,
                                    JSContext* aCx,
                                    JS::Handle<JS::Value> aRange,
                                    IDBCursorDirection aDirection,
                                    ErrorResult& aRv)
 {
   AssertIsOnOwningThread();
+  MOZ_ASSERT_IF(!aCx, aRange.isUndefined());
 
   if (mDeletedSpec) {
     aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
     return nullptr;
   }
 
   if (!mTransaction->IsOpen()) {
     aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
--- a/dom/indexedDB/IDBObjectStore.h
+++ b/dom/indexedDB/IDBObjectStore.h
@@ -257,16 +257,26 @@ public:
   {
     AssertIsOnOwningThread();
 
     return OpenCursorInternal(/* aKeysOnly */ false, aCx, aRange, aDirection,
                               aRv);
   }
 
   already_AddRefed<IDBRequest>
+  OpenCursor(IDBCursorDirection aDirection,
+             ErrorResult& aRv)
+  {
+    AssertIsOnOwningThread();
+
+    return OpenCursorInternal(/* aKeysOnly */ false, nullptr,
+                              JS::UndefinedHandleValue, aDirection, aRv);
+  }
+
+  already_AddRefed<IDBRequest>
   OpenKeyCursor(JSContext* aCx,
                 JS::Handle<JS::Value> aRange,
                 IDBCursorDirection aDirection,
                 ErrorResult& aRv)
   {
     AssertIsOnOwningThread();
 
     return OpenCursorInternal(/* aKeysOnly */ true, aCx, aRange, aDirection,
@@ -332,16 +342,18 @@ private:
                  ErrorResult& aRv);
 
   already_AddRefed<IDBIndex>
   CreateIndexInternal(const nsAString& aName,
                       const KeyPath& aKeyPath,
                       const IDBIndexParameters& aOptionalParameters,
                       ErrorResult& aRv);
 
+  // aCx is allowed to be null but only if aRange.isUndefined().  In that case,
+  // we don't actually use aCx for anything, so it's OK.
   already_AddRefed<IDBRequest>
   OpenCursorInternal(bool aKeysOnly,
                      JSContext* aCx,
                      JS::Handle<JS::Value> aRange,
                      IDBCursorDirection aDirection,
                      ErrorResult& aRv);
 };