Bug 906812: Remove nsISupports usage from IndexedDB WebIDL. r=sicking
authorKyle Huey <khuey@kylehuey.com>
Thu, 22 Aug 2013 22:17:10 -0700
changeset 144023 d3e6b1baf02e
parent 144022 e1bd096607b1
child 144024 c640b302f28a
push id25146
push userryanvm@gmail.com
push date2013-08-23 14:44 +0000
treeherdermozilla-central@487f1cb462cd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking
bugs906812
milestone26.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 906812: Remove nsISupports usage from IndexedDB WebIDL. r=sicking
dom/indexedDB/AsyncConnectionHelper.h
dom/indexedDB/IDBCursor.cpp
dom/indexedDB/IDBCursor.h
dom/indexedDB/IDBDatabase.cpp
dom/indexedDB/IDBRequest.cpp
dom/indexedDB/IDBRequest.h
dom/webidl/IDBCursor.webidl
dom/webidl/IDBRequest.webidl
--- a/dom/indexedDB/AsyncConnectionHelper.h
+++ b/dom/indexedDB/AsyncConnectionHelper.h
@@ -112,21 +112,16 @@ public:
     return !!mTransaction;
   }
 
   IDBTransaction* GetTransaction() const
   {
     return mTransaction;
   }
 
-  nsISupports* GetSource() const
-  {
-    return mRequest ? mRequest->Source() : nullptr;
-  }
-
   virtual nsresult GetResultCode() MOZ_OVERRIDE
   {
     return mResultCode;
   }
 
   enum ChildProcessSendResult
   {
     // The result was successfully sent to the child process
--- a/dom/indexedDB/IDBCursor.cpp
+++ b/dom/indexedDB/IDBCursor.cpp
@@ -22,20 +22,22 @@
 #include "ProfilerHelpers.h"
 #include "TransactionThreadPool.h"
 
 #include "ipc/IndexedDBChild.h"
 #include "ipc/IndexedDBParent.h"
 
 #include "IndexedDatabaseInlines.h"
 #include "mozilla/dom/BindingDeclarations.h"
+#include "mozilla/dom/UnionTypes.h"
 
 USING_INDEXEDDB_NAMESPACE
 using namespace mozilla::dom::indexedDB::ipc;
 using mozilla::dom::Optional;
+using mozilla::dom::IDBObjectStoreOrIDBIndexReturnValue;
 using mozilla::ErrorResult;
 
 static_assert(sizeof(size_t) >= sizeof(IDBCursor::Direction),
               "Relying on conversion between size_t and "
               "IDBCursor::Direction");
 
 namespace {
 
@@ -513,30 +515,27 @@ IDBCursor::GetDirection() const
     case DIRECTION_INVALID:
     default:
       MOZ_CRASH("Unknown direction!");
       return mozilla::dom::IDBCursorDirection::Next;
   }
 }
 
 
-already_AddRefed<nsISupports>
-IDBCursor::Source() const
+void
+IDBCursor::GetSource(IDBObjectStoreOrIDBIndexReturnValue& aSource) const
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 
-  nsCOMPtr<nsISupports> source;
   if (mType == OBJECTSTORE) {
-    source = do_QueryInterface(mObjectStore);
+    aSource.SetAsIDBObjectStore() = mObjectStore;
   }
   else {
-    source = do_QueryInterface(mIndex);
+    aSource.SetAsIDBIndex() = mIndex;
   }
-
-  return source.forget();
 }
 
 JS::Value
 IDBCursor::GetKey(JSContext* aCx, ErrorResult& aRv)
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 
   NS_ASSERTION(!mKey.IsUnset() || !mHaveValue, "Bad key!");
--- a/dom/indexedDB/IDBCursor.h
+++ b/dom/indexedDB/IDBCursor.h
@@ -17,16 +17,22 @@
 
 #include "mozilla/dom/indexedDB/IDBObjectStore.h"
 #include "mozilla/dom/indexedDB/Key.h"
 
 class nsIRunnable;
 class nsIScriptContext;
 class nsPIDOMWindow;
 
+namespace mozilla {
+namespace dom {
+class IDBObjectStoreOrIDBIndexReturnValue;
+}
+}
+
 BEGIN_INDEXEDDB_NAMESPACE
 
 class ContinueHelper;
 class ContinueObjectStoreHelper;
 class ContinueIndexHelper;
 class ContinueIndexObjectHelper;
 class IDBIndex;
 class IDBRequest;
@@ -154,18 +160,18 @@ public:
 
   // WebIDL
   IDBTransaction*
   GetParentObject() const
   {
     return mTransaction;
   }
 
-  already_AddRefed<nsISupports>
-  Source() const;
+  void
+  GetSource(IDBObjectStoreOrIDBIndexReturnValue& aSource) const;
 
   IDBCursorDirection
   GetDirection() const;
 
   JS::Value
   GetKey(JSContext* aCx, ErrorResult& aRv);
 
   JS::Value
--- a/dom/indexedDB/IDBDatabase.cpp
+++ b/dom/indexedDB/IDBDatabase.cpp
@@ -697,17 +697,17 @@ IDBDatabase::MozCreateFileHandle(const n
     return nullptr;
   }
 
   if (mClosed) {
     aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
     return nullptr;
   }
 
-  nsRefPtr<IDBRequest> request = IDBRequest::Create(nullptr, this, nullptr);
+  nsRefPtr<IDBRequest> request = IDBRequest::Create(this, nullptr);
 
   nsRefPtr<CreateFileHelper> helper =
     new CreateFileHelper(this, request, aName,
                          aType.WasPassed() ? aType.Value() : EmptyString());
 
   QuotaManager* quotaManager = QuotaManager::Get();
   NS_ASSERTION(quotaManager, "We should definitely have a manager here");
 
--- a/dom/indexedDB/IDBRequest.cpp
+++ b/dom/indexedDB/IDBRequest.cpp
@@ -4,42 +4,47 @@
  * 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/. */
 
 #include "IDBRequest.h"
 
 #include "nsIScriptContext.h"
 
 #include "mozilla/dom/IDBOpenDBRequestBinding.h"
+#include "mozilla/dom/UnionTypes.h"
 #include "nsComponentManagerUtils.h"
 #include "nsDOMClassInfoID.h"
 #include "nsDOMJSUtils.h"
 #include "nsContentUtils.h"
 #include "nsCxPusher.h"
 #include "nsEventDispatcher.h"
 #include "nsJSUtils.h"
 #include "nsPIDOMWindow.h"
 #include "nsStringGlue.h"
 #include "nsThreadUtils.h"
 #include "nsWrapperCacheInlines.h"
 
 #include "AsyncConnectionHelper.h"
+#include "IDBCursor.h"
 #include "IDBEvents.h"
 #include "IDBFactory.h"
+#include "IDBIndex.h"
+#include "IDBObjectStore.h"
 #include "IDBTransaction.h"
 
 namespace {
 
 #ifdef MOZ_ENABLE_PROFILER_SPS
 uint64_t gNextSerialNumber = 1;
 #endif
 
 } // anonymous namespace
 
 USING_INDEXEDDB_NAMESPACE
+using mozilla::dom::IDBObjectStoreOrIDBIndexOrIDBCursorReturnValue;
 
 IDBRequest::IDBRequest()
 : mResultVal(JSVAL_VOID),
   mActorParent(nullptr),
 #ifdef MOZ_ENABLE_PROFILER_SPS
   mSerialNumber(gNextSerialNumber++),
 #endif
   mErrorCode(NS_OK),
@@ -54,32 +59,99 @@ IDBRequest::IDBRequest()
 IDBRequest::~IDBRequest()
 {
   mResultVal = JSVAL_VOID;
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 }
 
 // static
 already_AddRefed<IDBRequest>
-IDBRequest::Create(nsISupports* aSource,
-                   IDBWrapperCache* aOwnerCache,
+IDBRequest::Create(IDBWrapperCache* aOwnerCache,
                    IDBTransaction* aTransaction)
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
   nsRefPtr<IDBRequest> request(new IDBRequest());
 
-  request->mSource = aSource;
   request->mTransaction = aTransaction;
   request->BindToOwner(aOwnerCache);
   request->SetScriptOwner(aOwnerCache->GetScriptOwner());
   request->CaptureCaller();
 
   return request.forget();
 }
 
+// static
+already_AddRefed<IDBRequest>
+IDBRequest::Create(IDBObjectStore* aSourceAsObjectStore,
+                   IDBWrapperCache* aOwnerCache,
+                   IDBTransaction* aTransaction)
+{
+  nsRefPtr<IDBRequest> request = Create(aOwnerCache, aTransaction);
+
+  request->mSourceAsObjectStore = aSourceAsObjectStore;
+
+  return request.forget();
+}
+
+// static
+already_AddRefed<IDBRequest>
+IDBRequest::Create(IDBIndex* aSourceAsIndex,
+                   IDBWrapperCache* aOwnerCache,
+                   IDBTransaction* aTransaction)
+{
+  nsRefPtr<IDBRequest> request = Create(aOwnerCache, aTransaction);
+
+  request->mSourceAsIndex = aSourceAsIndex;
+
+  return request.forget();
+}
+
+// static
+already_AddRefed<IDBRequest>
+IDBRequest::Create(IDBCursor* aSourceAsCursor,
+                   IDBWrapperCache* aOwnerCache,
+                   IDBTransaction* aTransaction)
+{
+  nsRefPtr<IDBRequest> request = Create(aOwnerCache, aTransaction);
+
+  request->mSourceAsCursor = aSourceAsCursor;
+
+  return request.forget();
+}
+
+#ifdef DEBUG
+void
+IDBRequest::AssertSourceIsCorrect() const
+{
+  // At most one of mSourceAs* is allowed to be non-null.  Check that by
+  // summing the double negation of each one and asserting the sum is at most
+  // 1.
+
+  MOZ_ASSERT(!!mSourceAsObjectStore + !!mSourceAsIndex + !!mSourceAsCursor <= 1);
+}
+#endif
+
+void
+IDBRequest::GetSource(Nullable<IDBObjectStoreOrIDBIndexOrIDBCursorReturnValue>& aSource) const
+{
+  MOZ_ASSERT(NS_IsMainThread());
+
+  AssertSourceIsCorrect();
+
+  if (mSourceAsObjectStore) {
+    aSource.SetValue().SetAsIDBObjectStore() = mSourceAsObjectStore;
+  } else if (mSourceAsIndex) {
+    aSource.SetValue().SetAsIDBIndex() = mSourceAsIndex;
+  } else if (mSourceAsCursor) {
+    aSource.SetValue().SetAsIDBCursor() = mSourceAsCursor;
+  } else {
+    aSource.SetNull();
+  }
+}
+
 void
 IDBRequest::Reset()
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
   mResultVal = JSVAL_VOID;
   mHaveResultOrErrorCode = false;
   mError = nullptr;
 }
@@ -276,24 +348,28 @@ IDBRequest::GetError(mozilla::ErrorResul
   return mError;
 }
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(IDBRequest)
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(IDBRequest, IDBWrapperCache)
   // Don't need NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS because
   // nsDOMEventTargetHelper does it for us.
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSource)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSourceAsObjectStore)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSourceAsIndex)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSourceAsCursor)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTransaction)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mError)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IDBRequest, IDBWrapperCache)
   tmp->mResultVal = JSVAL_VOID;
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mSource)
+  NS_IMPL_CYCLE_COLLECTION_UNLINK(mSourceAsObjectStore)
+  NS_IMPL_CYCLE_COLLECTION_UNLINK(mSourceAsIndex)
+  NS_IMPL_CYCLE_COLLECTION_UNLINK(mSourceAsCursor)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mTransaction)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mError)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(IDBRequest, IDBWrapperCache)
   // Don't need NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER because
   // nsDOMEventTargetHelper does it for us.
   NS_IMPL_CYCLE_COLLECTION_TRACE_JSVAL_MEMBER_CALLBACK(mResultVal)
--- a/dom/indexedDB/IDBRequest.h
+++ b/dom/indexedDB/IDBRequest.h
@@ -16,42 +16,61 @@
 #include "nsCycleCollectionParticipant.h"
 #include "nsWrapperCache.h"
 
 #include "mozilla/dom/indexedDB/IDBWrapperCache.h"
 
 class nsIScriptContext;
 class nsPIDOMWindow;
 
+namespace mozilla {
+namespace dom {
+class IDBObjectStoreOrIDBIndexOrIDBCursorReturnValue;
+}
+}
+
 BEGIN_INDEXEDDB_NAMESPACE
 
 class HelperBase;
+class IDBCursor;
 class IDBFactory;
+class IDBIndex;
+class IDBObjectStore;
 class IDBTransaction;
 class IndexedDBRequestParentBase;
 
 class IDBRequest : public IDBWrapperCache
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(IDBRequest,
                                                          IDBWrapperCache)
 
   static
-  already_AddRefed<IDBRequest> Create(nsISupports* aSource,
+  already_AddRefed<IDBRequest> Create(IDBWrapperCache* aOwnerCache,
+                                      IDBTransaction* aTransaction);
+
+  static
+  already_AddRefed<IDBRequest> Create(IDBObjectStore* aSource,
+                                      IDBWrapperCache* aOwnerCache,
+                                      IDBTransaction* aTransaction);
+
+  static
+  already_AddRefed<IDBRequest> Create(IDBIndex* aSource,
+                                      IDBWrapperCache* aOwnerCache,
+                                      IDBTransaction* aTransaction);
+  static
+  already_AddRefed<IDBRequest> Create(IDBCursor* aSource,
                                       IDBWrapperCache* aOwnerCache,
                                       IDBTransaction* aTransaction);
 
   // nsIDOMEventTarget
   virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor) MOZ_OVERRIDE;
 
-  nsISupports* Source()
-  {
-    return mSource;
-  }
+  void GetSource(Nullable<IDBObjectStoreOrIDBIndexOrIDBCursorReturnValue>& aSource) const;
 
   void Reset();
 
   nsresult NotifyHelperCompleted(HelperBase* aHelper);
   void NotifyHelperSentResultsToChildProcess(nsresult aRv);
 
   void SetError(nsresult aRv);
 
@@ -110,23 +129,16 @@ public:
   GetParentObject() const
   {
     return GetOwner();
   }
 
   JS::Value
   GetResult(JSContext* aCx, ErrorResult& aRv) const;
 
-  nsISupports*
-  GetSource() const
-  {
-    NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
-    return mSource;
-  }
-
   IDBTransaction*
   GetTransaction() const
   {
     NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
     return mTransaction;
   }
 
   IDBRequestReadyState
@@ -134,17 +146,28 @@ public:
 
   IMPL_EVENT_HANDLER(success);
   IMPL_EVENT_HANDLER(error);
 
 protected:
   IDBRequest();
   ~IDBRequest();
 
-  nsCOMPtr<nsISupports> mSource;
+  // At most one of these three fields can be non-null.
+  nsRefPtr<IDBObjectStore> mSourceAsObjectStore;
+  nsRefPtr<IDBIndex> mSourceAsIndex;
+  nsRefPtr<IDBCursor> mSourceAsCursor;
+
+  // Check that the above condition holds.
+#ifdef DEBUG
+  void AssertSourceIsCorrect() const;
+#else
+  void AssertSourceIsCorrect() const {}
+#endif
+
   nsRefPtr<IDBTransaction> mTransaction;
 
   JS::Heap<JS::Value> mResultVal;
   nsRefPtr<mozilla::dom::DOMError> mError;
   IndexedDBRequestParentBase* mActorParent;
   nsString mFilename;
 #ifdef MOZ_ENABLE_PROFILER_SPS
   uint64_t mSerialNumber;
--- a/dom/webidl/IDBCursor.webidl
+++ b/dom/webidl/IDBCursor.webidl
@@ -10,18 +10,17 @@
 enum IDBCursorDirection {
     "next",
     "nextunique",
     "prev",
     "prevunique"
 };
 
 interface IDBCursor {
-    // This should be: readonly    attribute (IDBObjectStore or IDBIndex) source;
-    readonly    attribute nsISupports source;
+    readonly    attribute (IDBObjectStore or IDBIndex) source;
 
     readonly    attribute IDBCursorDirection           direction;
 
     [Throws]
     readonly    attribute any                          key;
 
     [Throws]
     readonly    attribute any                          primaryKey;
--- a/dom/webidl/IDBRequest.webidl
+++ b/dom/webidl/IDBRequest.webidl
@@ -15,17 +15,17 @@ enum IDBRequestReadyState {
 
 interface IDBRequest : EventTarget {
     [Throws]
     readonly    attribute any                  result;
 
     [Throws]
     readonly    attribute DOMError?            error;
 
-    readonly    attribute nsISupports?         source;
+    readonly    attribute (IDBObjectStore or IDBIndex or IDBCursor)? source;
     readonly    attribute IDBTransaction?      transaction;
     readonly    attribute IDBRequestReadyState readyState;
 
     [SetterThrows]
                 attribute EventHandler         onsuccess;
 
     [SetterThrows]
                 attribute EventHandler         onerror;