refactor: convert crash reporter to gin (#17952)
This commit is contained in:
parent
493af7f84c
commit
3949f0bd50
10 changed files with 174 additions and 72 deletions
|
@ -277,41 +277,6 @@ struct Converter<std::set<T>> {
|
|||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct Converter<std::map<std::string, T>> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
std::map<std::string, T>* out) {
|
||||
if (!val->IsObject())
|
||||
return false;
|
||||
|
||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
v8::Local<v8::Object> dict = val->ToObject(context).ToLocalChecked();
|
||||
v8::Local<v8::Array> keys =
|
||||
dict->GetOwnPropertyNames(context).ToLocalChecked();
|
||||
for (uint32_t i = 0; i < keys->Length(); ++i) {
|
||||
v8::Local<v8::Value> key = keys->Get(context, i).ToLocalChecked();
|
||||
T value;
|
||||
if (Converter<T>::FromV8(
|
||||
isolate, dict->Get(context, key).ToLocalChecked(), &value))
|
||||
(*out)[gin::V8ToString(isolate, key)] = std::move(value);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
const std::map<std::string, T>& val) {
|
||||
v8::Local<v8::Object> result = v8::Object::New(isolate);
|
||||
auto context = isolate->GetCurrentContext();
|
||||
for (auto i = val.begin(); i != val.end(); i++) {
|
||||
result
|
||||
->Set(context, Converter<T>::ToV8(isolate, i->first),
|
||||
Converter<T>::ToV8(isolate, i->second))
|
||||
.Check();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
// Convenience functions that deduce T.
|
||||
template <typename T>
|
||||
v8::Local<v8::Value> ConvertToV8(v8::Isolate* isolate, const T& input) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue