Skip to content

Commit

Permalink
fix compilation for 7-1-x
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Jan 15, 2020
1 parent 0a2f98a commit ac99384
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
28 changes: 28 additions & 0 deletions native_mate/native_mate/converter.h
Expand Up @@ -241,6 +241,34 @@ struct Converter<std::vector<T>> {
}
};

template <typename T1, typename T2>
struct Converter<std::pair<T1, T2>> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const std::pair<T1, T2>& val) {
v8::Local<v8::Array> result(v8::Array::New(isolate, 2));
auto context = isolate->GetCurrentContext();
result->Set(context, 0, Converter<T1>::ToV8(isolate, val.first)).Check();
result->Set(context, 1, Converter<T2>::ToV8(isolate, val.second)).Check();
return result;
}
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
std::pair<T1, T2>* out) {
if (!val->IsArray())
return false;

v8::Local<v8::Array> array(v8::Local<v8::Array>::Cast(val));
if (array->Length() != 2)
return false;

auto context = isolate->GetCurrentContext();
return Converter<T1>::FromV8(
isolate, array->Get(context, 0).ToLocalChecked(), &out->first) &&
Converter<T2>::FromV8(
isolate, array->Get(context, 1).ToLocalChecked(), &out->second);
}
};

template <typename T>
struct Converter<std::set<T>> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
Expand Down
6 changes: 3 additions & 3 deletions shell/browser/api/atom_api_url_loader.cc
Expand Up @@ -33,21 +33,21 @@
#include "shell/common/node_includes.h"
#include "shell/common/promise_util.h"

namespace gin {
namespace mate {

template <>
struct Converter<network::mojom::HttpRawHeaderPairPtr> {
static v8::Local<v8::Value> ToV8(
v8::Isolate* isolate,
const network::mojom::HttpRawHeaderPairPtr& pair) {
gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
dict.Set("key", base::ToLowerASCII(pair->key));
dict.Set("value", pair->value);
return dict.GetHandle();
}
};

} // namespace gin
} // namespace mate

namespace electron {

Expand Down
24 changes: 0 additions & 24 deletions shell/common/api/atom_api_v8_util.cc
Expand Up @@ -28,30 +28,6 @@ struct hash<std::pair<Type1, Type2>> {

} // namespace std

namespace mate {

template <typename Type1, typename Type2>
struct Converter<std::pair<Type1, Type2>> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
std::pair<Type1, Type2>* out) {
if (!val->IsArray())
return false;

v8::Local<v8::Array> array(v8::Local<v8::Array>::Cast(val));
if (array->Length() != 2)
return false;

auto context = isolate->GetCurrentContext();
return Converter<Type1>::FromV8(
isolate, array->Get(context, 0).ToLocalChecked(), &out->first) &&
Converter<Type2>::FromV8(
isolate, array->Get(context, 1).ToLocalChecked(), &out->second);
}
};

} // namespace mate

namespace {

v8::Local<v8::Value> GetHiddenValue(v8::Isolate* isolate,
Expand Down

0 comments on commit ac99384

Please sign in to comment.