Bug 1260441 - Never pass a null js context to OpenCursor() r=bz
authorAlexandre Lissy <lissyx@lissyx.dyndns.org>
Wed, 30 Mar 2016 13:03:03 +0200
changeset 291130 5ba4fe816a3980fd20f3e3ffc92f6e714ce91d88
parent 291129 cb55f73763cd7838760ab747510d12e7f039f108
child 291131 41c11b33eedb73985d93e3ca63a3bb5c20a8d8ab
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1260441
milestone48.0a1
Bug 1260441 - Never pass a null js context to OpenCursor() r=bz MozReview-Commit-ID: 2Scs80wX411
dom/datastore/DataStoreService.cpp
dom/indexedDB/IDBObjectStore.cpp
dom/indexedDB/IDBObjectStore.h
dom/indexedDB/IDBRequest.cpp
--- a/dom/datastore/DataStoreService.cpp
+++ b/dom/datastore/DataStoreService.cpp
@@ -22,16 +22,17 @@
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/DOMError.h"
 #include "mozilla/dom/IDBCursor.h"
 #include "mozilla/dom/IDBObjectStore.h"
 #include "mozilla/dom/IDBRequest.h"
 #include "mozilla/dom/IDBTransaction.h"
 #include "mozilla/dom/PermissionMessageUtils.h"
 #include "mozilla/dom/Promise.h"
+#include "mozilla/dom/ScriptSettings.h"
 #include "mozilla/unused.h"
 
 #include "mozIApplication.h"
 #include "mozIApplicationClearPrivateDataParams.h"
 #include "nsIAppsService.h"
 #include "nsIDOMEvent.h"
 #include "nsIDocument.h"
 #include "nsIDOMGlobalPropertyInitializer.h"
@@ -405,17 +406,19 @@ public:
       mTxn = aDb->Transaction();
 
       RefPtr<IDBObjectStore> store =
       mTxn->ObjectStore(NS_LITERAL_STRING(DATASTOREDB_REVISION), error);
       if (NS_WARN_IF(error.Failed())) {
         return;
       }
 
-      mRequest = store->OpenCursor(IDBCursorDirection::Prev, error);
+      AutoJSAPI jsapi;
+      jsapi.Init();
+      mRequest = store->OpenCursor(jsapi.cx(), 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/IDBObjectStore.cpp
+++ b/dom/indexedDB/IDBObjectStore.cpp
@@ -2083,17 +2083,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());
+  MOZ_ASSERT(aCx);
 
   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,22 +257,23 @@ public:
   {
     AssertIsOnOwningThread();
 
     return OpenCursorInternal(/* aKeysOnly */ false, aCx, aRange, aDirection,
                               aRv);
   }
 
   already_AddRefed<IDBRequest>
-  OpenCursor(IDBCursorDirection aDirection,
+  OpenCursor(JSContext* aCx,
+             IDBCursorDirection aDirection,
              ErrorResult& aRv)
   {
     AssertIsOnOwningThread();
 
-    return OpenCursorInternal(/* aKeysOnly */ false, nullptr,
+    return OpenCursorInternal(/* aKeysOnly */ false, aCx,
                               JS::UndefinedHandleValue, aDirection, aRv);
   }
 
   already_AddRefed<IDBRequest>
   OpenKeyCursor(JSContext* aCx,
                 JS::Handle<JS::Value> aRange,
                 IDBCursorDirection aDirection,
                 ErrorResult& aRv)
@@ -342,18 +343,16 @@ 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);
 };
 
--- a/dom/indexedDB/IDBRequest.cpp
+++ b/dom/indexedDB/IDBRequest.cpp
@@ -111,16 +111,17 @@ IDBRequest::InitMembers()
 }
 
 // static
 already_AddRefed<IDBRequest>
 IDBRequest::Create(JSContext* aCx,
                    IDBDatabase* aDatabase,
                    IDBTransaction* aTransaction)
 {
+  MOZ_ASSERT(aCx);
   MOZ_ASSERT(aDatabase);
   aDatabase->AssertIsOnOwningThread();
 
   RefPtr<IDBRequest> request = new IDBRequest(aDatabase);
   CaptureCaller(aCx, request->mFilename, &request->mLineNo, &request->mColumn);
 
   request->mTransaction = aTransaction;
   request->SetScriptOwner(aDatabase->GetScriptOwner());