Implement crash-reporter.getLastLastCrashReport API on OS X.

This commit is contained in:
Haojian Wu 2015-06-03 09:47:42 +08:00
parent 2396b51cb6
commit 4457edb1d3
6 changed files with 72 additions and 0 deletions

View file

@ -31,10 +31,34 @@ struct Converter<std::map<std::string, std::string> > {
}
};
template<>
struct Converter<std::vector<crash_reporter::CrashReporter::UploadReportResult> > {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const std::vector<
crash_reporter::CrashReporter::UploadReportResult>& reports) {
v8::Local<v8::Array> result(v8::Array::New(isolate, reports.size()));
for (size_t i = 0; i < reports.size(); ++i) {
mate::Dictionary dict(isolate, v8::Object::New(isolate));
dict.Set("date", reports[i].first);
dict.Set("id", reports[i].second);
v8::TryCatch try_catch;
result->Set(static_cast<uint32>(i), dict.GetHandle());
if (try_catch.HasCaught())
LOG(ERROR) << "Setter for index " << i << " threw an exception.";
}
return result;
}
};
} // namespace mate
namespace {
std::vector<crash_reporter::CrashReporter::UploadReportResult>
GetUploadedReports() {
return (crash_reporter::CrashReporter::GetInstance())->GetUploadedReports();
}
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
v8::Local<v8::Context> context, void* priv) {
using crash_reporter::CrashReporter;
@ -42,6 +66,7 @@ void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
dict.SetMethod("start",
base::Bind(&CrashReporter::Start,
base::Unretained(CrashReporter::GetInstance())));
dict.SetMethod("_getUploadedReports", &GetUploadedReports);
}
} // namespace