From d7b8cce162fc9639c4f976304832f391f0d9f38f Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Thu, 17 May 2018 23:36:15 +0200 Subject: [PATCH] Remove native_mate/compat.h --- native_mate/arguments.cc | 10 +- native_mate/arguments.h | 7 +- native_mate/compat.h | 134 ------------------------- native_mate/constructor.h | 10 +- native_mate/converter.cc | 32 +++--- native_mate/converter.h | 7 +- native_mate/object_template_builder.cc | 2 - native_mate/scoped_persistent.h | 8 +- native_mate/wrappable.h | 1 - native_mate/wrappable_base.h | 2 - native_mate_files.gypi | 1 - 11 files changed, 36 insertions(+), 178 deletions(-) delete mode 100644 native_mate/compat.h diff --git a/native_mate/arguments.cc b/native_mate/arguments.cc index 130d77d..a23e652 100644 --- a/native_mate/arguments.cc +++ b/native_mate/arguments.cc @@ -31,7 +31,7 @@ Arguments::Arguments() insufficient_arguments_(false) { } -Arguments::Arguments(const MATE_METHOD_ARGS_TYPE& info) +Arguments::Arguments(const v8::FunctionCallbackInfo& info) : isolate_(info.GetIsolate()), info_(&info), next_(0), @@ -57,16 +57,16 @@ v8::Local Arguments::ThrowError() const { } v8::Local Arguments::ThrowError(const std::string& message) const { - MATE_THROW_EXCEPTION(isolate_, v8::Exception::Error( + isolate_->ThrowException(v8::Exception::Error( StringToV8(isolate_, message))); - return MATE_UNDEFINED(isolate_); + return v8::Undefined(isolate_); } v8::Local Arguments::ThrowTypeError( const std::string& message) const { - MATE_THROW_EXCEPTION(isolate_, v8::Exception::TypeError( + isolate_->ThrowException(v8::Exception::TypeError( StringToV8(isolate_, message))); - return MATE_UNDEFINED(isolate_); + return v8::Undefined(isolate_); } } // namespace mate diff --git a/native_mate/arguments.h b/native_mate/arguments.h index 44250e8..9198f28 100644 --- a/native_mate/arguments.h +++ b/native_mate/arguments.h @@ -6,7 +6,6 @@ #define NATIVE_MATE_ARGUMENTS_H_ #include "base/macros.h" -#include "native_mate/compat.h" #include "native_mate/converter.h" namespace mate { @@ -17,7 +16,7 @@ namespace mate { class Arguments { public: Arguments(); - explicit Arguments(const MATE_METHOD_ARGS_TYPE& info); + explicit Arguments(const v8::FunctionCallbackInfo& info); ~Arguments(); v8::Local GetHolder() const { @@ -75,12 +74,10 @@ class Arguments { return info_->Length(); } -#if NODE_VERSION_AT_LEAST(0, 11, 0) template void Return(T val) { info_->GetReturnValue().Set(ConvertToV8(isolate_, val)); } -#endif v8::Local PeekNext() const; @@ -92,7 +89,7 @@ class Arguments { private: v8::Isolate* isolate_; - const MATE_METHOD_ARGS_TYPE* info_; + const v8::FunctionCallbackInfo* info_; int next_; bool insufficient_arguments_; }; diff --git a/native_mate/compat.h b/native_mate/compat.h deleted file mode 100644 index 5baefb4..0000000 --- a/native_mate/compat.h +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright 2014 Cheng Zhao. All rights reserved. -// Use of this source code is governed by MIT license that can be found in the -// LICENSE file. - -#ifndef NATIVE_MATE_COMPAT_H_ -#define NATIVE_MATE_COMPAT_H_ - -#include "node_version.h" - -#if NODE_VERSION_AT_LEAST(0, 11, 0) - -#define MATE_HANDLE_SCOPE(isolate) v8::HandleScope handle_scope(isolate) - -#define MATE_METHOD_ARGS_TYPE v8::FunctionCallbackInfo -#define MATE_METHOD_RETURN_TYPE void - -#define MATE_METHOD_RETURN_VALUE(value) return info.GetReturnValue().Set(value) -#define MATE_METHOD_RETURN_UNDEFINED() return -#define MATE_METHOD_RETURN_NULL() return info.GetReturnValue().SetNull() -#define MATE_METHOD_RETURN(value) args.Return(value) - -#define MATE_STRING_NEW(isolate, data) \ - v8::String::NewFromUtf8(isolate, data, v8::String::kNormalString) -#define MATE_STRING_NEW_FROM_UTF8(isolate, data, length) \ - v8::String::NewFromUtf8(isolate, data, v8::String::kNormalString, length) -#define MATE_STRING_NEW_FROM_UTF16(isolate, data, length) \ - v8::String::NewFromTwoByte(isolate, data, v8::String::kNormalString, length) -#define MATE_STRING_NEW_SYMBOL(isolate, data, length) \ - v8::String::NewFromUtf8(isolate, data, v8::String::kInternalizedString, length) - -#define MATE_UNDEFINED(isolate) v8::Undefined(isolate) -#define MATE_TRUE(isolate) v8::True(isolate) -#define MATE_FALSE(isolate) v8::False(isolate) -#define MATE_ARRAY_NEW(isolate, size) v8::Array::New(isolate, size) -#define MATE_NUMBER_NEW(isolate, data) v8::Number::New(isolate, data) -#define MATE_INTEGER_NEW(isolate, data) v8::Integer::New(isolate, data) -#define MATE_INTEGER_NEW_UNSIGNED(isolate, data) \ - v8::Integer::NewFromUnsigned(isolate, data) -#define MATE_EXTERNAL_NEW(isolate, data) v8::External::New(isolate, data) -#define MATE_BOOLEAN_NEW(isolate, data) v8::Boolean::New(isolate, data) -#define MATE_OBJECT_NEW(isolate) v8::Object::New(isolate) - -#define MATE_SET_INTERNAL_FIELD_POINTER(object, index, value) \ - object->SetAlignedPointerInInternalField(index, value) -#define MATE_GET_INTERNAL_FIELD_POINTER(object, index) \ - object->GetAlignedPointerFromInternalField(index) - -#define MATE_PERSISTENT_INIT(isolate, handle, value) \ - handle(isolate, value) -#define MATE_PERSISTENT_ASSIGN(type, isolate, handle, value) \ - handle.Reset(isolate, value) -#define MATE_PERSISTENT_RESET(handle) \ - handle.Reset() -#define MATE_PERSISTENT_TO_LOCAL(type, isolate, handle) \ - v8::Local::New(isolate, handle) -#define MATE_PERSISTENT_SET_WEAK(handle, parameter, callback) \ - handle.SetWeak(parameter, callback) - -#define MATE_WEAK_CALLBACK(name, v8_type, c_type) \ - void name(const v8::WeakCallbackData& data) -#define MATE_WEAK_CALLBACK_INIT(c_type) \ - c_type* self = data.GetParameter() - -#define MATE_THROW_EXCEPTION(isolate, value) \ - isolate->ThrowException(value) - -#else // Node 0.8 and 0.10 - -#define MATE_HANDLE_SCOPE(isolate) v8::HandleScope handle_scope - -#define MATE_METHOD_ARGS_TYPE v8::Arguments -#define MATE_METHOD_RETURN_TYPE v8::Local - -#define MATE_METHOD_RETURN_VALUE(value) return value -#define MATE_METHOD_RETURN_UNDEFINED() return v8::Undefined() -#define MATE_METHOD_RETURN_NULL() return v8::Null() -#define MATE_METHOD_RETURN(value) \ - MATE_METHOD_RETURN_VALUE(ConvertToV8(args.isolate(), value)) - -#define MATE_STRING_NEW(isolate, data) \ - v8::String::New(data) -#define MATE_STRING_NEW_FROM_UTF8(isolate, data, length) \ - v8::String::New(data, length) -#define MATE_STRING_NEW_FROM_UTF16(isolate, data, length) \ - v8::String::NewFromTwoByte(data, v8::String::kNormalString, length) -#define MATE_STRING_NEW_SYMBOL(isolate, data, length) \ - v8::String::NewSymbol(data, length) - -#define MATE_UNDEFINED(isolate) v8::Undefined() -#define MATE_TRUE(isolate) v8::True() -#define MATE_FALSE(isolate) v8::False() -#define MATE_ARRAY_NEW(isolate, size) v8::Array::New(size) -#define MATE_NUMBER_NEW(isolate, data) v8::Number::New(data) -#define MATE_INTEGER_NEW(isolate, data) v8::Integer::New(data) -#define MATE_INTEGER_NEW_UNSIGNED(isolate, data) \ - v8::Integer::NewFromUnsigned(data) -#define MATE_EXTERNAL_NEW(isolate, data) v8::External::New(data) -#define MATE_BOOLEAN_NEW(isolate, data) v8::Boolean::New(data) -#define MATE_OBJECT_NEW(isolate) v8::Object::New() - -#define MATE_SET_INTERNAL_FIELD_POINTER(object, index, value) \ - object->SetPointerInInternalField(index, value) -#define MATE_GET_INTERNAL_FIELD_POINTER(object, index) \ - object->GetPointerFromInternalField(index) - -#define MATE_PERSISTENT_INIT(isolate, handle, value) \ - handle(value) -#define MATE_PERSISTENT_ASSIGN(type, isolate, handle, value) \ - handle = v8::Persistent::New(value) -#define MATE_PERSISTENT_RESET(handle) \ - handle.Dispose(); \ - handle.Clear() -#define MATE_PERSISTENT_TO_LOCAL(type, isolate, handle) \ - v8::Local::New(handle) -#define MATE_PERSISTENT_SET_WEAK(handle, parameter, callback) \ - handle.MakeWeak(parameter, callback) - -#define MATE_WEAK_CALLBACK(name, v8_type, c_type) \ - void name(v8::Persistent object, void* parameter) -#define MATE_WEAK_CALLBACK_INIT(c_type) \ - c_type* self = static_cast(parameter) - -#define MATE_THROW_EXCEPTION(isolate, value) \ - v8::ThrowException(value) - -#endif // (NODE_MODULE_VERSION > 0x000B) - - -// Generally we should not provide utility macros, but this just makes things -// much more comfortable so we keep it. -#define MATE_METHOD(name) \ - MATE_METHOD_RETURN_TYPE name(const MATE_METHOD_ARGS_TYPE& info) - -#endif // NATIVE_MATE_COMPAT_H_ diff --git a/native_mate/constructor.h b/native_mate/constructor.h index c6deead..6a91ebe 100644 --- a/native_mate/constructor.h +++ b/native_mate/constructor.h @@ -117,11 +117,11 @@ inline WrappableBase* InvokeFactory( }; template -MATE_METHOD_RETURN_TYPE InvokeNew(const base::Callback& factory, - v8::Isolate* isolate, Arguments* args) { +void InvokeNew(const base::Callback& factory, + v8::Isolate* isolate, Arguments* args) { if (!args->IsConstructCall()) { args->ThrowError("Requires constructor call"); - MATE_METHOD_RETURN_UNDEFINED(); + return; } WrappableBase* object; @@ -131,14 +131,14 @@ MATE_METHOD_RETURN_TYPE InvokeNew(const base::Callback& factory, object = internal::InvokeFactory(args, factory); if (try_catch.HasCaught()) { try_catch.ReThrow(); - MATE_METHOD_RETURN_UNDEFINED(); + return; } } if (!object) args->ThrowError(); - MATE_METHOD_RETURN_UNDEFINED(); + return; } } // namespace internal diff --git a/native_mate/converter.cc b/native_mate/converter.cc index 9edf940..260bdf1 100644 --- a/native_mate/converter.cc +++ b/native_mate/converter.cc @@ -4,7 +4,6 @@ #include "native_mate/converter.h" -#include "native_mate/compat.h" #include "v8/include/v8.h" using v8::Array; @@ -22,7 +21,7 @@ using v8::Value; namespace mate { Local Converter::ToV8(Isolate* isolate, bool val) { - return MATE_BOOLEAN_NEW(isolate, val); + return v8::Boolean::New(isolate, val); } bool Converter::FromV8(Isolate* isolate, Local val, bool* out) { @@ -35,7 +34,7 @@ bool Converter::FromV8(Isolate* isolate, Local val, bool* out) { #if !defined(OS_LINUX) && !defined(OS_FREEBSD) Local Converter::ToV8(Isolate* isolate, unsigned long val) { - return MATE_INTEGER_NEW(isolate, val); + return v8::Integer::New(isolate, val); } bool Converter::FromV8(Isolate* isolate, Local val, @@ -48,7 +47,7 @@ bool Converter::FromV8(Isolate* isolate, Local val, #endif Local Converter::ToV8(Isolate* isolate, int32_t val) { - return MATE_INTEGER_NEW(isolate, val); + return v8::Integer::New(isolate, val); } bool Converter::FromV8(Isolate* isolate, Local val, @@ -60,7 +59,7 @@ bool Converter::FromV8(Isolate* isolate, Local val, } Local Converter::ToV8(Isolate* isolate, uint32_t val) { - return MATE_INTEGER_NEW_UNSIGNED(isolate, val); + return v8::Integer::NewFromUnsigned(isolate, val); } bool Converter::FromV8(Isolate* isolate, Local val, @@ -72,7 +71,7 @@ bool Converter::FromV8(Isolate* isolate, Local val, } Local Converter::ToV8(Isolate* isolate, int64_t val) { - return MATE_NUMBER_NEW(isolate, static_cast(val)); + return v8::Number::New(isolate, static_cast(val)); } bool Converter::FromV8(Isolate* isolate, Local val, @@ -86,7 +85,7 @@ bool Converter::FromV8(Isolate* isolate, Local val, } Local Converter::ToV8(Isolate* isolate, uint64_t val) { - return MATE_NUMBER_NEW(isolate, static_cast(val)); + return v8::Number::New(isolate, static_cast(val)); } bool Converter::FromV8(Isolate* isolate, Local val, @@ -98,7 +97,7 @@ bool Converter::FromV8(Isolate* isolate, Local val, } Local Converter::ToV8(Isolate* isolate, float val) { - return MATE_NUMBER_NEW(isolate, val); + return v8::Number::New(isolate, val); } bool Converter::FromV8(Isolate* isolate, Local val, @@ -110,7 +109,7 @@ bool Converter::FromV8(Isolate* isolate, Local val, } Local Converter::ToV8(Isolate* isolate, double val) { - return MATE_NUMBER_NEW(isolate, val); + return v8::Number::New(isolate, val); } bool Converter::FromV8(Isolate* isolate, Local val, @@ -123,13 +122,15 @@ bool Converter::FromV8(Isolate* isolate, Local val, Local Converter::ToV8( Isolate* isolate, const char* val) { - return MATE_STRING_NEW_FROM_UTF8(isolate, val, -1); + return v8::String::NewFromUtf8(isolate, val); } Local Converter::ToV8( Isolate* isolate, const base::StringPiece& val) { - return MATE_STRING_NEW_FROM_UTF8(isolate, val.data(), - static_cast(val.length())); + return v8::String::NewFromUtf8(isolate, + val.data(), + v8::String::kNormalString, + static_cast(val.length())); } Local Converter::ToV8(Isolate* isolate, @@ -228,9 +229,10 @@ bool Converter >::FromV8(Isolate* isolate, Local val, v8::Local StringToSymbol(v8::Isolate* isolate, const base::StringPiece& val) { - return MATE_STRING_NEW_SYMBOL(isolate, - val.data(), - static_cast(val.length())); + return v8::String::NewFromUtf8(isolate, + val.data(), + v8::String::kInternalizedString, + static_cast(val.length())); } std::string V8ToString(v8::Local value) { diff --git a/native_mate/converter.h b/native_mate/converter.h index 53e682a..ec3649c 100644 --- a/native_mate/converter.h +++ b/native_mate/converter.h @@ -11,7 +11,6 @@ #include #include "base/strings/string_piece.h" -#include "native_mate/compat.h" #include "v8/include/v8.h" namespace mate { @@ -36,7 +35,7 @@ struct Converter {}; template<> struct Converter { static v8::Local ToV8(v8::Isolate* isolate, void* val) { - return MATE_UNDEFINED(isolate); + return v8::Undefined(isolate); } }; @@ -208,7 +207,7 @@ struct Converter > { static v8::Local ToV8(v8::Isolate* isolate, const std::vector& val) { v8::Local result( - MATE_ARRAY_NEW(isolate, static_cast(val.size()))); + v8::Array::New(isolate, static_cast(val.size()))); for (size_t i = 0; i < val.size(); ++i) { result->Set(static_cast(i), Converter::ToV8(isolate, val[i])); } @@ -241,7 +240,7 @@ struct Converter > { static v8::Local ToV8(v8::Isolate* isolate, const std::set& val) { v8::Local result( - MATE_ARRAY_NEW(isolate, static_cast(val.size()))); + v8::Array::New(isolate, static_cast(val.size()))); typename std::set::const_iterator it; int i; for (i = 0, it = val.begin(); it != val.end(); ++it, ++i) diff --git a/native_mate/object_template_builder.cc b/native_mate/object_template_builder.cc index ab4079e..c64e38f 100644 --- a/native_mate/object_template_builder.cc +++ b/native_mate/object_template_builder.cc @@ -24,10 +24,8 @@ ObjectTemplateBuilder& ObjectTemplateBuilder::SetImpl( ObjectTemplateBuilder& ObjectTemplateBuilder::SetPropertyImpl( const base::StringPiece& name, v8::Local getter, v8::Local setter) { -#if NODE_VERSION_AT_LEAST(0, 11, 0) template_->SetAccessorProperty(StringToSymbol(isolate_, name), getter, setter); -#endif return *this; } diff --git a/native_mate/scoped_persistent.h b/native_mate/scoped_persistent.h index c7c5355..5d9c8ff 100644 --- a/native_mate/scoped_persistent.h +++ b/native_mate/scoped_persistent.h @@ -30,14 +30,14 @@ class ScopedPersistent { void reset(v8::Isolate* isolate, v8::Local handle) { if (!handle.IsEmpty()) { isolate_ = isolate; - MATE_PERSISTENT_ASSIGN(T, isolate, handle_, handle); + handle_.Reset(isolate, handle); } else { reset(); } } void reset() { - MATE_PERSISTENT_RESET(handle_); + handle_.Reset(); } bool IsEmpty() const { @@ -51,12 +51,12 @@ class ScopedPersistent { v8::Local NewHandle(v8::Isolate* isolate) const { if (handle_.IsEmpty()) return v8::Local(); - return MATE_PERSISTENT_TO_LOCAL(T, isolate, handle_); + return v8::Local::New(isolate, handle_); } template void SetWeak(P* parameter, C callback) { - MATE_PERSISTENT_SET_WEAK(handle_, parameter, callback); + handle_.SetWeak(parameter, callback); } v8::Isolate* isolate() const { return isolate_; } diff --git a/native_mate/wrappable.h b/native_mate/wrappable.h index 8c1b480..489c581 100644 --- a/native_mate/wrappable.h +++ b/native_mate/wrappable.h @@ -6,7 +6,6 @@ #define NATIVE_MATE_WRAPPABLE_H_ #include "base/bind.h" -#include "native_mate/compat.h" #include "native_mate/converter.h" #include "native_mate/constructor.h" #include "gin/per_isolate_data.h" diff --git a/native_mate/wrappable_base.h b/native_mate/wrappable_base.h index 501bbee..1c489cc 100644 --- a/native_mate/wrappable_base.h +++ b/native_mate/wrappable_base.h @@ -1,8 +1,6 @@ #ifndef NATIVE_MATE_WRAPPABLE_BASE_H_ #define NATIVE_MATE_WRAPPABLE_BASE_H_ -#include "native_mate/compat.h" - namespace mate { namespace internal { diff --git a/native_mate_files.gypi b/native_mate_files.gypi index b67f0c7..d7e9374 100644 --- a/native_mate_files.gypi +++ b/native_mate_files.gypi @@ -3,7 +3,6 @@ 'native_mate_files': [ 'native_mate/arguments.cc', 'native_mate/arguments.h', - 'native_mate/compat.h', 'native_mate/constructor.h', 'native_mate/converter.cc', 'native_mate/converter.h',