Add APIs to match new V8 APIs.

This commit is contained in:
Cheng Zhao 2014-06-28 19:29:14 +08:00
parent a5c4a2c7c6
commit 6f574c3802
3 changed files with 23 additions and 8 deletions

View file

@ -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) \

View file

@ -9,6 +9,7 @@
#include <vector>
#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<void*> {
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, void* val) {
return v8::Undefined();
return MATE_UNDEFINED(isolate);
}
};
@ -157,7 +158,7 @@ struct Converter<std::vector<T> > {
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
const std::vector<T>& val) {
v8::Handle<v8::Array> result(
v8::Array::New(static_cast<int>(val.size())));
MATE_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]));
}

View file

@ -53,12 +53,6 @@ class ScopedPersistent {
return v8::Local<T>::New(isolate, handle_);
}
template <typename P>
void MakeWeak(P* parameters,
typename v8::WeakReferenceCallbacks<T, P>::Revivable callback) {
handle_.MakeWeak(parameters, callback);
}
private:
template <typename U>
static v8::Isolate* GetIsolate(v8::Handle<U> object_handle) {