Bug 1007034 - Add console warnings for the deprecated BindXXXParameter methods in mozIStorageBaseStatement and replace calls to the deprecated methods in dom/indexedDB/ActorsParent.cpp. r=mak
authorSajid Ahmed <sajid.ahmed@mail.utoronto.ca>
Wed, 05 Apr 2017 14:08:25 -0400
changeset 399527 c2f7bd2c69dbca656ae73e0a09e91ac131c053bf
parent 399526 f6144ffbe6368251d2a4fb57c2f112b03b58092f
child 399528 4b283abc6b68da4b4f9656b0231eb487342f5068
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1007034
milestone55.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 1007034 - Add console warnings for the deprecated BindXXXParameter methods in mozIStorageBaseStatement and replace calls to the deprecated methods in dom/indexedDB/ActorsParent.cpp. r=mak
dom/indexedDB/ActorsParent.cpp
storage/StorageBaseStatementInternal.h
storage/mozStorageHelper.h
--- a/dom/indexedDB/ActorsParent.cpp
+++ b/dom/indexedDB/ActorsParent.cpp
@@ -1292,27 +1292,27 @@ UpgradeSchemaFrom4To5(mozIStorageConnect
   ), getter_AddRefs(stmt));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   {
     mozStorageStatementScoper scoper(stmt);
 
-    rv = stmt->BindStringParameter(0, name);
-    if (NS_WARN_IF(NS_FAILED(rv))) {
-      return rv;
-    }
-
-    rv = stmt->BindInt32Parameter(1, intVersion);
-    if (NS_WARN_IF(NS_FAILED(rv))) {
-      return rv;
-    }
-
-    rv = stmt->BindInt64Parameter(2, dataVersion);
+    rv = stmt->BindStringByIndex(0, name);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
+    }
+
+    rv = stmt->BindInt32ByIndex(1, intVersion);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
+    }
+
+    rv = stmt->BindInt64ByIndex(2, dataVersion);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
 
     rv = stmt->Execute();
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
--- a/storage/StorageBaseStatementInternal.h
+++ b/storage/StorageBaseStatementInternal.h
@@ -5,16 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_storage_StorageBaseStatementInternal_h_
 #define mozilla_storage_StorageBaseStatementInternal_h_
 
 #include "nsISupports.h"
 #include "nsCOMPtr.h"
 #include "nsAutoPtr.h"
+#include "mozStorageHelper.h"
 
 struct sqlite3;
 struct sqlite3_stmt;
 class mozIStorageBindingParamsArray;
 class mozIStorageBindingParams;
 class mozIStorageStatementCallback;
 class mozIStoragePendingStatement;
 
@@ -231,16 +232,17 @@ NS_DEFINE_STATIC_IID_ACCESSOR(StorageBas
   {                                                                           \
     _guard                                                                    \
     mozIStorageBindingParams *params = getParams();                           \
     NS_ENSURE_TRUE(params, NS_ERROR_OUT_OF_MEMORY);                           \
     return params->BIND_NAME_CONCAT(_name, ByIndex) _invArgs;                 \
   }                                                                           \
   NS_IMETHODIMP _class::BIND_NAME_CONCAT(_name, Parameter) _declIndex         \
   {                                                                           \
+    WARN_DEPRECATED();                                                        \
     _guard                                                                    \
     mozIStorageBindingParams *params = getParams();                           \
     NS_ENSURE_TRUE(params, NS_ERROR_OUT_OF_MEMORY);                           \
     return params->BIND_NAME_CONCAT(_name, ByIndex) _invArgs;                 \
   }
 
 /**
  * Implement BindByName/BindByIndex for the given class.
--- a/storage/mozStorageHelper.h
+++ b/storage/mozStorageHelper.h
@@ -4,16 +4,18 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MOZSTORAGEHELPER_H
 #define MOZSTORAGEHELPER_H
 
 #include "nsAutoPtr.h"
 #include "nsStringGlue.h"
 #include "mozilla/DebugOnly.h"
+#include "nsIConsoleService.h"
+#include "nsIScriptError.h"
 
 #include "mozIStorageAsyncConnection.h"
 #include "mozIStorageConnection.h"
 #include "mozIStorageStatement.h"
 #include "mozIStoragePendingStatement.h"
 #include "nsError.h"
 
 /**
@@ -201,9 +203,32 @@ protected:
   nsCOMPtr<mozIStorageStatement> mStatement;
 };
 
 // Use this to make queries uniquely identifiable in telemetry
 // statistics, especially PRAGMAs.  We don't include __LINE__ so that
 // queries are stable in the face of source code changes.
 #define MOZ_STORAGE_UNIQUIFY_QUERY_STR "/* " __FILE__ " */ "
 
+// Use this to show a console warning when using deprecated methods.
+#define WARN_DEPRECATED()                                                          \
+  PR_BEGIN_MACRO                                                                   \
+                                                                                   \
+  if (NS_IsMainThread()) {                                                         \
+    nsCOMPtr<nsIConsoleService> cs = do_GetService(NS_CONSOLESERVICE_CONTRACTID);  \
+                                                                                   \
+    if (cs) {                                                                      \
+      nsCString msg(__FUNCTION__);                                                 \
+      msg.AppendLiteral(" is deprecated and will be removed soon.");               \
+                                                                                   \
+      nsCOMPtr<nsIScriptError> e = do_CreateInstance(NS_SCRIPTERROR_CONTRACTID);   \
+      if (e && NS_SUCCEEDED(e->Init(NS_ConvertUTF8toUTF16(msg), EmptyString(),     \
+                                    EmptyString(), 0, 0,                           \
+                                    nsIScriptError::errorFlag, "Storage"))) {      \
+        cs->LogMessage(e);                                                         \
+      }                                                                            \
+    }                                                                              \
+  }                                                                                \
+  MOZ_ASSERT(false, "You are trying to use a deprecated mozStorage method. "       \
+                    "Check error message in console to identify the method name.");\
+  PR_END_MACRO
+
 #endif /* MOZSTORAGEHELPER_H */