Bug 783431 - Fix js array initialization for bluetooth and telephony; r=mrbkap

This commit is contained in:
Kyle Machulis 2012-08-20 18:26:44 -07:00
parent a410f6a257
commit c1b5777800
2 changed files with 6 additions and 5 deletions

View File

@ -34,7 +34,7 @@ mozilla::dom::bluetooth::StringArrayToJSArray(JSContext* aCx, JSObject* aGlobal,
} else {
uint32_t valLength = aSourceArray.Length();
mozilla::ScopedDeleteArray<jsval> valArray(new jsval[valLength]);
JS::AutoArrayRooter tvr(aCx, valLength, valArray);
JS::AutoArrayRooter tvr(aCx, 0, valArray);
for (PRUint32 index = 0; index < valLength; index++) {
JSString* s = JS_NewUCStringCopyN(aCx, aSourceArray[index].BeginReading(),
aSourceArray[index].Length());
@ -43,6 +43,7 @@ mozilla::dom::bluetooth::StringArrayToJSArray(JSContext* aCx, JSObject* aGlobal,
return NS_ERROR_OUT_OF_MEMORY;
}
valArray[index] = STRING_TO_JSVAL(s);
tvr.changeLength(index + 1);
}
arrayObj = JS_NewArrayObject(aCx, valLength, valArray);
}
@ -83,14 +84,14 @@ mozilla::dom::bluetooth::BluetoothDeviceArrayToJSArray(JSContext* aCx, JSObject*
} else {
uint32_t valLength = aSourceArray.Length();
mozilla::ScopedDeleteArray<jsval> valArray(new jsval[valLength]);
JS::AutoArrayRooter tvr(aCx, valLength, valArray);
JS::AutoArrayRooter tvr(aCx, 0, valArray);
for (PRUint32 index = 0; index < valLength; index++) {
nsISupports* obj = aSourceArray[index]->ToISupports();
nsresult rv =
nsContentUtils::WrapNative(aCx, aGlobal, obj, &valArray[index]);
NS_ENSURE_SUCCESS(rv, rv);
tvr.changeLength(index + 1);
}
arrayObj = JS_NewArrayObject(aCx, valLength, valArray);
}

View File

@ -56,14 +56,14 @@ nsTArrayToJSArray(JSContext* aCx, JSObject* aGlobal,
} else {
uint32_t valLength = aSourceArray.Length();
mozilla::ScopedDeleteArray<jsval> valArray(new jsval[valLength]);
JS::AutoArrayRooter tvr(aCx, valLength, valArray);
JS::AutoArrayRooter tvr(aCx, 0, valArray);
for (PRUint32 index = 0; index < valLength; index++) {
nsISupports* obj = aSourceArray[index]->ToISupports();
nsresult rv =
nsContentUtils::WrapNative(aCx, aGlobal, obj, &valArray[index]);
NS_ENSURE_SUCCESS(rv, rv);
tvr.changeLength(index + 1);
}
arrayObj = JS_NewArrayObject(aCx, valLength, valArray);
}