From 6f574c38020bdf9d6ed9dd079905f4b110fbd10e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 28 Jun 2014 19:29:14 +0800 Subject: [PATCH] Add APIs to match new V8 APIs. --- native_mate/compat.h | 20 ++++++++++++++++++++ native_mate/converter.h | 5 +++-- native_mate/scoped_persistent.h | 6 ------ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/native_mate/compat.h b/native_mate/compat.h index 5641613c42e..11a7ef40963 100644 --- a/native_mate/compat.h +++ b/native_mate/compat.h @@ -19,11 +19,21 @@ #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_INTEGER_NEW(isolate, data) v8::Integer::New(isolate, data) + #define MATE_SET_INTERNAL_FIELD_POINTER(object, index, value) \ object->SetAlignedPointerInInternalField(index, value) #define MATE_GET_INTERNAL_FIELD_POINTER(object, index) \ @@ -58,11 +68,21 @@ #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_INTEGER_NEW(isolate, data) v8::Integer::New(data) + #define MATE_SET_INTERNAL_FIELD_POINTER(object, index, value) \ object->SetPointerInInternalField(index, value) #define MATE_GET_INTERNAL_FIELD_POINTER(object, index) \ diff --git a/native_mate/converter.h b/native_mate/converter.h index a94d8defbd6..c17e892c2b0 100644 --- a/native_mate/converter.h +++ b/native_mate/converter.h @@ -9,6 +9,7 @@ #include #include "base/strings/string_piece.h" +#include "native_mate/compat.h" #include "v8/include/v8.h" namespace mate { @@ -19,7 +20,7 @@ struct Converter {}; template<> struct Converter { static v8::Handle ToV8(v8::Isolate* isolate, void* val) { - return v8::Undefined(); + return MATE_UNDEFINED(isolate); } }; @@ -157,7 +158,7 @@ struct Converter > { static v8::Handle ToV8(v8::Isolate* isolate, const std::vector& val) { v8::Handle result( - v8::Array::New(static_cast(val.size()))); + MATE_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])); } diff --git a/native_mate/scoped_persistent.h b/native_mate/scoped_persistent.h index 37c2e0a281f..d2a8bd7fca6 100644 --- a/native_mate/scoped_persistent.h +++ b/native_mate/scoped_persistent.h @@ -53,12 +53,6 @@ class ScopedPersistent { return v8::Local::New(isolate, handle_); } - template - void MakeWeak(P* parameters, - typename v8::WeakReferenceCallbacks::Revivable callback) { - handle_.MakeWeak(parameters, callback); - } - private: template static v8::Isolate* GetIsolate(v8::Handle object_handle) {