From 864a5a55e1619d19416ae4948c09d176cb58eb21 Mon Sep 17 00:00:00 2001 From: Tom Schuster Date: Thu, 23 Jan 2014 20:49:40 +0100 Subject: [PATCH] Bug 961490 - More exact rooting in dom/indexedDB. r=terrence,khuey --- dom/indexedDB/IDBKeyRange.cpp | 8 ++++---- dom/indexedDB/IDBKeyRange.h | 2 +- dom/indexedDB/Key.cpp | 17 ++++++----------- dom/indexedDB/Key.h | 12 ++++++------ 4 files changed, 17 insertions(+), 22 deletions(-) diff --git a/dom/indexedDB/IDBKeyRange.cpp b/dom/indexedDB/IDBKeyRange.cpp index b4690d71133..96c9cf745d9 100644 --- a/dom/indexedDB/IDBKeyRange.cpp +++ b/dom/indexedDB/IDBKeyRange.cpp @@ -29,7 +29,7 @@ namespace { inline nsresult GetKeyFromJSVal(JSContext* aCx, - jsval aVal, + JS::Handle aVal, Key& aKey, bool aAllowUnset = false) { @@ -52,7 +52,7 @@ GetKeyFromJSVal(JSContext* aCx, // static nsresult IDBKeyRange::FromJSVal(JSContext* aCx, - const jsval& aVal, + JS::Handle aVal, IDBKeyRange** aKeyRange) { nsRefPtr keyRange; @@ -145,8 +145,8 @@ IDBKeyRange::DropJSObjects() if (!mRooted) { return; } - mCachedLowerVal = JSVAL_VOID; - mCachedUpperVal = JSVAL_VOID; + mCachedLowerVal = JS::UndefinedValue(); + mCachedUpperVal = JS::UndefinedValue(); mHaveCachedLowerVal = false; mHaveCachedUpperVal = false; mRooted = false; diff --git a/dom/indexedDB/IDBKeyRange.h b/dom/indexedDB/IDBKeyRange.h index f22c721705a..cc64527dcb5 100644 --- a/dom/indexedDB/IDBKeyRange.h +++ b/dom/indexedDB/IDBKeyRange.h @@ -36,7 +36,7 @@ public: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBKeyRange) static nsresult FromJSVal(JSContext* aCx, - const jsval& aVal, + JS::Handle aVal, IDBKeyRange** aKeyRange); template diff --git a/dom/indexedDB/Key.cpp b/dom/indexedDB/Key.cpp index 45282f2ab33..4156e8f64ae 100644 --- a/dom/indexedDB/Key.cpp +++ b/dom/indexedDB/Key.cpp @@ -101,7 +101,7 @@ const int MaxArrayCollapse = 3; const int MaxRecursionDepth = 256; nsresult -Key::EncodeJSValInternal(JSContext* aCx, const jsval aVal, +Key::EncodeJSValInternal(JSContext* aCx, JS::Handle aVal, uint8_t aTypeOffset, uint16_t aRecursionDepth) { NS_ENSURE_TRUE(aRecursionDepth < MaxRecursionDepth, NS_ERROR_DOM_INDEXEDDB_DATA_ERR); @@ -109,7 +109,7 @@ Key::EncodeJSValInternal(JSContext* aCx, const jsval aVal, 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; @@ -118,13 +118,8 @@ Key::EncodeJSValInternal(JSContext* aCx, const jsval aVal, 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; } @@ -132,8 +127,8 @@ Key::EncodeJSValInternal(JSContext* aCx, const jsval aVal, return NS_OK; } - if (!JSVAL_IS_PRIMITIVE(aVal)) { - JS::Rooted obj(aCx, JSVAL_TO_OBJECT(aVal)); + if (aVal.isObject()) { + JS::Rooted obj(aCx, &aVal.toObject()); if (JS_IsArrayObject(aCx, obj)) { aTypeOffset += eMaxType; diff --git a/dom/indexedDB/Key.h b/dom/indexedDB/Key.h index 8b4932193b1..4ab780c225e 100644 --- a/dom/indexedDB/Key.h +++ b/dom/indexedDB/Key.h @@ -161,11 +161,11 @@ public: } nsresult SetFromJSVal(JSContext* aCx, - const JS::Value aVal) + JS::Handle aVal) { mBuffer.Truncate(); - if (JSVAL_IS_NULL(aVal) || JSVAL_IS_VOID(aVal)) { + if (aVal.isNull() || aVal.isUndefined()) { Unset(); return NS_OK; } @@ -184,7 +184,7 @@ public: JS::MutableHandle aVal) const { if (IsUnset()) { - aVal.set(JSVAL_VOID); + aVal.setUndefined(); return NS_OK; } @@ -211,7 +211,7 @@ public: nsresult AppendItem(JSContext* aCx, bool aFirstOfArray, - const JS::Value aVal) + JS::Handle aVal) { nsresult rv = EncodeJSVal(aCx, aVal, aFirstOfArray ? eMaxType : 0); if (NS_FAILED(rv)) { @@ -305,7 +305,7 @@ private: } // 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 aVal, uint8_t aTypeOffset) { return EncodeJSValInternal(aCx, aVal, aTypeOffset, 0); @@ -331,7 +331,7 @@ private: nsCString mBuffer; private: - nsresult EncodeJSValInternal(JSContext* aCx, const JS::Value aVal, + nsresult EncodeJSValInternal(JSContext* aCx, JS::Handle aVal, uint8_t aTypeOffset, uint16_t aRecursionDepth); static nsresult DecodeJSValInternal(const unsigned char*& aPos,