Bug 786688 - Part 2: Code cleanup. r=sicking
authorJan Varga <jan.varga@gmail.com>
Tue, 30 Oct 2012 07:11:58 +0100
changeset 111874 90e2bd5252aacdcad158528d75909a6fc6170c59
parent 111873 a0ac5962820230b62c72572c9defbae3827026ff
child 111875 be030e22b120d31a5efa2f6997b159057b1ff554
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewerssicking
bugs786688
milestone19.0a1
Bug 786688 - Part 2: Code cleanup. r=sicking
dom/base/nsDOMClassInfo.cpp
dom/indexedDB/IDBFactory.cpp
dom/indexedDB/IDBFactory.h
dom/indexedDB/ipc/IndexedDBParent.cpp
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -7984,27 +7984,27 @@ nsDOMMutationObserverSH::PreserveWrapper
   nsDOMMutationObserver* mutationObserver =
     nsDOMMutationObserver::FromSupports(aNative);
   nsContentUtils::PreserveWrapper(aNative, mutationObserver);
 }
 
 // IDBFactory helper
 
 /* static */
-template<nsresult (*func)(JSContext *cx, unsigned argc, jsval *vp, bool aDelete), bool aDelete>
+template<nsresult (*func)(JSContext *, unsigned, jsval *, bool), bool aDelete>
 JSBool
 IDBFNativeShim(JSContext *cx, unsigned argc, jsval *vp)
 {
   nsresult rv = (*func)(cx, argc, vp, aDelete);
   if (NS_FAILED(rv)) {
     xpc::Throw(cx, rv);
     return false;
   }
 
-  return true;  
+  return true;
 }
 
 /* static */ nsresult
 IDBFOpenForPrincipal(JSContext *cx, unsigned argc, JS::Value *vp, bool aDelete)
 {
   // Just to be on the extra-safe side
   if (!nsContentUtils::IsCallerChrome()) {
     MOZ_NOT_REACHED("Shouldn't be possible to get here");
@@ -8018,16 +8018,20 @@ IDBFOpenForPrincipal(JSContext *cx, unsi
                            &principalJS, &nameJS, &version)) {
     return NS_ERROR_FAILURE;
   }
 
   if (version < 1 && argc >= 3) {
     return NS_ERROR_TYPE_ERR;
   }
 
+  if (aDelete) {
+    version = 0;
+  }
+
   nsDependentJSString name;
   NS_ENSURE_TRUE(name.init(cx, nameJS), NS_ERROR_UNEXPECTED);
 
   nsCOMPtr<nsIPrincipal> principal = do_QueryWrapper(cx, principalJS);
   NS_ENSURE_TRUE(principal, NS_ERROR_NO_INTERFACE);
 
   nsCString extendedOrigin;
   nsresult rv = principal->GetExtendedOrigin(extendedOrigin);
@@ -8037,17 +8041,17 @@ IDBFOpenForPrincipal(JSContext *cx, unsi
     do_QueryWrapper(cx, JS_THIS_OBJECT(cx, vp));
   NS_ENSURE_TRUE(factory, NS_ERROR_NO_INTERFACE);
 
   nsRefPtr<indexedDB::IDBOpenDBRequest> request;
   rv = static_cast<indexedDB::IDBFactory*>(factory.get())->
     OpenCommon(name, version, extendedOrigin, aDelete, cx,
                getter_AddRefs(request));
   NS_ENSURE_SUCCESS(rv, rv);
-  
+
   return WrapNative(cx, JS_GetGlobalForScopeChain(cx),
                     static_cast<nsIIDBOpenDBRequest*>(request),
                     &NS_GET_IID(nsIIDBOpenDBRequest), true, vp);
 }
 
 NS_IMETHODIMP
 IDBFactorySH::PostCreatePrototype(JSContext * cx, JSObject * proto)
 {
@@ -8056,17 +8060,17 @@ IDBFactorySH::PostCreatePrototype(JSCont
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (xpc::AccessCheck::isChrome(js::GetObjectCompartment(proto)) &&
       (!JS_DefineFunction(cx, proto, "openForPrincipal",
                           IDBFNativeShim<IDBFOpenForPrincipal, false>,
                           3, JSPROP_ENUMERATE) ||
        !JS_DefineFunction(cx, proto, "deleteForPrincipal",
                           IDBFNativeShim<IDBFOpenForPrincipal, true>,
-                          3, JSPROP_ENUMERATE))) {
+                          2, JSPROP_ENUMERATE))) {
     return NS_ERROR_UNEXPECTED;
   }
 
   return rv;
 }
 
 // IDBEventTarget helper
 
--- a/dom/indexedDB/IDBFactory.cpp
+++ b/dom/indexedDB/IDBFactory.cpp
@@ -579,31 +579,31 @@ IDBFactory::Open(const nsAString& aName,
                  uint8_t aArgc,
                  nsIIDBOpenDBRequest** _retval)
 {
   if (aVersion < 1 && aArgc) {
     return NS_ERROR_TYPE_ERR;
   }
 
   nsRefPtr<IDBOpenDBRequest> request;
-  nsresult rv = OpenCommon(aName, aVersion, mASCIIOrigin, false, aCx,
+  nsresult rv = OpenCommon(aName, aVersion, false, aCx,
                            getter_AddRefs(request));
   NS_ENSURE_SUCCESS(rv, rv);
 
   request.forget(_retval);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 IDBFactory::DeleteDatabase(const nsAString& aName,
                            JSContext* aCx,
                            nsIIDBOpenDBRequest** _retval)
 {
   nsRefPtr<IDBOpenDBRequest> request;
-  nsresult rv = OpenCommon(aName, 0, mASCIIOrigin, true, aCx, getter_AddRefs(request));
+  nsresult rv = OpenCommon(aName, 0, true, aCx, getter_AddRefs(request));
   NS_ENSURE_SUCCESS(rv, rv);
 
   request.forget(_retval);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 IDBFactory::Cmp(const jsval& aFirst,
--- a/dom/indexedDB/IDBFactory.h
+++ b/dom/indexedDB/IDBFactory.h
@@ -92,16 +92,27 @@ public:
   nsresult
   OpenCommon(const nsAString& aName,
              int64_t aVersion,
              const nsACString& aASCIIOrigin,
              bool aDeleting,
              JSContext* aCallingCx,
              IDBOpenDBRequest** _retval);
 
+  nsresult
+  OpenCommon(const nsAString& aName,
+             int64_t aVersion,
+             bool aDeleting,
+             JSContext* aCallingCx,
+             IDBOpenDBRequest** _retval)
+  {
+    return OpenCommon(aName, aVersion, mASCIIOrigin, aDeleting, aCallingCx,
+                      _retval);
+  }
+
   void
   SetActor(IndexedDBChild* aActorChild)
   {
     NS_ASSERTION(!aActorChild || !mActorChild, "Shouldn't have more than one!");
     mActorChild = aActorChild;
   }
 
   void
--- a/dom/indexedDB/ipc/IndexedDBParent.cpp
+++ b/dom/indexedDB/ipc/IndexedDBParent.cpp
@@ -84,18 +84,18 @@ IndexedDBParent::ActorDestroy(ActorDestr
 bool
 IndexedDBParent::RecvPIndexedDBDatabaseConstructor(
                                                PIndexedDBDatabaseParent* aActor,
                                                const nsString& aName,
                                                const uint64_t& aVersion)
 {
   nsRefPtr<IDBOpenDBRequest> request;
   nsresult rv =
-    mFactory->OpenCommon(aName, aVersion, mFactory->GetASCIIOrigin(), false,
-                         nullptr, getter_AddRefs(request));
+    mFactory->OpenCommon(aName, aVersion, false, nullptr,
+                         getter_AddRefs(request));
   NS_ENSURE_SUCCESS(rv, false);
 
   IndexedDBDatabaseParent* actor =
     static_cast<IndexedDBDatabaseParent*>(aActor);
 
   rv = actor->SetOpenRequest(request);
   NS_ENSURE_SUCCESS(rv, false);
 
@@ -108,18 +108,17 @@ IndexedDBParent::RecvPIndexedDBDeleteDat
                                   const nsString& aName)
 {
   IndexedDBDeleteDatabaseRequestParent* actor =
     static_cast<IndexedDBDeleteDatabaseRequestParent*>(aActor);
 
   nsRefPtr<IDBOpenDBRequest> request;
 
   nsresult rv =
-    mFactory->OpenCommon(aName, 0, mFactory->GetASCIIOrigin(), true, nullptr,
-                         getter_AddRefs(request));
+    mFactory->OpenCommon(aName, 0, true, nullptr, getter_AddRefs(request));
   NS_ENSURE_SUCCESS(rv, false);
 
   rv = actor->SetOpenRequest(request);
   NS_ENSURE_SUCCESS(rv, false);
 
   return true;
 }