refactor: use C++11 member initializers in native_mate (#19925)

This commit is contained in:
Milan Burda 2019-08-26 02:16:28 +02:00 committed by Cheng Zhao
parent 1eda92859f
commit 181f663cf1
14 changed files with 27 additions and 31 deletions

View file

@ -24,16 +24,12 @@ std::string V8TypeAsString(v8::Isolate* isolate, v8::Local<v8::Value> value) {
} // namespace } // namespace
Arguments::Arguments() Arguments::Arguments() = default;
: isolate_(NULL), info_(NULL), next_(0), insufficient_arguments_(false) {}
Arguments::Arguments(const v8::FunctionCallbackInfo<v8::Value>& info) Arguments::Arguments(const v8::FunctionCallbackInfo<v8::Value>& info)
: isolate_(info.GetIsolate()), : isolate_(info.GetIsolate()), info_(&info) {}
info_(&info),
next_(0),
insufficient_arguments_(false) {}
Arguments::~Arguments() {} Arguments::~Arguments() = default;
v8::Local<v8::Value> Arguments::PeekNext() const { v8::Local<v8::Value> Arguments::PeekNext() const {
if (next_ >= info_->Length()) if (next_ >= info_->Length())

View file

@ -95,10 +95,10 @@ class Arguments {
v8::Isolate* isolate() const { return isolate_; } v8::Isolate* isolate() const { return isolate_; }
private: private:
v8::Isolate* isolate_; v8::Isolate* isolate_ = nullptr;
const v8::FunctionCallbackInfo<v8::Value>* info_; const v8::FunctionCallbackInfo<v8::Value>* info_ = nullptr;
int next_; int next_ = 0;
bool insufficient_arguments_; bool insufficient_arguments_ = false;
}; };
} // namespace mate } // namespace mate

View file

@ -6,7 +6,7 @@
namespace mate { namespace mate {
Dictionary::Dictionary() : isolate_(NULL) {} Dictionary::Dictionary() = default;
Dictionary::Dictionary(v8::Isolate* isolate, v8::Local<v8::Object> object) Dictionary::Dictionary(v8::Isolate* isolate, v8::Local<v8::Object> object)
: isolate_(isolate), object_(object) {} : isolate_(isolate), object_(object) {}

View file

@ -125,7 +125,7 @@ class Dictionary {
v8::Isolate* isolate() const { return isolate_; } v8::Isolate* isolate() const { return isolate_; }
protected: protected:
v8::Isolate* isolate_; v8::Isolate* isolate_ = nullptr;
private: private:
v8::Local<v8::Object> object_; v8::Local<v8::Object> object_;

View file

@ -83,10 +83,10 @@ class CallbackHolder : public CallbackHolderBase {
int flags) int flags)
: CallbackHolderBase(isolate), callback(callback), flags(flags) {} : CallbackHolderBase(isolate), callback(callback), flags(flags) {}
base::Callback<Sig> callback; base::Callback<Sig> callback;
int flags; int flags = 0;
private: private:
virtual ~CallbackHolder() {} virtual ~CallbackHolder() = default;
DISALLOW_COPY_AND_ASSIGN(CallbackHolder); DISALLOW_COPY_AND_ASSIGN(CallbackHolder);
}; };
@ -162,9 +162,9 @@ struct ArgumentHolder {
using ArgLocalType = typename CallbackParamTraits<ArgType>::LocalType; using ArgLocalType = typename CallbackParamTraits<ArgType>::LocalType;
ArgLocalType value; ArgLocalType value;
bool ok; bool ok = false;
ArgumentHolder(Arguments* args, int create_flags) : ok(false) { ArgumentHolder(Arguments* args, int create_flags) {
if (index == 0 && (create_flags & HolderIsFirstArgument) && if (index == 0 && (create_flags & HolderIsFirstArgument) &&
Destroyable::IsDestroyed(args)) { Destroyable::IsDestroyed(args)) {
args->ThrowError("Object has been destroyed"); args->ThrowError("Object has been destroyed");

View file

@ -16,7 +16,7 @@ namespace mate {
template <typename T> template <typename T>
class Handle { class Handle {
public: public:
Handle() : object_(NULL) {} Handle() = default;
Handle(v8::Local<v8::Object> wrapper, T* object) Handle(v8::Local<v8::Object> wrapper, T* object)
: wrapper_(wrapper), object_(object) {} : wrapper_(wrapper), object_(object) {}
@ -34,7 +34,7 @@ class Handle {
private: private:
v8::Local<v8::Object> wrapper_; v8::Local<v8::Object> wrapper_;
T* object_; T* object_ = nullptr;
}; };
template <typename T> template <typename T>

View file

@ -11,7 +11,7 @@ ObjectTemplateBuilder::ObjectTemplateBuilder(
v8::Local<v8::ObjectTemplate> templ) v8::Local<v8::ObjectTemplate> templ)
: isolate_(isolate), template_(templ) {} : isolate_(isolate), template_(templ) {}
ObjectTemplateBuilder::~ObjectTemplateBuilder() {} ObjectTemplateBuilder::~ObjectTemplateBuilder() = default;
ObjectTemplateBuilder& ObjectTemplateBuilder::SetImpl(base::StringPiece name, ObjectTemplateBuilder& ObjectTemplateBuilder::SetImpl(base::StringPiece name,
v8::Local<v8::Data> val) { v8::Local<v8::Data> val) {

View file

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

View file

@ -6,13 +6,13 @@
namespace mate { namespace mate {
Promise::Promise() : isolate_(NULL) {} Promise::Promise() = default;
Promise::Promise(v8::Isolate* isolate) : isolate_(isolate) { Promise::Promise(v8::Isolate* isolate) : isolate_(isolate) {
resolver_ = v8::Promise::Resolver::New(isolate); resolver_ = v8::Promise::Resolver::New(isolate);
} }
Promise::~Promise() {} Promise::~Promise() = default;
Promise Promise::Create(v8::Isolate* isolate) { Promise Promise::Create(v8::Isolate* isolate) {
return Promise(isolate); return Promise(isolate);

View file

@ -37,7 +37,7 @@ class Promise {
void RejectWithErrorMessage(const std::string& error); void RejectWithErrorMessage(const std::string& error);
protected: protected:
v8::Isolate* isolate_; v8::Isolate* isolate_ = nullptr;
private: private:
v8::Local<v8::Promise::Resolver> resolver_; v8::Local<v8::Promise::Resolver> resolver_;

View file

@ -54,7 +54,7 @@ class ScopedPersistent {
v8::Isolate* isolate() const { return isolate_; } v8::Isolate* isolate() const { return isolate_; }
private: private:
v8::Isolate* isolate_; v8::Isolate* isolate_ = nullptr;
v8::Persistent<T> handle_; v8::Persistent<T> handle_;
DISALLOW_COPY_AND_ASSIGN(ScopedPersistent); DISALLOW_COPY_AND_ASSIGN(ScopedPersistent);
@ -64,7 +64,7 @@ template <typename T>
class RefCountedPersistent : public ScopedPersistent<T>, class RefCountedPersistent : public ScopedPersistent<T>,
public base::RefCounted<RefCountedPersistent<T>> { public base::RefCounted<RefCountedPersistent<T>> {
public: public:
RefCountedPersistent() {} RefCountedPersistent() = default;
RefCountedPersistent(v8::Isolate* isolate, v8::Local<v8::Value> handle) RefCountedPersistent(v8::Isolate* isolate, v8::Local<v8::Value> handle)
: ScopedPersistent<T>(isolate, handle) {} : ScopedPersistent<T>(isolate, handle) {}
@ -72,7 +72,7 @@ class RefCountedPersistent : public ScopedPersistent<T>,
protected: protected:
friend class base::RefCounted<RefCountedPersistent<T>>; friend class base::RefCounted<RefCountedPersistent<T>>;
~RefCountedPersistent() {} ~RefCountedPersistent() = default;
private: private:
DISALLOW_COPY_AND_ASSIGN(RefCountedPersistent); DISALLOW_COPY_AND_ASSIGN(RefCountedPersistent);

View file

@ -10,7 +10,7 @@
namespace mate { namespace mate {
WrappableBase::WrappableBase() : isolate_(nullptr) {} WrappableBase::WrappableBase() = default;
WrappableBase::~WrappableBase() { WrappableBase::~WrappableBase() {
if (wrapper_.IsEmpty()) if (wrapper_.IsEmpty())

View file

@ -21,7 +21,7 @@ void* FromV8Impl(v8::Isolate* isolate, v8::Local<v8::Value> val);
template <typename T> template <typename T>
class Wrappable : public WrappableBase { class Wrappable : public WrappableBase {
public: public:
Wrappable() {} Wrappable() = default;
template <typename Sig> template <typename Sig>
static void SetConstructor(v8::Isolate* isolate, static void SetConstructor(v8::Isolate* isolate,

View file

@ -55,7 +55,7 @@ class WrappableBase {
static void SecondWeakCallback( static void SecondWeakCallback(
const v8::WeakCallbackInfo<WrappableBase>& data); const v8::WeakCallbackInfo<WrappableBase>& data);
v8::Isolate* isolate_; v8::Isolate* isolate_ = nullptr;
v8::Global<v8::Object> wrapper_; // Weak v8::Global<v8::Object> wrapper_; // Weak
DISALLOW_COPY_AND_ASSIGN(WrappableBase); DISALLOW_COPY_AND_ASSIGN(WrappableBase);