chore: fix chromium-style errors in native_mate

Also clang-format some stuff.
This commit is contained in:
Jeremy Apthorp 2018-06-29 09:44:28 -07:00
parent 180b41ab73
commit 67673cbf7f
5 changed files with 45 additions and 51 deletions

View file

@ -6,18 +6,14 @@
namespace mate {
Dictionary::Dictionary()
: isolate_(NULL) {
}
Dictionary::Dictionary() : isolate_(NULL) {}
Dictionary::Dictionary(v8::Isolate* isolate,
v8::Local<v8::Object> object)
: isolate_(isolate),
object_(object) {
}
Dictionary::Dictionary(v8::Isolate* isolate, v8::Local<v8::Object> object)
: isolate_(isolate), object_(object) {}
Dictionary::~Dictionary() {
}
Dictionary::Dictionary(const Dictionary& other) = default;
Dictionary::~Dictionary() = default;
Dictionary Dictionary::CreateEmpty(v8::Isolate* isolate) {
return Dictionary(isolate, v8::Object::New(isolate));
@ -28,7 +24,7 @@ v8::Local<v8::Object> Dictionary::GetHandle() const {
}
v8::Local<v8::Value> Converter<Dictionary>::ToV8(v8::Isolate* isolate,
Dictionary val) {
Dictionary val) {
return val.GetHandle();
}

View file

@ -35,11 +35,12 @@ class Dictionary {
public:
Dictionary();
Dictionary(v8::Isolate* isolate, v8::Local<v8::Object> object);
Dictionary(const Dictionary& other);
virtual ~Dictionary();
static Dictionary CreateEmpty(v8::Isolate* isolate);
template<typename T>
template <typename T>
bool Get(const base::StringPiece& key, T* out) const {
// Check for existence before getting, otherwise this method will always
// returns true when T == v8::Local<v8::Value>.
@ -54,33 +55,30 @@ class Dictionary {
return ConvertFromV8(isolate_, val, out);
}
template<typename T>
template <typename T>
bool GetHidden(const base::StringPiece& key, T* out) const {
v8::Local<v8::Context> context = isolate_->GetCurrentContext();
v8::Local<v8::Private> privateKey =
v8::Private::ForApi(isolate_, StringToV8(isolate_, key));
v8::Local<v8::Value> value;
v8::Maybe<bool> result =
GetHandle()->HasPrivate(context, privateKey);
v8::Maybe<bool> result = GetHandle()->HasPrivate(context, privateKey);
if (internal::IsTrue(result) &&
GetHandle()->GetPrivate(context, privateKey).ToLocal(&value))
return ConvertFromV8(isolate_, value, out);
return false;
}
template<typename T>
template <typename T>
bool Set(const base::StringPiece& key, const T& val) {
v8::Local<v8::Value> v8_value;
if (!TryConvertToV8(isolate_, val, &v8_value))
return false;
v8::Maybe<bool> result =
GetHandle()->Set(isolate_->GetCurrentContext(),
StringToV8(isolate_, key),
v8_value);
v8::Maybe<bool> result = GetHandle()->Set(
isolate_->GetCurrentContext(), StringToV8(isolate_, key), v8_value);
return !result.IsNothing() && result.FromJust();
}
template<typename T>
template <typename T>
bool SetHidden(const base::StringPiece& key, T val) {
v8::Local<v8::Value> v8_value;
if (!TryConvertToV8(isolate_, val, &v8_value))
@ -93,20 +91,18 @@ class Dictionary {
return !result.IsNothing() && result.FromJust();
}
template<typename T>
template <typename T>
bool SetReadOnly(const base::StringPiece& key, T val) {
v8::Local<v8::Value> v8_value;
if (!TryConvertToV8(isolate_, val, &v8_value))
return false;
v8::Maybe<bool> result =
GetHandle()->DefineOwnProperty(isolate_->GetCurrentContext(),
StringToV8(isolate_, key),
v8_value,
v8::ReadOnly);
v8::Maybe<bool> result = GetHandle()->DefineOwnProperty(
isolate_->GetCurrentContext(), StringToV8(isolate_, key), v8_value,
v8::ReadOnly);
return !result.IsNothing() && result.FromJust();
}
template<typename T>
template <typename T>
bool SetMethod(const base::StringPiece& key, const T& callback) {
return GetHandle()->Set(
StringToV8(isolate_, key),
@ -132,10 +128,9 @@ class Dictionary {
v8::Local<v8::Object> object_;
};
template<>
template <>
struct Converter<Dictionary> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
Dictionary val);
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, Dictionary val);
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
Dictionary* out);

View file

@ -6,8 +6,7 @@
namespace mate {
PersistentDictionary::PersistentDictionary() {
}
PersistentDictionary::PersistentDictionary() {}
PersistentDictionary::PersistentDictionary(v8::Isolate* isolate,
v8::Local<v8::Object> object)
@ -15,8 +14,10 @@ PersistentDictionary::PersistentDictionary(v8::Isolate* isolate,
isolate_ = isolate;
}
PersistentDictionary::~PersistentDictionary() {
}
PersistentDictionary::PersistentDictionary(const PersistentDictionary& other) =
default;
PersistentDictionary::~PersistentDictionary() {}
v8::Local<v8::Object> PersistentDictionary::GetHandle() const {
return handle_->NewHandle();

View file

@ -16,15 +16,16 @@ class PersistentDictionary : public Dictionary {
public:
PersistentDictionary();
PersistentDictionary(v8::Isolate* isolate, v8::Local<v8::Object> object);
virtual ~PersistentDictionary();
PersistentDictionary(const PersistentDictionary& other);
~PersistentDictionary() override;
v8::Local<v8::Object> GetHandle() const override;
private:
scoped_refptr<RefCountedPersistent<v8::Object> > handle_;
scoped_refptr<RefCountedPersistent<v8::Object>> handle_;
};
template<>
template <>
struct Converter<PersistentDictionary> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,

View file

@ -6,9 +6,9 @@
#define NATIVE_MATE_WRAPPABLE_H_
#include "base/bind.h"
#include "native_mate/converter.h"
#include "native_mate/constructor.h"
#include "gin/per_isolate_data.h"
#include "native_mate/constructor.h"
#include "native_mate/converter.h"
namespace mate {
@ -18,25 +18,25 @@ void* FromV8Impl(v8::Isolate* isolate, v8::Local<v8::Value> val);
} // namespace internal
template<typename T>
template <typename T>
class Wrappable : public WrappableBase {
public:
Wrappable() {}
template<typename Sig>
template <typename Sig>
static void SetConstructor(v8::Isolate* isolate,
const base::Callback<Sig>& constructor) {
v8::Local<v8::FunctionTemplate> templ = CreateFunctionTemplate(
isolate, base::Bind(&internal::InvokeNew<Sig>, constructor));
templ->InstanceTemplate()->SetInternalFieldCount(1);
T::BuildPrototype(isolate, templ);
gin::PerIsolateData::From(isolate)->SetFunctionTemplate(
&kWrapperInfo, templ);
gin::PerIsolateData::From(isolate)->SetFunctionTemplate(&kWrapperInfo,
templ);
}
static v8::Local<v8::FunctionTemplate> GetConstructor(v8::Isolate* isolate) {
// Fill the object template.
auto data = gin::PerIsolateData::From(isolate);
auto* data = gin::PerIsolateData::From(isolate);
auto templ = data->GetFunctionTemplate(&kWrapperInfo);
if (templ.IsEmpty()) {
templ = v8::FunctionTemplate::New(isolate);
@ -55,8 +55,9 @@ class Wrappable : public WrappableBase {
// |wrapper| may be empty in some extreme cases, e.g., when
// Object.prototype.constructor is overwritten.
v8::Local<v8::Object> wrapper;
if (!templ->InstanceTemplate()->NewInstance(
isolate->GetCurrentContext()).ToLocal(&wrapper)) {
if (!templ->InstanceTemplate()
->NewInstance(isolate->GetCurrentContext())
.ToLocal(&wrapper)) {
// The current wrappable object will be no longer managed by V8. Delete
// this now.
delete this;
@ -72,8 +73,8 @@ class Wrappable : public WrappableBase {
};
// static
template<typename T>
gin::WrapperInfo Wrappable<T>::kWrapperInfo = { gin::kEmbedderNativeGin };
template <typename T>
gin::WrapperInfo Wrappable<T>::kWrapperInfo = {gin::kEmbedderNativeGin};
// This converter handles any subclass of Wrappable.
template <typename T>
@ -88,8 +89,8 @@ struct Converter<T*,
}
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val, T** out) {
*out = static_cast<T*>(static_cast<WrappableBase*>(
internal::FromV8Impl(isolate, val)));
*out = static_cast<T*>(
static_cast<WrappableBase*>(internal::FromV8Impl(isolate, val)));
return *out != nullptr;
}
};