Remove native_mate/compat.h
This commit is contained in:
Родитель
4cd7d11391
Коммит
d7b8cce162
|
@ -31,7 +31,7 @@ Arguments::Arguments()
|
|||
insufficient_arguments_(false) {
|
||||
}
|
||||
|
||||
Arguments::Arguments(const MATE_METHOD_ARGS_TYPE& info)
|
||||
Arguments::Arguments(const v8::FunctionCallbackInfo<v8::Value>& info)
|
||||
: isolate_(info.GetIsolate()),
|
||||
info_(&info),
|
||||
next_(0),
|
||||
|
@ -57,16 +57,16 @@ v8::Local<v8::Value> Arguments::ThrowError() const {
|
|||
}
|
||||
|
||||
v8::Local<v8::Value> 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<v8::Value> 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
|
||||
|
|
|
@ -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<v8::Value>& info);
|
||||
~Arguments();
|
||||
|
||||
v8::Local<v8::Object> GetHolder() const {
|
||||
|
@ -75,12 +74,10 @@ class Arguments {
|
|||
return info_->Length();
|
||||
}
|
||||
|
||||
#if NODE_VERSION_AT_LEAST(0, 11, 0)
|
||||
template<typename T>
|
||||
void Return(T val) {
|
||||
info_->GetReturnValue().Set(ConvertToV8(isolate_, val));
|
||||
}
|
||||
#endif
|
||||
|
||||
v8::Local<v8::Value> PeekNext() const;
|
||||
|
||||
|
@ -92,7 +89,7 @@ class Arguments {
|
|||
|
||||
private:
|
||||
v8::Isolate* isolate_;
|
||||
const MATE_METHOD_ARGS_TYPE* info_;
|
||||
const v8::FunctionCallbackInfo<v8::Value>* info_;
|
||||
int next_;
|
||||
bool insufficient_arguments_;
|
||||
};
|
||||
|
|
|
@ -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<v8::Value>
|
||||
#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<type>::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<v8_type, c_type>& 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<v8::Value>
|
||||
|
||||
#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<type>::New(value)
|
||||
#define MATE_PERSISTENT_RESET(handle) \
|
||||
handle.Dispose(); \
|
||||
handle.Clear()
|
||||
#define MATE_PERSISTENT_TO_LOCAL(type, isolate, handle) \
|
||||
v8::Local<type>::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<v8::Value> object, void* parameter)
|
||||
#define MATE_WEAK_CALLBACK_INIT(c_type) \
|
||||
c_type* self = static_cast<c_type*>(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_
|
|
@ -117,11 +117,11 @@ inline WrappableBase* InvokeFactory(
|
|||
};
|
||||
|
||||
template<typename Sig>
|
||||
MATE_METHOD_RETURN_TYPE InvokeNew(const base::Callback<Sig>& factory,
|
||||
v8::Isolate* isolate, Arguments* args) {
|
||||
void InvokeNew(const base::Callback<Sig>& 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<Sig>& 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
|
||||
|
|
|
@ -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<Value> Converter<bool>::ToV8(Isolate* isolate, bool val) {
|
||||
return MATE_BOOLEAN_NEW(isolate, val);
|
||||
return v8::Boolean::New(isolate, val);
|
||||
}
|
||||
|
||||
bool Converter<bool>::FromV8(Isolate* isolate, Local<Value> val, bool* out) {
|
||||
|
@ -35,7 +34,7 @@ bool Converter<bool>::FromV8(Isolate* isolate, Local<Value> val, bool* out) {
|
|||
#if !defined(OS_LINUX) && !defined(OS_FREEBSD)
|
||||
Local<Value> Converter<unsigned long>::ToV8(Isolate* isolate,
|
||||
unsigned long val) {
|
||||
return MATE_INTEGER_NEW(isolate, val);
|
||||
return v8::Integer::New(isolate, val);
|
||||
}
|
||||
|
||||
bool Converter<unsigned long>::FromV8(Isolate* isolate, Local<Value> val,
|
||||
|
@ -48,7 +47,7 @@ bool Converter<unsigned long>::FromV8(Isolate* isolate, Local<Value> val,
|
|||
#endif
|
||||
|
||||
Local<Value> Converter<int32_t>::ToV8(Isolate* isolate, int32_t val) {
|
||||
return MATE_INTEGER_NEW(isolate, val);
|
||||
return v8::Integer::New(isolate, val);
|
||||
}
|
||||
|
||||
bool Converter<int32_t>::FromV8(Isolate* isolate, Local<Value> val,
|
||||
|
@ -60,7 +59,7 @@ bool Converter<int32_t>::FromV8(Isolate* isolate, Local<Value> val,
|
|||
}
|
||||
|
||||
Local<Value> Converter<uint32_t>::ToV8(Isolate* isolate, uint32_t val) {
|
||||
return MATE_INTEGER_NEW_UNSIGNED(isolate, val);
|
||||
return v8::Integer::NewFromUnsigned(isolate, val);
|
||||
}
|
||||
|
||||
bool Converter<uint32_t>::FromV8(Isolate* isolate, Local<Value> val,
|
||||
|
@ -72,7 +71,7 @@ bool Converter<uint32_t>::FromV8(Isolate* isolate, Local<Value> val,
|
|||
}
|
||||
|
||||
Local<Value> Converter<int64_t>::ToV8(Isolate* isolate, int64_t val) {
|
||||
return MATE_NUMBER_NEW(isolate, static_cast<double>(val));
|
||||
return v8::Number::New(isolate, static_cast<double>(val));
|
||||
}
|
||||
|
||||
bool Converter<int64_t>::FromV8(Isolate* isolate, Local<Value> val,
|
||||
|
@ -86,7 +85,7 @@ bool Converter<int64_t>::FromV8(Isolate* isolate, Local<Value> val,
|
|||
}
|
||||
|
||||
Local<Value> Converter<uint64_t>::ToV8(Isolate* isolate, uint64_t val) {
|
||||
return MATE_NUMBER_NEW(isolate, static_cast<double>(val));
|
||||
return v8::Number::New(isolate, static_cast<double>(val));
|
||||
}
|
||||
|
||||
bool Converter<uint64_t>::FromV8(Isolate* isolate, Local<Value> val,
|
||||
|
@ -98,7 +97,7 @@ bool Converter<uint64_t>::FromV8(Isolate* isolate, Local<Value> val,
|
|||
}
|
||||
|
||||
Local<Value> Converter<float>::ToV8(Isolate* isolate, float val) {
|
||||
return MATE_NUMBER_NEW(isolate, val);
|
||||
return v8::Number::New(isolate, val);
|
||||
}
|
||||
|
||||
bool Converter<float>::FromV8(Isolate* isolate, Local<Value> val,
|
||||
|
@ -110,7 +109,7 @@ bool Converter<float>::FromV8(Isolate* isolate, Local<Value> val,
|
|||
}
|
||||
|
||||
Local<Value> Converter<double>::ToV8(Isolate* isolate, double val) {
|
||||
return MATE_NUMBER_NEW(isolate, val);
|
||||
return v8::Number::New(isolate, val);
|
||||
}
|
||||
|
||||
bool Converter<double>::FromV8(Isolate* isolate, Local<Value> val,
|
||||
|
@ -123,13 +122,15 @@ bool Converter<double>::FromV8(Isolate* isolate, Local<Value> val,
|
|||
|
||||
Local<Value> Converter<const char*>::ToV8(
|
||||
Isolate* isolate, const char* val) {
|
||||
return MATE_STRING_NEW_FROM_UTF8(isolate, val, -1);
|
||||
return v8::String::NewFromUtf8(isolate, val);
|
||||
}
|
||||
|
||||
Local<Value> Converter<base::StringPiece>::ToV8(
|
||||
Isolate* isolate, const base::StringPiece& val) {
|
||||
return MATE_STRING_NEW_FROM_UTF8(isolate, val.data(),
|
||||
static_cast<uint32_t>(val.length()));
|
||||
return v8::String::NewFromUtf8(isolate,
|
||||
val.data(),
|
||||
v8::String::kNormalString,
|
||||
static_cast<uint32_t>(val.length()));
|
||||
}
|
||||
|
||||
Local<Value> Converter<std::string>::ToV8(Isolate* isolate,
|
||||
|
@ -228,9 +229,10 @@ bool Converter<Local<Value> >::FromV8(Isolate* isolate, Local<Value> val,
|
|||
|
||||
v8::Local<v8::String> StringToSymbol(v8::Isolate* isolate,
|
||||
const base::StringPiece& val) {
|
||||
return MATE_STRING_NEW_SYMBOL(isolate,
|
||||
val.data(),
|
||||
static_cast<uint32_t>(val.length()));
|
||||
return v8::String::NewFromUtf8(isolate,
|
||||
val.data(),
|
||||
v8::String::kInternalizedString,
|
||||
static_cast<uint32_t>(val.length()));
|
||||
}
|
||||
|
||||
std::string V8ToString(v8::Local<v8::Value> value) {
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include <set>
|
||||
|
||||
#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<void*> {
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, void* val) {
|
||||
return MATE_UNDEFINED(isolate);
|
||||
return v8::Undefined(isolate);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -208,7 +207,7 @@ struct Converter<std::vector<T> > {
|
|||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
const std::vector<T>& val) {
|
||||
v8::Local<v8::Array> result(
|
||||
MATE_ARRAY_NEW(isolate, static_cast<int>(val.size())));
|
||||
v8::Array::New(isolate, static_cast<int>(val.size())));
|
||||
for (size_t i = 0; i < val.size(); ++i) {
|
||||
result->Set(static_cast<int>(i), Converter<T>::ToV8(isolate, val[i]));
|
||||
}
|
||||
|
@ -241,7 +240,7 @@ struct Converter<std::set<T> > {
|
|||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
const std::set<T>& val) {
|
||||
v8::Local<v8::Array> result(
|
||||
MATE_ARRAY_NEW(isolate, static_cast<int>(val.size())));
|
||||
v8::Array::New(isolate, static_cast<int>(val.size())));
|
||||
typename std::set<T>::const_iterator it;
|
||||
int i;
|
||||
for (i = 0, it = val.begin(); it != val.end(); ++it, ++i)
|
||||
|
|
|
@ -24,10 +24,8 @@ ObjectTemplateBuilder& ObjectTemplateBuilder::SetImpl(
|
|||
ObjectTemplateBuilder& ObjectTemplateBuilder::SetPropertyImpl(
|
||||
const base::StringPiece& name, v8::Local<v8::FunctionTemplate> getter,
|
||||
v8::Local<v8::FunctionTemplate> setter) {
|
||||
#if NODE_VERSION_AT_LEAST(0, 11, 0)
|
||||
template_->SetAccessorProperty(StringToSymbol(isolate_, name), getter,
|
||||
setter);
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,14 +30,14 @@ class ScopedPersistent {
|
|||
void reset(v8::Isolate* isolate, v8::Local<T> 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<T> NewHandle(v8::Isolate* isolate) const {
|
||||
if (handle_.IsEmpty())
|
||||
return v8::Local<T>();
|
||||
return MATE_PERSISTENT_TO_LOCAL(T, isolate, handle_);
|
||||
return v8::Local<T>::New(isolate, handle_);
|
||||
}
|
||||
|
||||
template<typename P, typename C>
|
||||
void SetWeak(P* parameter, C callback) {
|
||||
MATE_PERSISTENT_SET_WEAK(handle_, parameter, callback);
|
||||
handle_.SetWeak(parameter, callback);
|
||||
}
|
||||
|
||||
v8::Isolate* isolate() const { return isolate_; }
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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',
|
||||
|
|
Загрузка…
Ссылка в новой задаче