Bug 1329111 - Use JSONWriter when generating the GetSharedLibraryInfo() JSON. r=njn

MozReview-Commit-ID: LZalkkFreym

--HG--
extra : rebase_source : 71d95c3ff6454d72515c33ea7df742d95e94872b
This commit is contained in:
Markus Stange 2017-03-13 17:08:38 -04:00
Родитель 5d618f99af
Коммит e552737d0a
1 изменённых файлов: 20 добавлений и 21 удалений

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

@ -1034,37 +1034,36 @@ private:
NS_IMPL_ISUPPORTS(ProfileSaveEvent, nsIProfileSaveEvent)
const static uint64_t kJS_MAX_SAFE_UINTEGER = +9007199254740991ULL;
static int64_t
SafeJSInteger(uint64_t aValue) {
return aValue <= kJS_MAX_SAFE_UINTEGER ? int64_t(aValue) : -1;
}
static void
AddSharedLibraryInfoToStream(std::ostream& aStream, const SharedLibrary& aLib)
AddSharedLibraryInfoToStream(JSONWriter& aWriter, const SharedLibrary& aLib)
{
aStream << "{";
aStream << "\"start\":" << aLib.GetStart();
aStream << ",\"end\":" << aLib.GetEnd();
aStream << ",\"offset\":" << aLib.GetOffset();
aStream << ",\"name\":\"" << aLib.GetNativeDebugPath() << "\"";
const std::string& breakpadId = aLib.GetBreakpadId();
aStream << ",\"breakpadId\":\"" << breakpadId << "\"";
aStream << "}";
aWriter.StartObjectElement();
aWriter.IntProperty("start", SafeJSInteger(aLib.GetStart()));
aWriter.IntProperty("end", SafeJSInteger(aLib.GetEnd()));
aWriter.IntProperty("offset", SafeJSInteger(aLib.GetOffset()));
aWriter.StringProperty("name", aLib.GetNativeDebugPath().c_str());
aWriter.StringProperty("breakpadId", aLib.GetBreakpadId().c_str());
aWriter.EndObject();
}
static std::string
GetSharedLibraryInfoStringInternal()
{
SharedLibraryInfo info = SharedLibraryInfo::GetInfoForSelf();
if (info.GetSize() == 0) {
return "[]";
}
std::ostringstream os;
os << "[";
AddSharedLibraryInfoToStream(os, info.GetEntry(0));
for (size_t i = 1; i < info.GetSize(); i++) {
os << ",";
AddSharedLibraryInfoToStream(os, info.GetEntry(i));
JSONWriter w(MakeUnique<OStreamJSONWriteFunc>(os));
w.StartArrayElement();
for (size_t i = 0; i < info.GetSize(); i++) {
AddSharedLibraryInfoToStream(w, info.GetEntry(i));
}
os << "]";
w.EndArray();
return os.str();
}