Bug 491196 don't implement static functions in headers
authortimeless@mozdev.org
Wed, 22 Jul 2009 17:31:03 -0500
changeset 30577 975b1965bb8c5d21746e263a21d73171001f6c91
parent 30576 2356ce1839424a10df51021471b7b9fd89b3c0c9
child 30578 29669195ef9784f6d7e11c47f0f67dab9e7e77b8
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs491196
milestone1.9.2a1pre
Bug 491196 don't implement static functions in headers r=sdwilsh Moving JSValStorageStatementBinder to mozStoragePrivateHelpers as bindJSValue storage/src/mozStorageStatementParams.h: At global scope: storage/src/mozStorageStatementParams.h:78: warning: ‘PRBool mozilla::storage::JSValStorageStatementBinder(JSContext*, mozIStorageStatement*, int, jsval)’ defined but not used storage/src/mozStorageStatementParams.h:78: warning: ‘PRBool mozilla::storage::JSValStorageStatementBinder(JSContext*, mozIStorageStatement*, int, jsval)’ defined but not used You get this once for each file that includes a header that defines a static function which is not used in that file.
storage/src/mozStoragePrivateHelpers.cpp
storage/src/mozStoragePrivateHelpers.h
storage/src/mozStorageStatement.cpp
storage/src/mozStorageStatementParams.cpp
storage/src/mozStorageStatementParams.h
storage/src/mozStorageStatementWrapper.cpp
storage/test/unit/test_statement_wrapper_automatically.js
storage/test/unit/test_storage_statement_wrapper.js
--- a/storage/src/mozStoragePrivateHelpers.cpp
+++ b/storage/src/mozStoragePrivateHelpers.cpp
@@ -35,21 +35,25 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "sqlite3.h"
 
+#include "jsapi.h"
+#include "jsdate.h"
+
 #include "nsPrintfCString.h"
 #include "nsString.h"
 #include "nsError.h"
 
 #include "mozStoragePrivateHelpers.h"
+#include "mozIStorageStatement.h"
 
 namespace mozilla {
 namespace storage {
 
 nsresult
 convertResultCode(int aSQLiteResultCode)
 {
   switch (aSQLiteResultCode) {
@@ -111,10 +115,66 @@ checkAndLogStatementPerformance(sqlite3_
   message.Append("occurred for the SQL statement '");
   nsPrintfCString address("0x%p", aStatement);
   message.Append(address);
   message.Append("'.  See https://developer.mozilla.org/En/Storage/Warnings "
                  "details.");
   NS_WARNING(message.get());
 }
 
+bool
+bindJSValue(JSContext *aCtx,
+            mozIStorageStatement *aStatement,
+            int aIdx,
+            jsval aValue)
+{
+  if (JSVAL_IS_INT(aValue)) {
+    int v = JSVAL_TO_INT(aValue);
+    (void)aStatement->BindInt32Parameter(aIdx, v);
+    return true;
+  }
+
+  if (JSVAL_IS_DOUBLE(aValue)) {
+    double d = *JSVAL_TO_DOUBLE(aValue);
+    (void)aStatement->BindDoubleParameter(aIdx, d);
+    return true;
+  }
+
+  if (JSVAL_IS_STRING(aValue)) {
+    JSString *str = JSVAL_TO_STRING(aValue);
+    nsDependentString value(
+      reinterpret_cast<PRUnichar *>(::JS_GetStringChars(str)),
+      ::JS_GetStringLength(str)
+    );
+    (void)aStatement->BindStringParameter(aIdx, value);
+    return true;
+  }
+
+  if (JSVAL_IS_BOOLEAN(aValue)) {
+    (void)aStatement->BindInt32Parameter(aIdx, (aValue == JSVAL_TRUE) ? 1 : 0);
+    return true;
+  }
+
+  if (JSVAL_IS_NULL(aValue)) {
+    (void)aStatement->BindNullParameter(aIdx);
+    return true;
+  }
+
+  if (JSVAL_IS_OBJECT(aValue)) {
+    JSObject *obj = JSVAL_TO_OBJECT(aValue);
+    // some special things
+    if (!::js_DateIsValid(aCtx, obj))
+      return false;
+    
+    double msecd = ::js_DateGetMsecSinceEpoch(aCtx, obj);
+    msecd *= 1000.0;
+    PRInt64 msec;
+    LL_D2L(msec, msecd);
+    
+    (void)aStatement->BindInt64Parameter(aIdx, msec);
+    return true;
+  }
+
+  return false;
+}
+
 } // namespace storage
 } // namespace mozilla
--- a/storage/src/mozStoragePrivateHelpers.h
+++ b/storage/src/mozStoragePrivateHelpers.h
@@ -43,16 +43,19 @@
 
 /**
  * This file contains convenience methods for mozStorage.
  */
 
 #include "sqlite3.h"
 #include "nsIVariant.h"
 #include "mozStorage.h"
+#include "jsapi.h"
+
+class mozIStorageStatement;
 
 namespace mozilla {
 namespace storage {
 
 ////////////////////////////////////////////////////////////////////////////////
 //// Macros
 
 #define ENSURE_INDEX_VALUE(aIndex, aCount) \
@@ -77,16 +80,25 @@ nsresult convertResultCode(int aSQLiteRe
  * made faster with the careful use of an index.
  *
  * @param aStatement
  *        The sqlite3_stmt object to check.
  */
 void checkAndLogStatementPerformance(sqlite3_stmt *aStatement);
 
 /**
+ *
+ */
+bool
+bindJSValue(JSContext *aCtx,
+            mozIStorageStatement *aStatement,
+            int aIdx,
+            jsval aValue);
+
+/**
  * Used to convert an nsIVariant to the proper SQLite type.
  */
 template <typename T>
 int variantToSQLiteT(T aObj, nsIVariant *aValue);
 #include "variantToSQLiteT_impl.h" // To keep this file easier to read.
 
 } // namespace storage
 } // namespace mozilla
--- a/storage/src/mozStorageStatement.cpp
+++ b/storage/src/mozStorageStatement.cpp
@@ -615,17 +615,17 @@ Statement::EscapeStringForLIKE(const nsA
                                const PRUnichar aEscapeChar,
                                nsAString &_escapedString)
 {
   const PRUnichar MATCH_ALL('%');
   const PRUnichar MATCH_ONE('_');
 
   _escapedString.Truncate(0);
 
-  for (PRInt32 i = 0; i < aValue.Length(); i++) {
+  for (PRUint32 i = 0; i < aValue.Length(); i++) {
     if (aValue[i] == aEscapeChar || aValue[i] == MATCH_ALL ||
         aValue[i] == MATCH_ONE)
       _escapedString += aEscapeChar;
     _escapedString += aValue[i];
   }
   return NS_OK;
 }
 
--- a/storage/src/mozStorageStatementParams.cpp
+++ b/storage/src/mozStorageStatementParams.cpp
@@ -36,17 +36,19 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsMemory.h"
 #include "nsString.h"
 
+#include "mozStoragePrivateHelpers.h"
 #include "mozStorageStatementParams.h"
+#include "mozIStorageStatement.h"
 
 namespace mozilla {
 namespace storage {
 
 ////////////////////////////////////////////////////////////////////////////////
 //// StatementParams
 
 StatementParams::StatementParams(mozIStorageStatement *aStatement) :
@@ -81,30 +83,30 @@ StatementParams::SetProperty(nsIXPConnec
                              jsval *_vp,
                              PRBool *_retval)
 {
   NS_ENSURE_TRUE(mStatement, NS_ERROR_NOT_INITIALIZED);
 
   if (JSVAL_IS_INT(aId)) {
     int idx = JSVAL_TO_INT(aId);
 
-    PRBool res = JSValStorageStatementBinder(aCtx, mStatement, idx, *_vp);
+    PRBool res = bindJSValue(aCtx, mStatement, idx, *_vp);
     NS_ENSURE_TRUE(res, NS_ERROR_UNEXPECTED);
   }
   else if (JSVAL_IS_STRING(aId)) {
     JSString *str = JSVAL_TO_STRING(aId);
     NS_ConvertUTF16toUTF8 name(::JS_GetStringChars(str),
                                ::JS_GetStringLength(str));
 
     // check to see if there's a parameter with this name
     PRUint32 index;
     nsresult rv = mStatement->GetParameterIndex(name, &index);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    PRBool res = JSValStorageStatementBinder(aCtx, mStatement, index, *_vp);
+    PRBool res = bindJSValue(aCtx, mStatement, index, *_vp);
     NS_ENSURE_TRUE(res, NS_ERROR_UNEXPECTED);
   }
   else {
     return NS_ERROR_INVALID_ARG;
   }
 
   *_retval = PR_TRUE;
   return NS_OK;
--- a/storage/src/mozStorageStatementParams.h
+++ b/storage/src/mozStorageStatementParams.h
@@ -38,19 +38,16 @@
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef _MOZSTORAGESTATEMENTPARAMS_H_
 #define _MOZSTORAGESTATEMENTPARAMS_H_
 
 #include "mozIStorageStatementWrapper.h"
 #include "nsIXPCScriptable.h"
 
-#include "jsapi.h"
-#include "jsdate.h"
-
 class mozIStorageStatement;
 
 namespace mozilla {
 namespace storage {
 
 class Statement;
 
 class StatementParams : public mozIStorageStatementParams
@@ -66,63 +63,12 @@ public:
 
 protected:
   mozIStorageStatement *mStatement;
   PRUint32 mParamCount;
 
   friend class Statement;
 };
 
-static
-PRBool
-JSValStorageStatementBinder(JSContext *aCtx,
-                            mozIStorageStatement *aStatement,
-                            int aIdx,
-                            jsval aValue)
-{
-  if (JSVAL_IS_INT(aValue)) {
-    int v = JSVAL_TO_INT(aValue);
-    (void)aStatement->BindInt32Parameter(aIdx, v);
-  }
-  else if (JSVAL_IS_DOUBLE(aValue)) {
-    double d = *JSVAL_TO_DOUBLE(aValue);
-    (void)aStatement->BindDoubleParameter(aIdx, d);
-  }
-  else if (JSVAL_IS_STRING(aValue)) {
-    JSString *str = JSVAL_TO_STRING(aValue);
-    nsDependentString value(
-      reinterpret_cast<PRUnichar *>(::JS_GetStringChars(str)),
-      ::JS_GetStringLength(str)
-    );
-    (void)aStatement->BindStringParameter(aIdx, value);
-  }
-  else if (JSVAL_IS_BOOLEAN(aValue)) {
-    (void)aStatement->BindInt32Parameter(aIdx, (aValue == JSVAL_TRUE) ? 1 : 0);
-  }
-  else if (JSVAL_IS_NULL(aValue)) {
-    (void)aStatement->BindNullParameter(aIdx);
-  }
-  else if (JSVAL_IS_OBJECT(aValue)) {
-    JSObject *obj = JSVAL_TO_OBJECT(aValue);
-    // some special things
-    if (::js_DateIsValid (aCtx, obj)) {
-      double msecd = ::js_DateGetMsecSinceEpoch(aCtx, obj);
-      msecd *= 1000.0;
-      PRInt64 msec;
-      LL_D2L(msec, msecd);
-
-      (void)aStatement->BindInt64Parameter(aIdx, msec);
-    }
-    else {
-      return PR_FALSE;
-    }
-  }
-  else {
-    return PR_FALSE;
-  }
-
-  return PR_TRUE;
-}
-
 } // namespace storage
 } // namespace mozilla
 
 #endif /* _MOZSTORAGESTATEMENTPARAMS_H_ */
--- a/storage/src/mozStorageStatementWrapper.cpp
+++ b/storage/src/mozStorageStatementWrapper.cpp
@@ -35,16 +35,17 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsString.h"
 
+#include "mozStoragePrivateHelpers.h"
 #include "mozStorageStatementWrapper.h"
 #include "mozStorageStatementParams.h"
 #include "mozStorageStatementRow.h"
 
 #include "sqlite3.h"
 
 namespace mozilla {
 namespace storage {
@@ -197,17 +198,17 @@ StatementWrapper::Call(nsIXPConnectWrapp
     return NS_ERROR_FAILURE;
   }
 
   // reset
   (void)mStatement->Reset();
 
   // bind parameters
   for (int i = 0; i < (int)aArgc; i++) {
-    if (!JSValStorageStatementBinder(aCtx, mStatement, i, aArgv[i])) {
+    if (!bindJSValue(aCtx, mStatement, i, aArgv[i])) {
       *_retval = PR_FALSE;
       return NS_ERROR_INVALID_ARG;
     }
   }
 
   // if there are no results, we just execute
   if (mResultColumnCount == 0)
     (void)mStatement->Execute();
--- a/storage/test/unit/test_statement_wrapper_automatically.js
+++ b/storage/test/unit/test_statement_wrapper_automatically.js
@@ -174,18 +174,18 @@ function printValDesc(aVal)
   print("Testing value: toString=" + aVal +
         (toSource ? " toSource=" + toSource : ""));
 }
 
 function run_test()
 {
   setup();
 
-  // Static function JSValStorageStatementBinder in
-  // storage/src/mozStorageStatementParams.h tells us that the following types
+  // function JSValStorageStatementBinder in
+  // storage/src/mozStorageStatementParams.cpp tells us that the following types
   // and only the following types are valid as statement parameters:
   var vals = [
     1337,       // int
     3.1337,     // double
     "foo",      // string
     true,       // boolean
     null,       // null
     new Date(), // Date object
--- a/storage/test/unit/test_storage_statement_wrapper.js
+++ b/storage/test/unit/test_storage_statement_wrapper.js
@@ -183,18 +183,18 @@ function printValDesc(aVal)
   print("Testing value: toString=" + aVal +
         (toSource ? " toSource=" + toSource : ""));
 }
 
 function run_test()
 {
   setup();
 
-  // Static function JSValStorageStatementBinder in
-  // storage/src/mozStorageStatementParams.h tells us that the following types
+  // function JSValStorageStatementBinder in
+  // storage/src/mozStorageStatementParams.cpp tells us that the following types
   // and only the following types are valid as statement parameters:
   var vals = [
     1337,       // int
     3.1337,     // double
     "foo",      // string
     true,       // boolean
     null,       // null
     new Date(), // Date object