Bug 961490 - More exact rooting in dom/indexedDB. r=terrence,khuey

This commit is contained in:
Tom Schuster 2014-01-23 20:49:40 +01:00
parent d30ed35589
commit 864a5a55e1
4 changed files with 17 additions and 22 deletions

View File

@ -29,7 +29,7 @@ namespace {
inline nsresult
GetKeyFromJSVal(JSContext* aCx,
jsval aVal,
JS::Handle<JS::Value> aVal,
Key& aKey,
bool aAllowUnset = false)
{
@ -52,7 +52,7 @@ GetKeyFromJSVal(JSContext* aCx,
// static
nsresult
IDBKeyRange::FromJSVal(JSContext* aCx,
const jsval& aVal,
JS::Handle<JS::Value> aVal,
IDBKeyRange** aKeyRange)
{
nsRefPtr<IDBKeyRange> 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;

View File

@ -36,7 +36,7 @@ public:
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>

View File

@ -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<JS::Value> 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<JSObject*> obj(aCx, JSVAL_TO_OBJECT(aVal));
if (aVal.isObject()) {
JS::Rooted<JSObject*> obj(aCx, &aVal.toObject());
if (JS_IsArrayObject(aCx, obj)) {
aTypeOffset += eMaxType;

View File

@ -161,11 +161,11 @@ public:
}
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;
}
@ -184,7 +184,7 @@ public:
JS::MutableHandle<JS::Value> 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<JS::Value> 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<JS::Value> 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<JS::Value> aVal,
uint8_t aTypeOffset, uint16_t aRecursionDepth);
static nsresult DecodeJSValInternal(const unsigned char*& aPos,