Bug 994811 part 2. Use ToJSValue in msMessage::GetDeliveryInfo. r=gene

There is one behavior change here: the old code converted null strings
in the MmsDeliveryInfo into "", but the new code will convert them to
a JS null value.
This commit is contained in:
Boris Zbarsky 2014-04-11 22:20:54 -04:00
Родитель 98f070ccaf
Коммит 1d8a40af7b
1 изменённых файлов: 3 добавлений и 68 удалений

Просмотреть файл

@ -14,6 +14,7 @@
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/mobilemessage/Constants.h" // For MessageType
#include "mozilla/dom/mobilemessage/SmsTypes.h"
#include "mozilla/dom/ToJSValue.h"
#include "nsDOMFile.h"
#include "nsCxPusher.h"
@ -467,76 +468,10 @@ MmsMessage::GetDeliveryInfo(JSContext* aCx, JS::MutableHandle<JS::Value> aDelive
return NS_OK;
}
JS::Rooted<JSObject*> deliveryInfo(
aCx, JS_NewArrayObject(aCx, length));
NS_ENSURE_TRUE(deliveryInfo, NS_ERROR_OUT_OF_MEMORY);
for (uint32_t i = 0; i < length; ++i) {
const MmsDeliveryInfo &info = mDeliveryInfo[i];
JS::Rooted<JSObject*> infoJsObj(
aCx, JS_NewObject(aCx, nullptr, JS::NullPtr(), JS::NullPtr()));
NS_ENSURE_TRUE(infoJsObj, NS_ERROR_OUT_OF_MEMORY);
JS::Rooted<JS::Value> tmpJsVal(aCx);
JSString* tmpJsStr;
// Get |info.mReceiver|.
tmpJsStr = JS_NewUCStringCopyN(aCx,
info.mReceiver.get(),
info.mReceiver.Length());
NS_ENSURE_TRUE(tmpJsStr, NS_ERROR_OUT_OF_MEMORY);
tmpJsVal.setString(tmpJsStr);
if (!JS_DefineProperty(aCx, infoJsObj, "receiver", tmpJsVal,
nullptr, nullptr, JSPROP_ENUMERATE)) {
return NS_ERROR_FAILURE;
}
// Get |info.mDeliveryStatus|.
tmpJsStr = JS_NewUCStringCopyN(aCx,
info.mDeliveryStatus.get(),
info.mDeliveryStatus.Length());
NS_ENSURE_TRUE(tmpJsStr, NS_ERROR_OUT_OF_MEMORY);
tmpJsVal.setString(tmpJsStr);
if (!JS_DefineProperty(aCx, infoJsObj, "deliveryStatus", tmpJsVal,
nullptr, nullptr, JSPROP_ENUMERATE)) {
return NS_ERROR_FAILURE;
}
// Get |info.mDeliveryTimestamp|.
tmpJsVal.setNumber(static_cast<double>(info.mDeliveryTimestamp));
if (!JS_DefineProperty(aCx, infoJsObj, "deliveryTimestamp", tmpJsVal,
nullptr, nullptr, JSPROP_ENUMERATE)) {
return NS_ERROR_FAILURE;
}
// Get |info.mReadStatus|.
tmpJsStr = JS_NewUCStringCopyN(aCx,
info.mReadStatus.get(),
info.mReadStatus.Length());
NS_ENSURE_TRUE(tmpJsStr, NS_ERROR_OUT_OF_MEMORY);
tmpJsVal.setString(tmpJsStr);
if (!JS_DefineProperty(aCx, infoJsObj, "readStatus", tmpJsVal,
nullptr, nullptr, JSPROP_ENUMERATE)) {
return NS_ERROR_FAILURE;
}
// Get |info.mReadTimestamp|.
tmpJsVal.setNumber(static_cast<double>(info.mReadTimestamp));
if (!JS_DefineProperty(aCx, infoJsObj, "readTimestamp", tmpJsVal,
nullptr, nullptr, JSPROP_ENUMERATE)) {
return NS_ERROR_FAILURE;
}
if (!JS_SetElement(aCx, deliveryInfo, i, infoJsObj)) {
return NS_ERROR_FAILURE;
}
if (!ToJSValue(aCx, mDeliveryInfo, aDeliveryInfo)) {
return NS_ERROR_OUT_OF_MEMORY;
}
aDeliveryInfo.setObject(*deliveryInfo);
return NS_OK;
}