Bug 961490 - More exact rooting in dom/indexedDB. r=terrence,khuey
authorTom Schuster <evilpies@gmail.com>
Thu, 23 Jan 2014 20:49:40 +0100
changeset 164881 2a93f0989941b661802123666a4d927c0b62ef48
parent 164880 7c3b5796373b70ce075ac8a3587ff0822e69282e
child 164882 4e559e11306b3a8dcbfdf73ee673bcdfb8369c1a
push id38846
push userevilpies@gmail.com
push dateThu, 23 Jan 2014 19:50:16 +0000
treeherdermozilla-inbound@16805a1975cd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence, khuey
bugs961490
milestone29.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 961490 - More exact rooting in dom/indexedDB. r=terrence,khuey
dom/indexedDB/IDBKeyRange.cpp
dom/indexedDB/IDBKeyRange.h
dom/indexedDB/Key.cpp
dom/indexedDB/Key.h
--- a/dom/indexedDB/IDBKeyRange.cpp
+++ b/dom/indexedDB/IDBKeyRange.cpp
@@ -24,17 +24,17 @@ using namespace mozilla;
 using namespace mozilla::dom;
 USING_INDEXEDDB_NAMESPACE
 using namespace mozilla::dom::indexedDB::ipc;
 
 namespace {
 
 inline nsresult
 GetKeyFromJSVal(JSContext* aCx,
-                jsval aVal,
+                JS::Handle<JS::Value> aVal,
                 Key& aKey,
                 bool aAllowUnset = false)
 {
   nsresult rv = aKey.SetFromJSVal(aCx, aVal);
   if (NS_FAILED(rv)) {
     NS_ASSERTION(NS_ERROR_GET_MODULE(rv) == NS_ERROR_MODULE_DOM_INDEXEDDB,
                  "Bad error code!");
     return rv;
@@ -47,17 +47,17 @@ GetKeyFromJSVal(JSContext* aCx,
   return NS_OK;
 }
 
 } // anonymous namespace
 
 // static
 nsresult
 IDBKeyRange::FromJSVal(JSContext* aCx,
-                       const jsval& aVal,
+                       JS::Handle<JS::Value> aVal,
                        IDBKeyRange** aKeyRange)
 {
   nsRefPtr<IDBKeyRange> keyRange;
 
   if (aVal.isNullOrUndefined()) {
     // undefined and null returns no IDBKeyRange.
     keyRange.forget(aKeyRange);
     return NS_OK;
@@ -140,18 +140,18 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF(IDBKeyRa
 NS_IMPL_CYCLE_COLLECTING_RELEASE(IDBKeyRange)
 
 void
 IDBKeyRange::DropJSObjects()
 {
   if (!mRooted) {
     return;
   }
-  mCachedLowerVal = JSVAL_VOID;
-  mCachedUpperVal = JSVAL_VOID;
+  mCachedLowerVal = JS::UndefinedValue();
+  mCachedUpperVal = JS::UndefinedValue();
   mHaveCachedLowerVal = false;
   mHaveCachedUpperVal = false;
   mRooted = false;
   mozilla::DropJSObjects(this);
 }
 
 IDBKeyRange::~IDBKeyRange()
 {
--- a/dom/indexedDB/IDBKeyRange.h
+++ b/dom/indexedDB/IDBKeyRange.h
@@ -31,17 +31,17 @@ class KeyRange;
 
 class IDBKeyRange MOZ_FINAL : public nsISupports
 {
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBKeyRange)
 
   static nsresult FromJSVal(JSContext* aCx,
-                            const jsval& aVal,
+                            JS::Handle<JS::Value> aVal,
                             IDBKeyRange** aKeyRange);
 
   template <class T>
   static already_AddRefed<IDBKeyRange>
   FromSerializedKeyRange(const T& aKeyRange);
 
   const Key& Lower() const
   {
--- a/dom/indexedDB/Key.cpp
+++ b/dom/indexedDB/Key.cpp
@@ -96,49 +96,44 @@ USING_INDEXEDDB_NAMESPACE
  [[]]          // 8
 */
 
 const int MaxArrayCollapse = 3;
 
 const int MaxRecursionDepth = 256;
 
 nsresult
-Key::EncodeJSValInternal(JSContext* aCx, const jsval aVal,
+Key::EncodeJSValInternal(JSContext* aCx, JS::Handle<JS::Value> aVal,
                          uint8_t aTypeOffset, uint16_t aRecursionDepth)
 {
   NS_ENSURE_TRUE(aRecursionDepth < MaxRecursionDepth, NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
 
   static_assert(eMaxType * MaxArrayCollapse < 256,
                 "Unable to encode jsvals.");
 
-  if (JSVAL_IS_STRING(aVal)) {
+  if (aVal.isString()) {
     nsDependentJSString str;
     if (!str.init(aCx, aVal)) {
       return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
     }
     EncodeString(str, aTypeOffset);
     return NS_OK;
   }
 
-  if (JSVAL_IS_INT(aVal)) {
-    EncodeNumber((double)JSVAL_TO_INT(aVal), eFloat + aTypeOffset);
-    return NS_OK;
-  }
-
-  if (JSVAL_IS_DOUBLE(aVal)) {
-    double d = JSVAL_TO_DOUBLE(aVal);
+  if (aVal.isNumber()) {
+    double d = aVal.toNumber();
     if (mozilla::IsNaN(d)) {
       return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
     }
     EncodeNumber(d, eFloat + aTypeOffset);
     return NS_OK;
   }
 
-  if (!JSVAL_IS_PRIMITIVE(aVal)) {
-    JS::Rooted<JSObject*> obj(aCx, JSVAL_TO_OBJECT(aVal));
+  if (aVal.isObject()) {
+    JS::Rooted<JSObject*> obj(aCx, &aVal.toObject());
     if (JS_IsArrayObject(aCx, obj)) {
       aTypeOffset += eMaxType;
 
       if (aTypeOffset == eMaxType * MaxArrayCollapse) {
         mBuffer.Append(aTypeOffset);
         aTypeOffset = 0;
       }
       NS_ASSERTION((aTypeOffset % eMaxType) == 0 &&
--- a/dom/indexedDB/Key.h
+++ b/dom/indexedDB/Key.h
@@ -156,21 +156,21 @@ public:
   void SetFromInteger(int64_t aInt)
   {
     mBuffer.Truncate();
     EncodeNumber(double(aInt), eFloat);
     TrimBuffer();
   }
 
   nsresult SetFromJSVal(JSContext* aCx,
-                        const JS::Value aVal)
+                        JS::Handle<JS::Value> aVal)
   {
     mBuffer.Truncate();
 
-    if (JSVAL_IS_NULL(aVal) || JSVAL_IS_VOID(aVal)) {
+    if (aVal.isNull() || aVal.isUndefined()) {
       Unset();
       return NS_OK;
     }
 
     nsresult rv = EncodeJSVal(aCx, aVal, 0);
     if (NS_FAILED(rv)) {
       Unset();
       return rv;
@@ -179,17 +179,17 @@ public:
 
     return NS_OK;
   }
 
   nsresult ToJSVal(JSContext* aCx,
                    JS::MutableHandle<JS::Value> aVal) const
   {
     if (IsUnset()) {
-      aVal.set(JSVAL_VOID);
+      aVal.setUndefined();
       return NS_OK;
     }
 
     const unsigned char* pos = BufferStart();
     nsresult rv = DecodeJSVal(pos, BufferEnd(), aCx, 0, aVal);
     NS_ENSURE_SUCCESS(rv, rv);
 
     NS_ASSERTION(pos >= BufferEnd(),
@@ -206,17 +206,17 @@ public:
     if (NS_SUCCEEDED(rv)) {
       aVal = value;
     }
     return rv;
   }
 
   nsresult AppendItem(JSContext* aCx,
                       bool aFirstOfArray,
-                      const JS::Value aVal)
+                      JS::Handle<JS::Value> aVal)
   {
     nsresult rv = EncodeJSVal(aCx, aVal, aFirstOfArray ? eMaxType : 0);
     if (NS_FAILED(rv)) {
       Unset();
       return rv;
     }
 
     return NS_OK;
@@ -300,17 +300,17 @@ private:
     while (!*end) {
       --end;
     }
 
     mBuffer.Truncate(end + 1 - mBuffer.BeginReading());
   }
 
   // Encoding functions. These append the encoded value to the end of mBuffer
-  inline nsresult EncodeJSVal(JSContext* aCx, const JS::Value aVal,
+  inline nsresult EncodeJSVal(JSContext* aCx, JS::Handle<JS::Value> aVal,
                               uint8_t aTypeOffset)
   {
     return EncodeJSValInternal(aCx, aVal, aTypeOffset, 0);
   }
   void EncodeString(const nsAString& aString, uint8_t aTypeOffset);
   void EncodeNumber(double aFloat, uint8_t aType);
 
   // Decoding functions. aPos points into mBuffer and is adjusted to point
@@ -326,17 +326,17 @@ private:
                            const unsigned char* aEnd,
                            nsString& aString);
   static double DecodeNumber(const unsigned char*& aPos,
                              const unsigned char* aEnd);
 
   nsCString mBuffer;
 
 private:
-  nsresult EncodeJSValInternal(JSContext* aCx, const JS::Value aVal,
+  nsresult EncodeJSValInternal(JSContext* aCx, JS::Handle<JS::Value> aVal,
                                uint8_t aTypeOffset, uint16_t aRecursionDepth);
 
   static nsresult DecodeJSValInternal(const unsigned char*& aPos,
                                       const unsigned char* aEnd,
                                       JSContext* aCx, uint8_t aTypeOffset,
                                       JS::MutableHandle<JS::Value> aVal, uint16_t aRecursionDepth);
 };