Use Local instead of Handle

This commit is contained in:
Cheng Zhao 2015-05-22 19:11:02 +08:00
parent 047a8de934
commit 269be86998
23 changed files with 238 additions and 238 deletions

View file

@ -26,13 +26,13 @@ Arguments::Arguments(const MATE_METHOD_ARGS_TYPE& info)
Arguments::~Arguments() { Arguments::~Arguments() {
} }
v8::Handle<v8::Value> Arguments::PeekNext() const { v8::Local<v8::Value> Arguments::PeekNext() const {
if (next_ >= info_->Length()) if (next_ >= info_->Length())
return v8::Handle<v8::Value>(); return v8::Local<v8::Value>();
return (*info_)[next_]; return (*info_)[next_];
} }
v8::Handle<v8::Value> Arguments::ThrowError() const { v8::Local<v8::Value> Arguments::ThrowError() const {
if (insufficient_arguments_) if (insufficient_arguments_)
return ThrowTypeError("Insufficient number of arguments."); return ThrowTypeError("Insufficient number of arguments.");
@ -40,13 +40,13 @@ v8::Handle<v8::Value> Arguments::ThrowError() const {
"Error processing argument %d.", next_ - 1)); "Error processing argument %d.", next_ - 1));
} }
v8::Handle<v8::Value> Arguments::ThrowError(const std::string& message) const { v8::Local<v8::Value> Arguments::ThrowError(const std::string& message) const {
MATE_THROW_EXCEPTION(isolate_, v8::Exception::Error( MATE_THROW_EXCEPTION(isolate_, v8::Exception::Error(
StringToV8(isolate_, message))); StringToV8(isolate_, message)));
return MATE_UNDEFINED(isolate_); return MATE_UNDEFINED(isolate_);
} }
v8::Handle<v8::Value> Arguments::ThrowTypeError( v8::Local<v8::Value> Arguments::ThrowTypeError(
const std::string& message) const { const std::string& message) const {
MATE_THROW_EXCEPTION(isolate_, v8::Exception::TypeError( MATE_THROW_EXCEPTION(isolate_, v8::Exception::TypeError(
StringToV8(isolate_, message))); StringToV8(isolate_, message)));

View file

@ -36,7 +36,7 @@ class Arguments {
insufficient_arguments_ = true; insufficient_arguments_ = true;
return false; return false;
} }
v8::Handle<v8::Value> val = (*info_)[next_++]; v8::Local<v8::Value> val = (*info_)[next_++];
return ConvertFromV8(isolate_, val, out); return ConvertFromV8(isolate_, val, out);
} }
@ -49,14 +49,14 @@ class Arguments {
int remaining = info_->Length() - next_; int remaining = info_->Length() - next_;
out->resize(remaining); out->resize(remaining);
for (int i = 0; i < remaining; ++i) { for (int i = 0; i < remaining; ++i) {
v8::Handle<v8::Value> val = (*info_)[next_++]; v8::Local<v8::Value> val = (*info_)[next_++];
if (!ConvertFromV8(isolate_, val, &out->at(i))) if (!ConvertFromV8(isolate_, val, &out->at(i)))
return false; return false;
} }
return true; return true;
} }
v8::Handle<v8::Object> GetThis() { v8::Local<v8::Object> GetThis() {
return info_->This(); return info_->This();
} }
@ -75,11 +75,11 @@ class Arguments {
} }
#endif #endif
v8::Handle<v8::Value> PeekNext() const; v8::Local<v8::Value> PeekNext() const;
v8::Handle<v8::Value> ThrowError() const; v8::Local<v8::Value> ThrowError() const;
v8::Handle<v8::Value> ThrowError(const std::string& message) const; v8::Local<v8::Value> ThrowError(const std::string& message) const;
v8::Handle<v8::Value> ThrowTypeError(const std::string& message) const; v8::Local<v8::Value> ThrowTypeError(const std::string& message) const;
v8::Isolate* isolate() const { return isolate_; } v8::Isolate* isolate() const { return isolate_; }

View file

@ -28,8 +28,8 @@ struct V8FunctionInvoker<R()> {
R ret; R ret;
Locker locker(isolate); Locker locker(isolate);
MATE_HANDLE_SCOPE(isolate); MATE_HANDLE_SCOPE(isolate);
v8::Handle<v8::Function> holder = function->NewHandle(); v8::Local<v8::Function> holder = function->NewHandle();
v8::Handle<v8::Value> val(holder->Call(holder, 0, NULL)); v8::Local<v8::Value> val(holder->Call(holder, 0, NULL));
Converter<R>::FromV8(isolate, val, &ret); Converter<R>::FromV8(isolate, val, &ret);
return ret; return ret;
} }
@ -40,7 +40,7 @@ struct V8FunctionInvoker<void()> {
static void Go(v8::Isolate* isolate, SafeV8Function function) { static void Go(v8::Isolate* isolate, SafeV8Function function) {
Locker locker(isolate); Locker locker(isolate);
MATE_HANDLE_SCOPE(isolate); MATE_HANDLE_SCOPE(isolate);
v8::Handle<v8::Function> holder = function->NewHandle(); v8::Local<v8::Function> holder = function->NewHandle();
holder->Call(holder, 0, NULL); holder->Call(holder, 0, NULL);
} }
}; };
@ -51,11 +51,11 @@ struct V8FunctionInvoker<R(P1)> {
R ret; R ret;
Locker locker(isolate); Locker locker(isolate);
MATE_HANDLE_SCOPE(isolate); MATE_HANDLE_SCOPE(isolate);
v8::Handle<v8::Function> holder = function->NewHandle(); v8::Local<v8::Function> holder = function->NewHandle();
v8::Handle<v8::Value> args[] = { v8::Local<v8::Value> args[] = {
ConvertToV8(isolate, a1), ConvertToV8(isolate, a1),
}; };
v8::Handle<v8::Value> val(holder->Call(holder, arraysize(args), args)); v8::Local<v8::Value> val(holder->Call(holder, arraysize(args), args));
Converter<R>::FromV8(isolate, val, &ret); Converter<R>::FromV8(isolate, val, &ret);
return ret; return ret;
} }
@ -66,8 +66,8 @@ struct V8FunctionInvoker<void(P1)> {
static void Go(v8::Isolate* isolate, SafeV8Function function, P1 a1) { static void Go(v8::Isolate* isolate, SafeV8Function function, P1 a1) {
Locker locker(isolate); Locker locker(isolate);
MATE_HANDLE_SCOPE(isolate); MATE_HANDLE_SCOPE(isolate);
v8::Handle<v8::Function> holder = function->NewHandle(); v8::Local<v8::Function> holder = function->NewHandle();
v8::Handle<v8::Value> args[] = { v8::Local<v8::Value> args[] = {
ConvertToV8(isolate, a1), ConvertToV8(isolate, a1),
}; };
holder->Call(holder, arraysize(args), args); holder->Call(holder, arraysize(args), args);
@ -80,12 +80,12 @@ struct V8FunctionInvoker<R(P1, P2)> {
R ret; R ret;
Locker locker(isolate); Locker locker(isolate);
MATE_HANDLE_SCOPE(isolate); MATE_HANDLE_SCOPE(isolate);
v8::Handle<v8::Function> holder = function->NewHandle(); v8::Local<v8::Function> holder = function->NewHandle();
v8::Handle<v8::Value> args[] = { v8::Local<v8::Value> args[] = {
ConvertToV8(isolate, a1), ConvertToV8(isolate, a1),
ConvertToV8(isolate, a2), ConvertToV8(isolate, a2),
}; };
v8::Handle<v8::Value> val(holder->Call(holder, arraysize(args), args)); v8::Local<v8::Value> val(holder->Call(holder, arraysize(args), args));
Converter<R>::FromV8(isolate, val, &ret); Converter<R>::FromV8(isolate, val, &ret);
return ret; return ret;
} }
@ -96,8 +96,8 @@ struct V8FunctionInvoker<void(P1, P2)> {
static void Go(v8::Isolate* isolate, SafeV8Function function, P1 a1, P2 a2) { static void Go(v8::Isolate* isolate, SafeV8Function function, P1 a1, P2 a2) {
Locker locker(isolate); Locker locker(isolate);
MATE_HANDLE_SCOPE(isolate); MATE_HANDLE_SCOPE(isolate);
v8::Handle<v8::Function> holder = function->NewHandle(); v8::Local<v8::Function> holder = function->NewHandle();
v8::Handle<v8::Value> args[] = { v8::Local<v8::Value> args[] = {
ConvertToV8(isolate, a1), ConvertToV8(isolate, a1),
ConvertToV8(isolate, a2), ConvertToV8(isolate, a2),
}; };
@ -112,13 +112,13 @@ struct V8FunctionInvoker<R(P1, P2, P3)> {
R ret; R ret;
Locker locker(isolate); Locker locker(isolate);
MATE_HANDLE_SCOPE(isolate); MATE_HANDLE_SCOPE(isolate);
v8::Handle<v8::Function> holder = function->NewHandle(); v8::Local<v8::Function> holder = function->NewHandle();
v8::Handle<v8::Value> args[] = { v8::Local<v8::Value> args[] = {
ConvertToV8(isolate, a1), ConvertToV8(isolate, a1),
ConvertToV8(isolate, a2), ConvertToV8(isolate, a2),
ConvertToV8(isolate, a3), ConvertToV8(isolate, a3),
}; };
v8::Handle<v8::Value> val(holder->Call(holder, arraysize(args), args)); v8::Local<v8::Value> val(holder->Call(holder, arraysize(args), args));
Converter<R>::FromV8(isolate, val, &ret); Converter<R>::FromV8(isolate, val, &ret);
return ret; return ret;
} }
@ -130,8 +130,8 @@ struct V8FunctionInvoker<void(P1, P2, P3)> {
P3 a3) { P3 a3) {
Locker locker(isolate); Locker locker(isolate);
MATE_HANDLE_SCOPE(isolate); MATE_HANDLE_SCOPE(isolate);
v8::Handle<v8::Function> holder = function->NewHandle(); v8::Local<v8::Function> holder = function->NewHandle();
v8::Handle<v8::Value> args[] = { v8::Local<v8::Value> args[] = {
ConvertToV8(isolate, a1), ConvertToV8(isolate, a1),
ConvertToV8(isolate, a2), ConvertToV8(isolate, a2),
ConvertToV8(isolate, a3), ConvertToV8(isolate, a3),
@ -147,14 +147,14 @@ struct V8FunctionInvoker<R(P1, P2, P3, P4)> {
R ret; R ret;
Locker locker(isolate); Locker locker(isolate);
MATE_HANDLE_SCOPE(isolate); MATE_HANDLE_SCOPE(isolate);
v8::Handle<v8::Function> holder = function->NewHandle(); v8::Local<v8::Function> holder = function->NewHandle();
v8::Handle<v8::Value> args[] = { v8::Local<v8::Value> args[] = {
ConvertToV8(isolate, a1), ConvertToV8(isolate, a1),
ConvertToV8(isolate, a2), ConvertToV8(isolate, a2),
ConvertToV8(isolate, a3), ConvertToV8(isolate, a3),
ConvertToV8(isolate, a4), ConvertToV8(isolate, a4),
}; };
v8::Handle<v8::Value> val(holder->Call(holder, arraysize(args), args)); v8::Local<v8::Value> val(holder->Call(holder, arraysize(args), args));
Converter<R>::FromV8(isolate, val, &ret); Converter<R>::FromV8(isolate, val, &ret);
return ret; return ret;
} }
@ -166,8 +166,8 @@ struct V8FunctionInvoker<void(P1, P2, P3, P4)> {
P3 a3, P4 a4) { P3 a3, P4 a4) {
Locker locker(isolate); Locker locker(isolate);
MATE_HANDLE_SCOPE(isolate); MATE_HANDLE_SCOPE(isolate);
v8::Handle<v8::Function> holder = function->NewHandle(); v8::Local<v8::Function> holder = function->NewHandle();
v8::Handle<v8::Value> args[] = { v8::Local<v8::Value> args[] = {
ConvertToV8(isolate, a1), ConvertToV8(isolate, a1),
ConvertToV8(isolate, a2), ConvertToV8(isolate, a2),
ConvertToV8(isolate, a3), ConvertToV8(isolate, a3),
@ -185,15 +185,15 @@ struct V8FunctionInvoker<R(P1, P2, P3, P4, P5)> {
R ret; R ret;
Locker locker(isolate); Locker locker(isolate);
MATE_HANDLE_SCOPE(isolate); MATE_HANDLE_SCOPE(isolate);
v8::Handle<v8::Function> holder = function->NewHandle(); v8::Local<v8::Function> holder = function->NewHandle();
v8::Handle<v8::Value> args[] = { v8::Local<v8::Value> args[] = {
ConvertToV8(isolate, a1), ConvertToV8(isolate, a1),
ConvertToV8(isolate, a2), ConvertToV8(isolate, a2),
ConvertToV8(isolate, a3), ConvertToV8(isolate, a3),
ConvertToV8(isolate, a4), ConvertToV8(isolate, a4),
ConvertToV8(isolate, a5), ConvertToV8(isolate, a5),
}; };
v8::Handle<v8::Value> val(holder->Call(holder, arraysize(args), args)); v8::Local<v8::Value> val(holder->Call(holder, arraysize(args), args));
Converter<R>::FromV8(isolate, val, &ret); Converter<R>::FromV8(isolate, val, &ret);
return ret; return ret;
} }
@ -205,8 +205,8 @@ struct V8FunctionInvoker<void(P1, P2, P3, P4, P5)> {
P3 a3, P4 a4, P5 a5) { P3 a3, P4 a4, P5 a5) {
Locker locker(isolate); Locker locker(isolate);
MATE_HANDLE_SCOPE(isolate); MATE_HANDLE_SCOPE(isolate);
v8::Handle<v8::Function> holder = function->NewHandle(); v8::Local<v8::Function> holder = function->NewHandle();
v8::Handle<v8::Value> args[] = { v8::Local<v8::Value> args[] = {
ConvertToV8(isolate, a1), ConvertToV8(isolate, a1),
ConvertToV8(isolate, a2), ConvertToV8(isolate, a2),
ConvertToV8(isolate, a3), ConvertToV8(isolate, a3),
@ -225,8 +225,8 @@ struct V8FunctionInvoker<R(P1, P2, P3, P4, P5, P6)> {
R ret; R ret;
Locker locker(isolate); Locker locker(isolate);
MATE_HANDLE_SCOPE(isolate); MATE_HANDLE_SCOPE(isolate);
v8::Handle<v8::Function> holder = function->NewHandle(); v8::Local<v8::Function> holder = function->NewHandle();
v8::Handle<v8::Value> args[] = { v8::Local<v8::Value> args[] = {
ConvertToV8(isolate, a1), ConvertToV8(isolate, a1),
ConvertToV8(isolate, a2), ConvertToV8(isolate, a2),
ConvertToV8(isolate, a3), ConvertToV8(isolate, a3),
@ -234,7 +234,7 @@ struct V8FunctionInvoker<R(P1, P2, P3, P4, P5, P6)> {
ConvertToV8(isolate, a5), ConvertToV8(isolate, a5),
ConvertToV8(isolate, a6), ConvertToV8(isolate, a6),
}; };
v8::Handle<v8::Value> val(holder->Call(holder, arraysize(args), args)); v8::Local<v8::Value> val(holder->Call(holder, arraysize(args), args));
Converter<R>::FromV8(isolate, val, &ret); Converter<R>::FromV8(isolate, val, &ret);
return ret; return ret;
} }
@ -247,8 +247,8 @@ struct V8FunctionInvoker<void(P1, P2, P3, P4, P5, P6)> {
P3 a3, P4 a4, P5 a5, P6 a6) { P3 a3, P4 a4, P5 a5, P6 a6) {
Locker locker(isolate); Locker locker(isolate);
MATE_HANDLE_SCOPE(isolate); MATE_HANDLE_SCOPE(isolate);
v8::Handle<v8::Function> holder = function->NewHandle(); v8::Local<v8::Function> holder = function->NewHandle();
v8::Handle<v8::Value> args[] = { v8::Local<v8::Value> args[] = {
ConvertToV8(isolate, a1), ConvertToV8(isolate, a1),
ConvertToV8(isolate, a2), ConvertToV8(isolate, a2),
ConvertToV8(isolate, a3), ConvertToV8(isolate, a3),
@ -264,12 +264,12 @@ struct V8FunctionInvoker<void(P1, P2, P3, P4, P5, P6)> {
template<typename Sig> template<typename Sig>
struct Converter<base::Callback<Sig> > { struct Converter<base::Callback<Sig> > {
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const base::Callback<Sig>& val) { const base::Callback<Sig>& val) {
return CreateFunctionTemplate(isolate, val)->GetFunction(); return CreateFunctionTemplate(isolate, val)->GetFunction();
} }
static bool FromV8(v8::Isolate* isolate, static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val, v8::Local<v8::Value> val,
base::Callback<Sig>* out) { base::Callback<Sig>* out) {
if (!val->IsFunction()) if (!val->IsFunction())
return false; return false;

View file

@ -35,19 +35,19 @@ struct V8FunctionInvoker<R($for ARG , [[P$(ARG)]])> {
R ret; R ret;
Locker locker(isolate); Locker locker(isolate);
MATE_HANDLE_SCOPE(isolate); MATE_HANDLE_SCOPE(isolate);
v8::Handle<v8::Function> holder = function->NewHandle(); v8::Local<v8::Function> holder = function->NewHandle();
$if ARITY == 0 [[ $if ARITY == 0 [[
v8::Handle<v8::Value> val(holder->Call(holder, 0, NULL)); v8::Local<v8::Value> val(holder->Call(holder, 0, NULL));
]] $else [[ ]] $else [[
v8::Handle<v8::Value> args[] = { v8::Local<v8::Value> args[] = {
$for ARG [[ $for ARG [[
ConvertToV8(isolate, a$(ARG)), ConvertToV8(isolate, a$(ARG)),
]] ]]
}; };
v8::Handle<v8::Value> val(holder->Call(holder, arraysize(args), args)); v8::Local<v8::Value> val(holder->Call(holder, arraysize(args), args));
]] ]]
Converter<R>::FromV8(isolate, val, &ret); Converter<R>::FromV8(isolate, val, &ret);
@ -60,12 +60,12 @@ struct V8FunctionInvoker<void($for ARG , [[P$(ARG)]])> {
static void Go(v8::Isolate* isolate, SafeV8Function function$for ARG [[, P$(ARG) a$(ARG)]]) { static void Go(v8::Isolate* isolate, SafeV8Function function$for ARG [[, P$(ARG) a$(ARG)]]) {
Locker locker(isolate); Locker locker(isolate);
MATE_HANDLE_SCOPE(isolate); MATE_HANDLE_SCOPE(isolate);
v8::Handle<v8::Function> holder = function->NewHandle(); v8::Local<v8::Function> holder = function->NewHandle();
$if ARITY == 0 [[ $if ARITY == 0 [[
holder->Call(holder, 0, NULL); holder->Call(holder, 0, NULL);
]] $else [[ ]] $else [[
v8::Handle<v8::Value> args[] = { v8::Local<v8::Value> args[] = {
$for ARG [[ $for ARG [[
ConvertToV8(isolate, a$(ARG)), ConvertToV8(isolate, a$(ARG)),
@ -84,12 +84,12 @@ $for ARG [[
template<typename Sig> template<typename Sig>
struct Converter<base::Callback<Sig> > { struct Converter<base::Callback<Sig> > {
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const base::Callback<Sig>& val) { const base::Callback<Sig>& val) {
return CreateFunctionTemplate(isolate, val)->GetFunction(); return CreateFunctionTemplate(isolate, val)->GetFunction();
} }
static bool FromV8(v8::Isolate* isolate, static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val, v8::Local<v8::Value> val,
base::Callback<Sig>* out) { base::Callback<Sig>* out) {
if (!val->IsFunction()) if (!val->IsFunction())
return false; return false;

View file

@ -69,7 +69,7 @@
#define MATE_HANDLE_SCOPE(isolate) v8::HandleScope handle_scope #define MATE_HANDLE_SCOPE(isolate) v8::HandleScope handle_scope
#define MATE_METHOD_ARGS_TYPE v8::Arguments #define MATE_METHOD_ARGS_TYPE v8::Arguments
#define MATE_METHOD_RETURN_TYPE v8::Handle<v8::Value> #define MATE_METHOD_RETURN_TYPE v8::Local<v8::Value>
#define MATE_METHOD_RETURN_VALUE(value) return value #define MATE_METHOD_RETURN_VALUE(value) return value
#define MATE_METHOD_RETURN_UNDEFINED() return v8::Undefined() #define MATE_METHOD_RETURN_UNDEFINED() return v8::Undefined()

View file

@ -133,7 +133,7 @@ class Constructor {
MATE_PERSISTENT_RESET(constructor_); MATE_PERSISTENT_RESET(constructor_);
} }
v8::Handle<v8::FunctionTemplate> GetFunctionTemplate( v8::Local<v8::FunctionTemplate> GetFunctionTemplate(
v8::Isolate* isolate, const WrappableFactoryFunction& factory) { v8::Isolate* isolate, const WrappableFactoryFunction& factory) {
if (constructor_.IsEmpty()) { if (constructor_.IsEmpty()) {
v8::Local<v8::FunctionTemplate> constructor = CreateFunctionTemplate( v8::Local<v8::FunctionTemplate> constructor = CreateFunctionTemplate(

View file

@ -69,7 +69,7 @@ class Constructor {
MATE_PERSISTENT_RESET(constructor_); MATE_PERSISTENT_RESET(constructor_);
} }
v8::Handle<v8::FunctionTemplate> GetFunctionTemplate( v8::Local<v8::FunctionTemplate> GetFunctionTemplate(
v8::Isolate* isolate, const WrappableFactoryFunction& factory) { v8::Isolate* isolate, const WrappableFactoryFunction& factory) {
if (constructor_.IsEmpty()) { if (constructor_.IsEmpty()) {
v8::Local<v8::FunctionTemplate> constructor = CreateFunctionTemplate( v8::Local<v8::FunctionTemplate> constructor = CreateFunctionTemplate(

View file

@ -10,9 +10,9 @@
using v8::Boolean; using v8::Boolean;
using v8::External; using v8::External;
using v8::Function; using v8::Function;
using v8::Handle;
using v8::Integer; using v8::Integer;
using v8::Isolate; using v8::Isolate;
using v8::Local;
using v8::Number; using v8::Number;
using v8::Object; using v8::Object;
using v8::String; using v8::String;
@ -20,11 +20,11 @@ using v8::Value;
namespace mate { namespace mate {
Handle<Value> Converter<bool>::ToV8(Isolate* isolate, bool val) { Local<Value> Converter<bool>::ToV8(Isolate* isolate, bool val) {
return MATE_BOOLEAN_NEW(isolate, val); return MATE_BOOLEAN_NEW(isolate, val);
} }
bool Converter<bool>::FromV8(Isolate* isolate, Handle<Value> val, bool* out) { bool Converter<bool>::FromV8(Isolate* isolate, Local<Value> val, bool* out) {
if (!val->IsBoolean()) if (!val->IsBoolean())
return false; return false;
*out = val->BooleanValue(); *out = val->BooleanValue();
@ -32,12 +32,12 @@ bool Converter<bool>::FromV8(Isolate* isolate, Handle<Value> val, bool* out) {
} }
#if !defined(OS_LINUX) #if !defined(OS_LINUX)
Handle<Value> Converter<unsigned long>::ToV8(Isolate* isolate, Local<Value> Converter<unsigned long>::ToV8(Isolate* isolate,
unsigned long val) { unsigned long val) {
return MATE_INTEGER_NEW(isolate, val); return MATE_INTEGER_NEW(isolate, val);
} }
bool Converter<unsigned long>::FromV8(Isolate* isolate, Handle<Value> val, bool Converter<unsigned long>::FromV8(Isolate* isolate, Local<Value> val,
unsigned long* out) { unsigned long* out) {
if (!val->IsNumber()) if (!val->IsNumber())
return false; return false;
@ -46,11 +46,11 @@ bool Converter<unsigned long>::FromV8(Isolate* isolate, Handle<Value> val,
} }
#endif #endif
Handle<Value> Converter<int32_t>::ToV8(Isolate* isolate, int32_t val) { Local<Value> Converter<int32_t>::ToV8(Isolate* isolate, int32_t val) {
return MATE_INTEGER_NEW(isolate, val); return MATE_INTEGER_NEW(isolate, val);
} }
bool Converter<int32_t>::FromV8(Isolate* isolate, Handle<Value> val, bool Converter<int32_t>::FromV8(Isolate* isolate, Local<Value> val,
int32_t* out) { int32_t* out) {
if (!val->IsInt32()) if (!val->IsInt32())
return false; return false;
@ -58,11 +58,11 @@ bool Converter<int32_t>::FromV8(Isolate* isolate, Handle<Value> val,
return true; return true;
} }
Handle<Value> Converter<uint32_t>::ToV8(Isolate* isolate, uint32_t val) { Local<Value> Converter<uint32_t>::ToV8(Isolate* isolate, uint32_t val) {
return MATE_INTEGER_NEW_UNSIGNED(isolate, val); return MATE_INTEGER_NEW_UNSIGNED(isolate, val);
} }
bool Converter<uint32_t>::FromV8(Isolate* isolate, Handle<Value> val, bool Converter<uint32_t>::FromV8(Isolate* isolate, Local<Value> val,
uint32_t* out) { uint32_t* out) {
if (!val->IsUint32()) if (!val->IsUint32())
return false; return false;
@ -70,11 +70,11 @@ bool Converter<uint32_t>::FromV8(Isolate* isolate, Handle<Value> val,
return true; return true;
} }
Handle<Value> Converter<int64_t>::ToV8(Isolate* isolate, int64_t val) { Local<Value> Converter<int64_t>::ToV8(Isolate* isolate, int64_t val) {
return MATE_NUMBER_NEW(isolate, static_cast<double>(val)); return MATE_NUMBER_NEW(isolate, static_cast<double>(val));
} }
bool Converter<int64_t>::FromV8(Isolate* isolate, Handle<Value> val, bool Converter<int64_t>::FromV8(Isolate* isolate, Local<Value> val,
int64_t* out) { int64_t* out) {
if (!val->IsNumber()) if (!val->IsNumber())
return false; return false;
@ -84,11 +84,11 @@ bool Converter<int64_t>::FromV8(Isolate* isolate, Handle<Value> val,
return true; return true;
} }
Handle<Value> Converter<uint64_t>::ToV8(Isolate* isolate, uint64_t val) { Local<Value> Converter<uint64_t>::ToV8(Isolate* isolate, uint64_t val) {
return MATE_NUMBER_NEW(isolate, static_cast<double>(val)); return MATE_NUMBER_NEW(isolate, static_cast<double>(val));
} }
bool Converter<uint64_t>::FromV8(Isolate* isolate, Handle<Value> val, bool Converter<uint64_t>::FromV8(Isolate* isolate, Local<Value> val,
uint64_t* out) { uint64_t* out) {
if (!val->IsNumber()) if (!val->IsNumber())
return false; return false;
@ -96,11 +96,11 @@ bool Converter<uint64_t>::FromV8(Isolate* isolate, Handle<Value> val,
return true; return true;
} }
Handle<Value> Converter<float>::ToV8(Isolate* isolate, float val) { Local<Value> Converter<float>::ToV8(Isolate* isolate, float val) {
return MATE_NUMBER_NEW(isolate, val); return MATE_NUMBER_NEW(isolate, val);
} }
bool Converter<float>::FromV8(Isolate* isolate, Handle<Value> val, bool Converter<float>::FromV8(Isolate* isolate, Local<Value> val,
float* out) { float* out) {
if (!val->IsNumber()) if (!val->IsNumber())
return false; return false;
@ -108,11 +108,11 @@ bool Converter<float>::FromV8(Isolate* isolate, Handle<Value> val,
return true; return true;
} }
Handle<Value> Converter<double>::ToV8(Isolate* isolate, double val) { Local<Value> Converter<double>::ToV8(Isolate* isolate, double val) {
return MATE_NUMBER_NEW(isolate, val); return MATE_NUMBER_NEW(isolate, val);
} }
bool Converter<double>::FromV8(Isolate* isolate, Handle<Value> val, bool Converter<double>::FromV8(Isolate* isolate, Local<Value> val,
double* out) { double* out) {
if (!val->IsNumber()) if (!val->IsNumber())
return false; return false;
@ -120,100 +120,100 @@ bool Converter<double>::FromV8(Isolate* isolate, Handle<Value> val,
return true; return true;
} }
Handle<Value> Converter<const char*>::ToV8( Local<Value> Converter<const char*>::ToV8(
Isolate* isolate, const char* val) { Isolate* isolate, const char* val) {
return MATE_STRING_NEW_FROM_UTF8(isolate, val, -1); return MATE_STRING_NEW_FROM_UTF8(isolate, val, -1);
} }
Handle<Value> Converter<base::StringPiece>::ToV8( Local<Value> Converter<base::StringPiece>::ToV8(
Isolate* isolate, const base::StringPiece& val) { Isolate* isolate, const base::StringPiece& val) {
return MATE_STRING_NEW_FROM_UTF8(isolate, val.data(), return MATE_STRING_NEW_FROM_UTF8(isolate, val.data(),
static_cast<uint32_t>(val.length())); static_cast<uint32_t>(val.length()));
} }
Handle<Value> Converter<std::string>::ToV8(Isolate* isolate, Local<Value> Converter<std::string>::ToV8(Isolate* isolate,
const std::string& val) { const std::string& val) {
return Converter<base::StringPiece>::ToV8(isolate, val); return Converter<base::StringPiece>::ToV8(isolate, val);
} }
bool Converter<std::string>::FromV8(Isolate* isolate, Handle<Value> val, bool Converter<std::string>::FromV8(Isolate* isolate, Local<Value> val,
std::string* out) { std::string* out) {
if (!val->IsString()) if (!val->IsString())
return false; return false;
Handle<String> str = Handle<String>::Cast(val); Local<String> str = Local<String>::Cast(val);
int length = str->Utf8Length(); int length = str->Utf8Length();
out->resize(length); out->resize(length);
str->WriteUtf8(&(*out)[0], length, NULL, String::NO_NULL_TERMINATION); str->WriteUtf8(&(*out)[0], length, NULL, String::NO_NULL_TERMINATION);
return true; return true;
} }
bool Converter<Handle<Function> >::FromV8(Isolate* isolate, Handle<Value> val, bool Converter<Local<Function> >::FromV8(Isolate* isolate, Local<Value> val,
Handle<Function>* out) { Local<Function>* out) {
if (!val->IsFunction()) if (!val->IsFunction())
return false; return false;
*out = Handle<Function>::Cast(val); *out = Local<Function>::Cast(val);
return true; return true;
} }
Handle<Value> Converter<Handle<Object> >::ToV8(Isolate* isolate, Local<Value> Converter<Local<Object> >::ToV8(Isolate* isolate,
Handle<Object> val) { Local<Object> val) {
return val; return val;
} }
bool Converter<Handle<Object> >::FromV8(Isolate* isolate, Handle<Value> val, bool Converter<Local<Object> >::FromV8(Isolate* isolate, Local<Value> val,
Handle<Object>* out) { Local<Object>* out) {
if (!val->IsObject()) if (!val->IsObject())
return false; return false;
*out = Handle<Object>::Cast(val); *out = Local<Object>::Cast(val);
return true; return true;
} }
Handle<Value> Converter<Handle<String> >::ToV8(Isolate* isolate, Local<Value> Converter<Local<String> >::ToV8(Isolate* isolate,
Handle<String> val) { Local<String> val) {
return val; return val;
} }
bool Converter<Handle<String> >::FromV8(Isolate* isolate, Handle<Value> val, bool Converter<Local<String> >::FromV8(Isolate* isolate, Local<Value> val,
Handle<String>* out) { Local<String>* out) {
if (!val->IsString()) if (!val->IsString())
return false; return false;
*out = Handle<String>::Cast(val); *out = Local<String>::Cast(val);
return true; return true;
} }
Handle<Value> Converter<Handle<External> >::ToV8(Isolate* isolate, Local<Value> Converter<Local<External> >::ToV8(Isolate* isolate,
Handle<External> val) { Local<External> val) {
return val; return val;
} }
bool Converter<Handle<External> >::FromV8(Isolate* isolate, bool Converter<Local<External> >::FromV8(Isolate* isolate,
v8::Handle<Value> val, v8::Local<Value> val,
Handle<External>* out) { Local<External>* out) {
if (!val->IsExternal()) if (!val->IsExternal())
return false; return false;
*out = Handle<External>::Cast(val); *out = Local<External>::Cast(val);
return true; return true;
} }
Handle<Value> Converter<Handle<Value> >::ToV8(Isolate* isolate, Local<Value> Converter<Local<Value> >::ToV8(Isolate* isolate,
Handle<Value> val) { Local<Value> val) {
return val; return val;
} }
bool Converter<Handle<Value> >::FromV8(Isolate* isolate, Handle<Value> val, bool Converter<Local<Value> >::FromV8(Isolate* isolate, Local<Value> val,
Handle<Value>* out) { Local<Value>* out) {
*out = val; *out = val;
return true; return true;
} }
v8::Handle<v8::String> StringToSymbol(v8::Isolate* isolate, v8::Local<v8::String> StringToSymbol(v8::Isolate* isolate,
const base::StringPiece& val) { const base::StringPiece& val) {
return MATE_STRING_NEW_SYMBOL(isolate, return MATE_STRING_NEW_SYMBOL(isolate,
val.data(), val.data(),
static_cast<uint32_t>(val.length())); static_cast<uint32_t>(val.length()));
} }
std::string V8ToString(v8::Handle<v8::Value> value) { std::string V8ToString(v8::Local<v8::Value> value) {
if (value.IsEmpty()) if (value.IsEmpty())
return std::string(); return std::string();
std::string result; std::string result;

View file

@ -20,156 +20,156 @@ struct Converter {};
template<> template<>
struct Converter<void*> { struct Converter<void*> {
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, void* val) { static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, void* val) {
return MATE_UNDEFINED(isolate); return MATE_UNDEFINED(isolate);
} }
}; };
template<> template<>
struct Converter<bool> { struct Converter<bool> {
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
bool val); bool val);
static bool FromV8(v8::Isolate* isolate, static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val, v8::Local<v8::Value> val,
bool* out); bool* out);
}; };
#if !defined(OS_LINUX) #if !defined(OS_LINUX)
template<> template<>
struct Converter<unsigned long> { struct Converter<unsigned long> {
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
unsigned long val); unsigned long val);
static bool FromV8(v8::Isolate* isolate, static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val, v8::Local<v8::Value> val,
unsigned long* out); unsigned long* out);
}; };
#endif #endif
template<> template<>
struct Converter<int32_t> { struct Converter<int32_t> {
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
int32_t val); int32_t val);
static bool FromV8(v8::Isolate* isolate, static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val, v8::Local<v8::Value> val,
int32_t* out); int32_t* out);
}; };
template<> template<>
struct Converter<uint32_t> { struct Converter<uint32_t> {
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
uint32_t val); uint32_t val);
static bool FromV8(v8::Isolate* isolate, static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val, v8::Local<v8::Value> val,
uint32_t* out); uint32_t* out);
}; };
template<> template<>
struct Converter<int64_t> { struct Converter<int64_t> {
// Warning: JavaScript cannot represent 64 integers precisely. // Warning: JavaScript cannot represent 64 integers precisely.
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
int64_t val); int64_t val);
static bool FromV8(v8::Isolate* isolate, static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val, v8::Local<v8::Value> val,
int64_t* out); int64_t* out);
}; };
template<> template<>
struct Converter<uint64_t> { struct Converter<uint64_t> {
// Warning: JavaScript cannot represent 64 integers precisely. // Warning: JavaScript cannot represent 64 integers precisely.
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
uint64_t val); uint64_t val);
static bool FromV8(v8::Isolate* isolate, static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val, v8::Local<v8::Value> val,
uint64_t* out); uint64_t* out);
}; };
template<> template<>
struct Converter<float> { struct Converter<float> {
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
float val); float val);
static bool FromV8(v8::Isolate* isolate, static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val, v8::Local<v8::Value> val,
float* out); float* out);
}; };
template<> template<>
struct Converter<double> { struct Converter<double> {
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
double val); double val);
static bool FromV8(v8::Isolate* isolate, static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val, v8::Local<v8::Value> val,
double* out); double* out);
}; };
template<> template<>
struct Converter<const char*> { struct Converter<const char*> {
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, const char* val); static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, const char* val);
}; };
template<> template<>
struct Converter<base::StringPiece> { struct Converter<base::StringPiece> {
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const base::StringPiece& val); const base::StringPiece& val);
// No conversion out is possible because StringPiece does not contain storage. // No conversion out is possible because StringPiece does not contain storage.
}; };
template<> template<>
struct Converter<std::string> { struct Converter<std::string> {
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const std::string& val); const std::string& val);
static bool FromV8(v8::Isolate* isolate, static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val, v8::Local<v8::Value> val,
std::string* out); std::string* out);
}; };
template<> template<>
struct Converter<v8::Handle<v8::Function> > { struct Converter<v8::Local<v8::Function> > {
static bool FromV8(v8::Isolate* isolate, static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val, v8::Local<v8::Value> val,
v8::Handle<v8::Function>* out); v8::Local<v8::Function>* out);
}; };
template<> template<>
struct Converter<v8::Handle<v8::Object> > { struct Converter<v8::Local<v8::Object> > {
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
v8::Handle<v8::Object> val); v8::Local<v8::Object> val);
static bool FromV8(v8::Isolate* isolate, static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val, v8::Local<v8::Value> val,
v8::Handle<v8::Object>* out); v8::Local<v8::Object>* out);
}; };
template<> template<>
struct Converter<v8::Handle<v8::String> > { struct Converter<v8::Local<v8::String> > {
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
v8::Handle<v8::String> val); v8::Local<v8::String> val);
static bool FromV8(v8::Isolate* isolate, static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val, v8::Local<v8::Value> val,
v8::Handle<v8::String>* out); v8::Local<v8::String>* out);
}; };
template<> template<>
struct Converter<v8::Handle<v8::External> > { struct Converter<v8::Local<v8::External> > {
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
v8::Handle<v8::External> val); v8::Local<v8::External> val);
static bool FromV8(v8::Isolate* isolate, static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val, v8::Local<v8::Value> val,
v8::Handle<v8::External>* out); v8::Local<v8::External>* out);
}; };
template<> template<>
struct Converter<v8::Handle<v8::Value> > { struct Converter<v8::Local<v8::Value> > {
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val); v8::Local<v8::Value> val);
static bool FromV8(v8::Isolate* isolate, static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val, v8::Local<v8::Value> val,
v8::Handle<v8::Value>* out); v8::Local<v8::Value>* out);
}; };
template<typename T> template<typename T>
struct Converter<std::vector<T> > { struct Converter<std::vector<T> > {
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const std::vector<T>& val) { const std::vector<T>& val) {
v8::Handle<v8::Array> result( v8::Local<v8::Array> result(
MATE_ARRAY_NEW(isolate, static_cast<int>(val.size()))); MATE_ARRAY_NEW(isolate, static_cast<int>(val.size())));
for (size_t i = 0; i < val.size(); ++i) { for (size_t i = 0; i < val.size(); ++i) {
result->Set(static_cast<int>(i), Converter<T>::ToV8(isolate, val[i])); result->Set(static_cast<int>(i), Converter<T>::ToV8(isolate, val[i]));
@ -178,13 +178,13 @@ struct Converter<std::vector<T> > {
} }
static bool FromV8(v8::Isolate* isolate, static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val, v8::Local<v8::Value> val,
std::vector<T>* out) { std::vector<T>* out) {
if (!val->IsArray()) if (!val->IsArray())
return false; return false;
std::vector<T> result; std::vector<T> result;
v8::Handle<v8::Array> array(v8::Handle<v8::Array>::Cast(val)); v8::Local<v8::Array> array(v8::Local<v8::Array>::Cast(val));
uint32_t length = array->Length(); uint32_t length = array->Length();
for (uint32_t i = 0; i < length; ++i) { for (uint32_t i = 0; i < length; ++i) {
T item; T item;
@ -200,9 +200,9 @@ struct Converter<std::vector<T> > {
template<typename T> template<typename T>
struct Converter<std::set<T> > { struct Converter<std::set<T> > {
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const std::set<T>& val) { const std::set<T>& val) {
v8::Handle<v8::Array> result( v8::Local<v8::Array> result(
MATE_ARRAY_NEW(isolate, static_cast<int>(val.size()))); MATE_ARRAY_NEW(isolate, static_cast<int>(val.size())));
typename std::set<T>::const_iterator it; typename std::set<T>::const_iterator it;
int i; int i;
@ -212,13 +212,13 @@ struct Converter<std::set<T> > {
} }
static bool FromV8(v8::Isolate* isolate, static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val, v8::Local<v8::Value> val,
std::set<T>* out) { std::set<T>* out) {
if (!val->IsArray()) if (!val->IsArray())
return false; return false;
std::set<T> result; std::set<T> result;
v8::Handle<v8::Array> array(v8::Handle<v8::Array>::Cast(val)); v8::Local<v8::Array> array(v8::Local<v8::Array>::Cast(val));
uint32_t length = array->Length(); uint32_t length = array->Length();
for (uint32_t i = 0; i < length; ++i) { for (uint32_t i = 0; i < length; ++i) {
T item; T item;
@ -234,32 +234,32 @@ struct Converter<std::set<T> > {
// Convenience functions that deduce T. // Convenience functions that deduce T.
template<typename T> template<typename T>
v8::Handle<v8::Value> ConvertToV8(v8::Isolate* isolate, v8::Local<v8::Value> ConvertToV8(v8::Isolate* isolate,
const T& input) { const T& input) {
return Converter<T>::ToV8(isolate, input); return Converter<T>::ToV8(isolate, input);
} }
inline v8::Handle<v8::Value> ConvertToV8(v8::Isolate* isolate, inline v8::Local<v8::Value> ConvertToV8(v8::Isolate* isolate,
const char* input) { const char* input) {
return Converter<const char*>::ToV8(isolate, input); return Converter<const char*>::ToV8(isolate, input);
} }
inline v8::Handle<v8::String> StringToV8( inline v8::Local<v8::String> StringToV8(
v8::Isolate* isolate, v8::Isolate* isolate,
const base::StringPiece& input) { const base::StringPiece& input) {
return ConvertToV8(isolate, input).As<v8::String>(); return ConvertToV8(isolate, input).As<v8::String>();
} }
v8::Handle<v8::String> StringToSymbol(v8::Isolate* isolate, v8::Local<v8::String> StringToSymbol(v8::Isolate* isolate,
const base::StringPiece& input); const base::StringPiece& input);
template<typename T> template<typename T>
bool ConvertFromV8(v8::Isolate* isolate, v8::Handle<v8::Value> input, bool ConvertFromV8(v8::Isolate* isolate, v8::Local<v8::Value> input,
T* result) { T* result) {
return Converter<T>::FromV8(isolate, input, result); return Converter<T>::FromV8(isolate, input, result);
} }
std::string V8ToString(v8::Handle<v8::Value> value); std::string V8ToString(v8::Local<v8::Value> value);
} // namespace mate } // namespace mate

View file

@ -11,7 +11,7 @@ Dictionary::Dictionary()
} }
Dictionary::Dictionary(v8::Isolate* isolate, Dictionary::Dictionary(v8::Isolate* isolate,
v8::Handle<v8::Object> object) v8::Local<v8::Object> object)
: isolate_(isolate), : isolate_(isolate),
object_(object) { object_(object) {
} }
@ -19,21 +19,21 @@ Dictionary::Dictionary(v8::Isolate* isolate,
Dictionary::~Dictionary() { Dictionary::~Dictionary() {
} }
v8::Handle<v8::Object> Dictionary::GetHandle() const { v8::Local<v8::Object> Dictionary::GetHandle() const {
return object_; return object_;
} }
v8::Handle<v8::Value> Converter<Dictionary>::ToV8(v8::Isolate* isolate, v8::Local<v8::Value> Converter<Dictionary>::ToV8(v8::Isolate* isolate,
Dictionary val) { Dictionary val) {
return val.GetHandle(); return val.GetHandle();
} }
bool Converter<Dictionary>::FromV8(v8::Isolate* isolate, bool Converter<Dictionary>::FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val, v8::Local<v8::Value> val,
Dictionary* out) { Dictionary* out) {
if (!val->IsObject()) if (!val->IsObject())
return false; return false;
*out = Dictionary(isolate, v8::Handle<v8::Object>::Cast(val)); *out = Dictionary(isolate, v8::Local<v8::Object>::Cast(val));
return true; return true;
} }

View file

@ -25,12 +25,12 @@ namespace mate {
class Dictionary { class Dictionary {
public: public:
Dictionary(); Dictionary();
Dictionary(v8::Isolate* isolate, v8::Handle<v8::Object> object); Dictionary(v8::Isolate* isolate, v8::Local<v8::Object> object);
~Dictionary(); ~Dictionary();
template<typename T> template<typename T>
bool Get(const base::StringPiece& key, T* out) const { bool Get(const base::StringPiece& key, T* out) const {
v8::Handle<v8::Value> val = GetHandle()->Get(StringToV8(isolate_, key)); v8::Local<v8::Value> val = GetHandle()->Get(StringToV8(isolate_, key));
return ConvertFromV8(isolate_, val, out); return ConvertFromV8(isolate_, val, out);
} }
@ -49,7 +49,7 @@ class Dictionary {
bool IsEmpty() const { return isolate() == NULL; } bool IsEmpty() const { return isolate() == NULL; }
virtual v8::Handle<v8::Object> GetHandle() const; virtual v8::Local<v8::Object> GetHandle() const;
v8::Isolate* isolate() const { return isolate_; } v8::Isolate* isolate() const { return isolate_; }
@ -57,15 +57,15 @@ class Dictionary {
v8::Isolate* isolate_; v8::Isolate* isolate_;
private: private:
v8::Handle<v8::Object> object_; v8::Local<v8::Object> object_;
}; };
template<> template<>
struct Converter<Dictionary> { struct Converter<Dictionary> {
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
Dictionary val); Dictionary val);
static bool FromV8(v8::Isolate* isolate, static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val, v8::Local<v8::Value> val,
Dictionary* out); Dictionary* out);
}; };

View file

@ -17,7 +17,7 @@ CallbackHolderBase::~CallbackHolderBase() {
DCHECK(v8_ref_.IsEmpty()); DCHECK(v8_ref_.IsEmpty());
} }
v8::Handle<v8::External> CallbackHolderBase::GetHandle(v8::Isolate* isolate) { v8::Local<v8::External> CallbackHolderBase::GetHandle(v8::Isolate* isolate) {
return MATE_PERSISTENT_TO_LOCAL(v8::External, isolate, v8_ref_); return MATE_PERSISTENT_TO_LOCAL(v8::External, isolate, v8_ref_);
} }

View file

@ -48,7 +48,7 @@ struct CallbackParamTraits<const T*> {
// among every CallbackHolder instance. // among every CallbackHolder instance.
class CallbackHolderBase { class CallbackHolderBase {
public: public:
v8::Handle<v8::External> GetHandle(v8::Isolate* isolate); v8::Local<v8::External> GetHandle(v8::Isolate* isolate);
protected: protected:
explicit CallbackHolderBase(v8::Isolate* isolate); explicit CallbackHolderBase(v8::Isolate* isolate);
@ -333,7 +333,7 @@ template<typename R>
struct Dispatcher<R()> { struct Dispatcher<R()> {
static MATE_METHOD(DispatchToCallback) { static MATE_METHOD(DispatchToCallback) {
Arguments args(info); Arguments args(info);
v8::Handle<v8::External> v8_holder; v8::Local<v8::External> v8_holder;
CHECK(args.GetData(&v8_holder)); CHECK(args.GetData(&v8_holder));
CallbackHolderBase* holder_base = reinterpret_cast<CallbackHolderBase*>( CallbackHolderBase* holder_base = reinterpret_cast<CallbackHolderBase*>(
v8_holder->Value()); v8_holder->Value());
@ -349,7 +349,7 @@ template<typename R, typename P1>
struct Dispatcher<R(P1)> { struct Dispatcher<R(P1)> {
static MATE_METHOD(DispatchToCallback) { static MATE_METHOD(DispatchToCallback) {
Arguments args(info); Arguments args(info);
v8::Handle<v8::External> v8_holder; v8::Local<v8::External> v8_holder;
CHECK(args.GetData(&v8_holder)); CHECK(args.GetData(&v8_holder));
CallbackHolderBase* holder_base = reinterpret_cast<CallbackHolderBase*>( CallbackHolderBase* holder_base = reinterpret_cast<CallbackHolderBase*>(
v8_holder->Value()); v8_holder->Value());
@ -371,7 +371,7 @@ template<typename R, typename P1, typename P2>
struct Dispatcher<R(P1, P2)> { struct Dispatcher<R(P1, P2)> {
static MATE_METHOD(DispatchToCallback) { static MATE_METHOD(DispatchToCallback) {
Arguments args(info); Arguments args(info);
v8::Handle<v8::External> v8_holder; v8::Local<v8::External> v8_holder;
CHECK(args.GetData(&v8_holder)); CHECK(args.GetData(&v8_holder));
CallbackHolderBase* holder_base = reinterpret_cast<CallbackHolderBase*>( CallbackHolderBase* holder_base = reinterpret_cast<CallbackHolderBase*>(
v8_holder->Value()); v8_holder->Value());
@ -395,7 +395,7 @@ template<typename R, typename P1, typename P2, typename P3>
struct Dispatcher<R(P1, P2, P3)> { struct Dispatcher<R(P1, P2, P3)> {
static MATE_METHOD(DispatchToCallback) { static MATE_METHOD(DispatchToCallback) {
Arguments args(info); Arguments args(info);
v8::Handle<v8::External> v8_holder; v8::Local<v8::External> v8_holder;
CHECK(args.GetData(&v8_holder)); CHECK(args.GetData(&v8_holder));
CallbackHolderBase* holder_base = reinterpret_cast<CallbackHolderBase*>( CallbackHolderBase* holder_base = reinterpret_cast<CallbackHolderBase*>(
v8_holder->Value()); v8_holder->Value());
@ -421,7 +421,7 @@ template<typename R, typename P1, typename P2, typename P3, typename P4>
struct Dispatcher<R(P1, P2, P3, P4)> { struct Dispatcher<R(P1, P2, P3, P4)> {
static MATE_METHOD(DispatchToCallback) { static MATE_METHOD(DispatchToCallback) {
Arguments args(info); Arguments args(info);
v8::Handle<v8::External> v8_holder; v8::Local<v8::External> v8_holder;
CHECK(args.GetData(&v8_holder)); CHECK(args.GetData(&v8_holder));
CallbackHolderBase* holder_base = reinterpret_cast<CallbackHolderBase*>( CallbackHolderBase* holder_base = reinterpret_cast<CallbackHolderBase*>(
v8_holder->Value()); v8_holder->Value());
@ -451,7 +451,7 @@ template<typename R, typename P1, typename P2, typename P3, typename P4,
struct Dispatcher<R(P1, P2, P3, P4, P5)> { struct Dispatcher<R(P1, P2, P3, P4, P5)> {
static MATE_METHOD(DispatchToCallback) { static MATE_METHOD(DispatchToCallback) {
Arguments args(info); Arguments args(info);
v8::Handle<v8::External> v8_holder; v8::Local<v8::External> v8_holder;
CHECK(args.GetData(&v8_holder)); CHECK(args.GetData(&v8_holder));
CallbackHolderBase* holder_base = reinterpret_cast<CallbackHolderBase*>( CallbackHolderBase* holder_base = reinterpret_cast<CallbackHolderBase*>(
v8_holder->Value()); v8_holder->Value());
@ -483,7 +483,7 @@ template<typename R, typename P1, typename P2, typename P3, typename P4,
struct Dispatcher<R(P1, P2, P3, P4, P5, P6)> { struct Dispatcher<R(P1, P2, P3, P4, P5, P6)> {
static MATE_METHOD(DispatchToCallback) { static MATE_METHOD(DispatchToCallback) {
Arguments args(info); Arguments args(info);
v8::Handle<v8::External> v8_holder; v8::Local<v8::External> v8_holder;
CHECK(args.GetData(&v8_holder)); CHECK(args.GetData(&v8_holder));
CallbackHolderBase* holder_base = reinterpret_cast<CallbackHolderBase*>( CallbackHolderBase* holder_base = reinterpret_cast<CallbackHolderBase*>(
v8_holder->Value()); v8_holder->Value());
@ -517,7 +517,7 @@ template<typename R, typename P1, typename P2, typename P3, typename P4,
struct Dispatcher<R(P1, P2, P3, P4, P5, P6, P7)> { struct Dispatcher<R(P1, P2, P3, P4, P5, P6, P7)> {
static MATE_METHOD(DispatchToCallback) { static MATE_METHOD(DispatchToCallback) {
Arguments args(info); Arguments args(info);
v8::Handle<v8::External> v8_holder; v8::Local<v8::External> v8_holder;
CHECK(args.GetData(&v8_holder)); CHECK(args.GetData(&v8_holder));
CallbackHolderBase* holder_base = reinterpret_cast<CallbackHolderBase*>( CallbackHolderBase* holder_base = reinterpret_cast<CallbackHolderBase*>(
v8_holder->Value()); v8_holder->Value());
@ -567,7 +567,7 @@ v8::Local<v8::FunctionTemplate> CreateFunctionTemplate(
isolate, isolate,
#endif #endif
&internal::Dispatcher<Sig>::DispatchToCallback, &internal::Dispatcher<Sig>::DispatchToCallback,
ConvertToV8<v8::Handle<v8::External> >(isolate, ConvertToV8<v8::Local<v8::External> >(isolate,
holder->GetHandle(isolate))); holder->GetHandle(isolate)));
} }

View file

@ -51,7 +51,7 @@ struct CallbackParamTraits<const T*> {
// among every CallbackHolder instance. // among every CallbackHolder instance.
class CallbackHolderBase { class CallbackHolderBase {
public: public:
v8::Handle<v8::External> GetHandle(v8::Isolate* isolate); v8::Local<v8::External> GetHandle(v8::Isolate* isolate);
protected: protected:
explicit CallbackHolderBase(v8::Isolate* isolate); explicit CallbackHolderBase(v8::Isolate* isolate);
@ -169,7 +169,7 @@ template<typename R$for ARG [[, typename P$(ARG)]]>
struct Dispatcher<R($for ARG , [[P$(ARG)]])> { struct Dispatcher<R($for ARG , [[P$(ARG)]])> {
static MATE_METHOD(DispatchToCallback) { static MATE_METHOD(DispatchToCallback) {
Arguments args(info); Arguments args(info);
v8::Handle<v8::External> v8_holder; v8::Local<v8::External> v8_holder;
CHECK(args.GetData(&v8_holder)); CHECK(args.GetData(&v8_holder));
CallbackHolderBase* holder_base = reinterpret_cast<CallbackHolderBase*>( CallbackHolderBase* holder_base = reinterpret_cast<CallbackHolderBase*>(
v8_holder->Value()); v8_holder->Value());
@ -216,7 +216,7 @@ v8::Local<v8::FunctionTemplate> CreateFunctionTemplate(
isolate, isolate,
#endif #endif
&internal::Dispatcher<Sig>::DispatchToCallback, &internal::Dispatcher<Sig>::DispatchToCallback,
ConvertToV8<v8::Handle<v8::External> >(isolate, ConvertToV8<v8::Local<v8::External> >(isolate,
holder->GetHandle(isolate))); holder->GetHandle(isolate)));
} }

View file

@ -18,7 +18,7 @@ class Handle {
public: public:
Handle() : object_(NULL) {} Handle() : object_(NULL) {}
Handle(v8::Handle<v8::Value> wrapper, T* object) Handle(v8::Local<v8::Value> wrapper, T* object)
: wrapper_(wrapper), : wrapper_(wrapper),
object_(object) { object_(object) {
} }
@ -31,21 +31,21 @@ class Handle {
} }
T* operator->() const { return object_; } T* operator->() const { return object_; }
v8::Handle<v8::Value> ToV8() const { return wrapper_; } v8::Local<v8::Value> ToV8() const { return wrapper_; }
T* get() const { return object_; } T* get() const { return object_; }
private: private:
v8::Handle<v8::Value> wrapper_; v8::Local<v8::Value> wrapper_;
T* object_; T* object_;
}; };
template<typename T> template<typename T>
struct Converter<mate::Handle<T> > { struct Converter<mate::Handle<T> > {
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const mate::Handle<T>& val) { const mate::Handle<T>& val) {
return val.ToV8(); return val.ToV8();
} }
static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val, static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
mate::Handle<T>* out) { mate::Handle<T>* out) {
T* object = NULL; T* object = NULL;
if (!Converter<T*>::FromV8(isolate, val, &object)) { if (!Converter<T*>::FromV8(isolate, val, &object)) {

View file

@ -17,14 +17,14 @@ ObjectTemplateBuilder::~ObjectTemplateBuilder() {
} }
ObjectTemplateBuilder& ObjectTemplateBuilder::SetImpl( ObjectTemplateBuilder& ObjectTemplateBuilder::SetImpl(
const base::StringPiece& name, v8::Handle<v8::Data> val) { const base::StringPiece& name, v8::Local<v8::Data> val) {
template_->Set(StringToSymbol(isolate_, name), val); template_->Set(StringToSymbol(isolate_, name), val);
return *this; return *this;
} }
ObjectTemplateBuilder& ObjectTemplateBuilder::SetPropertyImpl( ObjectTemplateBuilder& ObjectTemplateBuilder::SetPropertyImpl(
const base::StringPiece& name, v8::Handle<v8::FunctionTemplate> getter, const base::StringPiece& name, v8::Local<v8::FunctionTemplate> getter,
v8::Handle<v8::FunctionTemplate> setter) { v8::Local<v8::FunctionTemplate> setter) {
#if NODE_VERSION_AT_LEAST(0, 11, 0) #if NODE_VERSION_AT_LEAST(0, 11, 0)
template_->SetAccessorProperty(StringToSymbol(isolate_, name), getter, template_->SetAccessorProperty(StringToSymbol(isolate_, name), getter,
setter); setter);

View file

@ -22,7 +22,7 @@ namespace {
// because of base::Bind(). // because of base::Bind().
template<typename T, typename Enable = void> template<typename T, typename Enable = void>
struct CallbackTraits { struct CallbackTraits {
static v8::Handle<v8::FunctionTemplate> CreateTemplate(v8::Isolate* isolate, static v8::Local<v8::FunctionTemplate> CreateTemplate(v8::Isolate* isolate,
T callback) { T callback) {
return CreateFunctionTemplate(isolate, base::Bind(callback)); return CreateFunctionTemplate(isolate, base::Bind(callback));
} }
@ -31,7 +31,7 @@ struct CallbackTraits {
// Specialization for base::Callback. // Specialization for base::Callback.
template<typename T> template<typename T>
struct CallbackTraits<base::Callback<T> > { struct CallbackTraits<base::Callback<T> > {
static v8::Handle<v8::FunctionTemplate> CreateTemplate( static v8::Local<v8::FunctionTemplate> CreateTemplate(
v8::Isolate* isolate, const base::Callback<T>& callback) { v8::Isolate* isolate, const base::Callback<T>& callback) {
return CreateFunctionTemplate(isolate, callback); return CreateFunctionTemplate(isolate, callback);
} }
@ -44,7 +44,7 @@ struct CallbackTraits<base::Callback<T> > {
template<typename T> template<typename T>
struct CallbackTraits<T, typename enable_if< struct CallbackTraits<T, typename enable_if<
is_member_function_pointer<T>::value>::type> { is_member_function_pointer<T>::value>::type> {
static v8::Handle<v8::FunctionTemplate> CreateTemplate(v8::Isolate* isolate, static v8::Local<v8::FunctionTemplate> CreateTemplate(v8::Isolate* isolate,
T callback) { T callback) {
return CreateFunctionTemplate(isolate, base::Bind(callback), return CreateFunctionTemplate(isolate, base::Bind(callback),
HolderIsFirstArgument); HolderIsFirstArgument);
@ -54,9 +54,9 @@ struct CallbackTraits<T, typename enable_if<
// This specialization allows people to construct function templates directly if // This specialization allows people to construct function templates directly if
// they need to do fancier stuff. // they need to do fancier stuff.
template<> template<>
struct CallbackTraits<v8::Handle<v8::FunctionTemplate> > { struct CallbackTraits<v8::Local<v8::FunctionTemplate> > {
static v8::Handle<v8::FunctionTemplate> CreateTemplate( static v8::Local<v8::FunctionTemplate> CreateTemplate(
v8::Handle<v8::FunctionTemplate> templ) { v8::Local<v8::FunctionTemplate> templ) {
return templ; return templ;
} }
}; };
@ -109,10 +109,10 @@ class ObjectTemplateBuilder {
private: private:
ObjectTemplateBuilder& SetImpl(const base::StringPiece& name, ObjectTemplateBuilder& SetImpl(const base::StringPiece& name,
v8::Handle<v8::Data> val); v8::Local<v8::Data> val);
ObjectTemplateBuilder& SetPropertyImpl( ObjectTemplateBuilder& SetPropertyImpl(
const base::StringPiece& name, v8::Handle<v8::FunctionTemplate> getter, const base::StringPiece& name, v8::Local<v8::FunctionTemplate> getter,
v8::Handle<v8::FunctionTemplate> setter); v8::Local<v8::FunctionTemplate> setter);
v8::Isolate* isolate_; v8::Isolate* isolate_;

View file

@ -10,7 +10,7 @@ PersistentDictionary::PersistentDictionary() {
} }
PersistentDictionary::PersistentDictionary(v8::Isolate* isolate, PersistentDictionary::PersistentDictionary(v8::Isolate* isolate,
v8::Handle<v8::Object> object) v8::Local<v8::Object> object)
: handle_(new RefCountedPersistent<v8::Object>(isolate, object)) { : handle_(new RefCountedPersistent<v8::Object>(isolate, object)) {
isolate_ = isolate; isolate_ = isolate;
} }
@ -18,16 +18,16 @@ PersistentDictionary::PersistentDictionary(v8::Isolate* isolate,
PersistentDictionary::~PersistentDictionary() { PersistentDictionary::~PersistentDictionary() {
} }
v8::Handle<v8::Object> PersistentDictionary::GetHandle() const { v8::Local<v8::Object> PersistentDictionary::GetHandle() const {
return handle_->NewHandle(); return handle_->NewHandle();
} }
bool Converter<PersistentDictionary>::FromV8(v8::Isolate* isolate, bool Converter<PersistentDictionary>::FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val, v8::Local<v8::Value> val,
PersistentDictionary* out) { PersistentDictionary* out) {
if (!val->IsObject()) if (!val->IsObject())
return false; return false;
*out = PersistentDictionary(isolate, v8::Handle<v8::Object>::Cast(val)); *out = PersistentDictionary(isolate, v8::Local<v8::Object>::Cast(val));
return true; return true;
} }

View file

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

View file

@ -18,16 +18,16 @@ class ScopedPersistent {
public: public:
ScopedPersistent() : isolate_(v8::Isolate::GetCurrent()) {} ScopedPersistent() : isolate_(v8::Isolate::GetCurrent()) {}
ScopedPersistent(v8::Isolate* isolate, v8::Handle<v8::Value> handle) ScopedPersistent(v8::Isolate* isolate, v8::Local<v8::Value> handle)
: isolate_(isolate) { : isolate_(isolate) {
reset(isolate, v8::Handle<T>::Cast(handle)); reset(isolate, v8::Local<T>::Cast(handle));
} }
~ScopedPersistent() { ~ScopedPersistent() {
reset(); reset();
} }
void reset(v8::Isolate* isolate, v8::Handle<T> handle) { void reset(v8::Isolate* isolate, v8::Local<T> handle) {
if (!handle.IsEmpty()) { if (!handle.IsEmpty()) {
isolate_ = isolate; isolate_ = isolate;
MATE_PERSISTENT_ASSIGN(T, isolate, handle_, handle); MATE_PERSISTENT_ASSIGN(T, isolate, handle_, handle);
@ -44,11 +44,11 @@ class ScopedPersistent {
return handle_.IsEmpty(); return handle_.IsEmpty();
} }
v8::Handle<T> NewHandle() const { v8::Local<T> NewHandle() const {
return NewHandle(isolate_); return NewHandle(isolate_);
} }
v8::Handle<T> NewHandle(v8::Isolate* isolate) const { v8::Local<T> NewHandle(v8::Isolate* isolate) const {
if (handle_.IsEmpty()) if (handle_.IsEmpty())
return v8::Local<T>(); return v8::Local<T>();
return MATE_PERSISTENT_TO_LOCAL(T, isolate, handle_); return MATE_PERSISTENT_TO_LOCAL(T, isolate, handle_);
@ -74,7 +74,7 @@ class RefCountedPersistent : public ScopedPersistent<T>,
public: public:
RefCountedPersistent() {} RefCountedPersistent() {}
RefCountedPersistent(v8::Isolate* isolate, v8::Handle<v8::Value> handle) RefCountedPersistent(v8::Isolate* isolate, v8::Local<v8::Value> handle)
: ScopedPersistent<T>(isolate, handle) { : ScopedPersistent<T>(isolate, handle) {
} }
@ -89,16 +89,16 @@ class RefCountedPersistent : public ScopedPersistent<T>,
template<typename T> template<typename T>
struct Converter<ScopedPersistent<T> > { struct Converter<ScopedPersistent<T> > {
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const ScopedPersistent<T>& val) { const ScopedPersistent<T>& val) {
return val.NewHandle(isolate); return val.NewHandle(isolate);
} }
static bool FromV8(v8::Isolate* isolate, static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val, v8::Local<v8::Value> val,
ScopedPersistent<T>* out) { ScopedPersistent<T>* out) {
v8::Handle<T> converted; v8::Local<T> converted;
if (!Converter<v8::Handle<T> >::FromV8(isolate, val, &converted)) if (!Converter<v8::Local<T> >::FromV8(isolate, val, &converted))
return false; return false;
out->reset(isolate, converted); out->reset(isolate, converted);

View file

@ -26,17 +26,17 @@ std::string TryCatch::GetStackTrace() {
} }
std::stringstream ss; std::stringstream ss;
v8::Handle<v8::Message> message = try_catch_.Message(); v8::Local<v8::Message> message = try_catch_.Message();
ss << V8ToString(message->Get()) << std::endl ss << V8ToString(message->Get()) << std::endl
<< V8ToString(message->GetSourceLine()) << std::endl; << V8ToString(message->GetSourceLine()) << std::endl;
v8::Handle<v8::StackTrace> trace = message->GetStackTrace(); v8::Local<v8::StackTrace> trace = message->GetStackTrace();
if (trace.IsEmpty()) if (trace.IsEmpty())
return ss.str(); return ss.str();
int len = trace->GetFrameCount(); int len = trace->GetFrameCount();
for (int i = 0; i < len; ++i) { for (int i = 0; i < len; ++i) {
v8::Handle<v8::StackFrame> frame = trace->GetFrame(i); v8::Local<v8::StackFrame> frame = trace->GetFrame(i);
ss << V8ToString(frame->GetScriptName()) << ":" ss << V8ToString(frame->GetScriptName()) << ":"
<< frame->GetLineNumber() << ":" << frame->GetLineNumber() << ":"
<< frame->GetColumn() << ": " << frame->GetColumn() << ": "

View file

@ -17,7 +17,7 @@ Wrappable::~Wrappable() {
MATE_PERSISTENT_RESET(wrapper_); MATE_PERSISTENT_RESET(wrapper_);
} }
void Wrappable::Wrap(v8::Isolate* isolate, v8::Handle<v8::Object> wrapper) { void Wrappable::Wrap(v8::Isolate* isolate, v8::Local<v8::Object> wrapper) {
if (!wrapper_.IsEmpty()) if (!wrapper_.IsEmpty())
return; return;
@ -26,7 +26,7 @@ void Wrappable::Wrap(v8::Isolate* isolate, v8::Handle<v8::Object> wrapper) {
MATE_PERSISTENT_SET_WEAK(wrapper_, this, WeakCallback); MATE_PERSISTENT_SET_WEAK(wrapper_, this, WeakCallback);
// Call object._init if we have one. // Call object._init if we have one.
v8::Handle<v8::Function> init; v8::Local<v8::Function> init;
if (Dictionary(isolate, wrapper).Get("_init", &init)) if (Dictionary(isolate, wrapper).Get("_init", &init))
init->Call(wrapper, 0, NULL); init->Call(wrapper, 0, NULL);
@ -35,7 +35,7 @@ void Wrappable::Wrap(v8::Isolate* isolate, v8::Handle<v8::Object> wrapper) {
// static // static
void Wrappable::BuildPrototype(v8::Isolate* isolate, void Wrappable::BuildPrototype(v8::Isolate* isolate,
v8::Handle<v8::ObjectTemplate> prototype) { v8::Local<v8::ObjectTemplate> prototype) {
} }
ObjectTemplateBuilder Wrappable::GetObjectTemplateBuilder( ObjectTemplateBuilder Wrappable::GetObjectTemplateBuilder(
@ -49,7 +49,7 @@ MATE_WEAK_CALLBACK(Wrappable::WeakCallback, v8::Object, Wrappable) {
delete self; delete self;
} }
v8::Handle<v8::Object> Wrappable::GetWrapper(v8::Isolate* isolate) { v8::Local<v8::Object> Wrappable::GetWrapper(v8::Isolate* isolate) {
if (!wrapper_.IsEmpty()) if (!wrapper_.IsEmpty())
return MATE_PERSISTENT_TO_LOCAL(v8::Object, isolate, wrapper_); return MATE_PERSISTENT_TO_LOCAL(v8::Object, isolate, wrapper_);
@ -57,17 +57,17 @@ v8::Handle<v8::Object> Wrappable::GetWrapper(v8::Isolate* isolate) {
GetObjectTemplateBuilder(isolate).Build(); GetObjectTemplateBuilder(isolate).Build();
CHECK(!templ.IsEmpty()); CHECK(!templ.IsEmpty());
CHECK_EQ(1, templ->InternalFieldCount()); CHECK_EQ(1, templ->InternalFieldCount());
v8::Handle<v8::Object> wrapper = templ->NewInstance(); v8::Local<v8::Object> wrapper = templ->NewInstance();
Wrap(isolate, wrapper); Wrap(isolate, wrapper);
return wrapper; return wrapper;
} }
namespace internal { namespace internal {
void* FromV8Impl(v8::Isolate* isolate, v8::Handle<v8::Value> val) { void* FromV8Impl(v8::Isolate* isolate, v8::Local<v8::Value> val) {
if (!val->IsObject()) if (!val->IsObject())
return NULL; return NULL;
v8::Handle<v8::Object> obj = v8::Handle<v8::Object>::Cast(val); v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(val);
if (obj->InternalFieldCount() != 1) if (obj->InternalFieldCount() != 1)
return NULL; return NULL;
return MATE_GET_INTERNAL_FIELD_POINTER(obj, 0); return MATE_GET_INTERNAL_FIELD_POINTER(obj, 0);

View file

@ -13,7 +13,7 @@ namespace mate {
namespace internal { namespace internal {
void* FromV8Impl(v8::Isolate* isolate, v8::Handle<v8::Value> val); void* FromV8Impl(v8::Isolate* isolate, v8::Local<v8::Value> val);
} // namespace internal } // namespace internal
@ -52,15 +52,15 @@ class Wrappable {
// If the type is created via the Constructor, then the GetWrapper would // If the type is created via the Constructor, then the GetWrapper would
// return the constructed object, otherwise it would try to create a new // return the constructed object, otherwise it would try to create a new
// object constructed by GetObjectTemplateBuilder. // object constructed by GetObjectTemplateBuilder.
v8::Handle<v8::Object> GetWrapper(v8::Isolate* isolate); v8::Local<v8::Object> GetWrapper(v8::Isolate* isolate);
// Bind the C++ class to the JS wrapper. // Bind the C++ class to the JS wrapper.
void Wrap(v8::Isolate* isolate, v8::Handle<v8::Object> wrapper); void Wrap(v8::Isolate* isolate, v8::Local<v8::Object> wrapper);
// The user should define T::BuildPrototype if they want to use Constructor // The user should define T::BuildPrototype if they want to use Constructor
// to build a constructor function for this type. // to build a constructor function for this type.
static void BuildPrototype(v8::Isolate* isolate, static void BuildPrototype(v8::Isolate* isolate,
v8::Handle<v8::ObjectTemplate> prototype); v8::Local<v8::ObjectTemplate> prototype);
protected: protected:
Wrappable(); Wrappable();
@ -84,11 +84,11 @@ class Wrappable {
template<typename T> template<typename T>
struct Converter<T*, typename enable_if< struct Converter<T*, typename enable_if<
is_convertible<T*, Wrappable*>::value>::type> { is_convertible<T*, Wrappable*>::value>::type> {
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, T* val) { static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, T* val) {
return val->GetWrapper(isolate); return val->GetWrapper(isolate);
} }
static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val, T** out) { static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val, T** out) {
*out = static_cast<T*>(static_cast<Wrappable*>( *out = static_cast<T*>(static_cast<Wrappable*>(
internal::FromV8Impl(isolate, val))); internal::FromV8Impl(isolate, val)));
return *out != NULL; return *out != NULL;