Updated some c++ files for 0.11/0.12 compatibility

pull/952/head
murgatroid99 10 years ago
parent 3a98218282
commit 5f875d2986
  1. 17
      src/node/ext/byte_buffer.cc
  2. 43
      src/node/ext/call.cc
  3. 2
      src/node/ext/call.h

@ -44,7 +44,6 @@
namespace grpc {
namespace node {
using ::node::Buffer;
using v8::Context;
using v8::Function;
using v8::Handle;
@ -54,8 +53,8 @@ using v8::Value;
grpc_byte_buffer *BufferToByteBuffer(Handle<Value> buffer) {
NanScope();
int length = Buffer::Length(buffer);
char *data = Buffer::Data(buffer);
int length = ::node::Buffer::Length(buffer);
char *data = ::node::Buffer::Data(buffer);
gpr_slice slice = gpr_slice_malloc(length);
memcpy(GPR_SLICE_START_PTR(slice), data, length);
grpc_byte_buffer *byte_buffer(grpc_byte_buffer_create(&slice, 1));
@ -66,7 +65,7 @@ grpc_byte_buffer *BufferToByteBuffer(Handle<Value> buffer) {
Handle<Value> ByteBufferToBuffer(grpc_byte_buffer *buffer) {
NanEscapableScope();
if (buffer == NULL) {
NanReturnNull();
return NanNull();
}
size_t length = grpc_byte_buffer_length(buffer);
char *result = reinterpret_cast<char *>(calloc(length, sizeof(char)));
@ -82,12 +81,14 @@ Handle<Value> ByteBufferToBuffer(grpc_byte_buffer *buffer) {
Handle<Value> MakeFastBuffer(Handle<Value> slowBuffer) {
NanEscapableScope();
Handle<Object> globalObj = Context::GetCurrent()->Global();
Handle<Object> globalObj = NanGetCurrentContext()->Global();
Handle<Function> bufferConstructor = Handle<Function>::Cast(
globalObj->Get(NanNew("Buffer")));
Handle<Value> consArgs[3] = { slowBuffer,
NanNew<Number>(Buffer::Length(slowBuffer)),
NanNew<Number>(0) };
Handle<Value> consArgs[3] = {
slowBuffer,
NanNew<Number>(::node::Buffer::Length(slowBuffer)),
NanNew<Number>(0)
};
Handle<Object> fastBuffer = bufferConstructor->NewInstance(3, consArgs);
return NanEscapeScope(fastBuffer);
}

@ -54,8 +54,6 @@ using std::vector;
namespace grpc {
namespace node {
using ::node::Buffer;
using v8::Arguments;
using v8::Array;
using v8::Boolean;
using v8::Exception;
@ -74,7 +72,7 @@ using v8::Uint32;
using v8::String;
using v8::Value;
Persistent<Function> Call::constructor;
NanCallback *Call::constructor;
Persistent<FunctionTemplate> Call::fun_tpl;
@ -101,9 +99,9 @@ bool CreateMetadataArray(Handle<Object> metadata, grpc_metadata_array *array,
Handle<Value> value = values->Get(j);
grpc_metadata *current = &array->metadata[array->count];
current->key = **utf8_key;
if (Buffer::HasInstance(value)) {
current->value = Buffer::Data(value);
current->value_length = Buffer::Length(value);
if (::node::Buffer::HasInstance(value)) {
current->value = ::node::Buffer::Data(value);
current->value_length = ::node::Buffer::Length(value);
Persistent<Value> handle;
NanAssignPersistent(handle, value);
resources->handles.push_back(unique_ptr<PersistentHolder>(
@ -140,7 +138,7 @@ Handle<Value> ParseMetadata(const grpc_metadata_array *metadata_array) {
Handle<Object> metadata_object = NanNew<Object>();
for (unsigned int i = 0; i < length; i++) {
grpc_metadata* elem = &metadata_elements[i];
Handle<String> key_string = String::New(elem->key);
Handle<String> key_string = NanNew(elem->key);
Handle<Array> array;
if (metadata_object->Has(key_string)) {
array = Handle<Array>::Cast(metadata_object->Get(key_string));
@ -194,7 +192,7 @@ class SendMessageOp : public Op {
}
bool ParseOp(Handle<Value> value, grpc_op *out,
shared_ptr<Resources> resources) {
if (!Buffer::HasInstance(value)) {
if (!::node::Buffer::HasInstance(value)) {
return false;
}
out->data.send_message = BufferToByteBuffer(value);
@ -357,7 +355,7 @@ class ClientStatusOp : public Op {
Handle<Object> status_obj = NanNew<Object>();
status_obj->Set(NanNew("code"), NanNew<Number>(status));
if (status_details != NULL) {
status_obj->Set(NanNew("details"), String::New(status_details));
status_obj->Set(NanNew("details"), NanNew(status_details));
}
status_obj->Set(NanNew("metadata"), ParseMetadata(&metadata_array));
return NanEscapeScope(status_obj);
@ -436,20 +434,21 @@ Call::~Call() {
void Call::Init(Handle<Object> exports) {
NanScope();
Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
Local<FunctionTemplate> tpl = NanNew<FunctionTemplate>(New);
tpl->SetClassName(NanNew("Call"));
tpl->InstanceTemplate()->SetInternalFieldCount(1);
NanSetPrototypeTemplate(tpl, "startBatch",
FunctionTemplate::New(StartBatch)->GetFunction());
NanNew<FunctionTemplate>(StartBatch)->GetFunction());
NanSetPrototypeTemplate(tpl, "cancel",
FunctionTemplate::New(Cancel)->GetFunction());
NanNew<FunctionTemplate>(Cancel)->GetFunction());
NanAssignPersistent(fun_tpl, tpl);
NanAssignPersistent(constructor, tpl->GetFunction());
constructor->Set(NanNew("WRITE_BUFFER_HINT"),
Handle<Function> ctr = tpl->GetFunction();
ctr->Set(NanNew("WRITE_BUFFER_HINT"),
NanNew<Uint32, uint32_t>(GRPC_WRITE_BUFFER_HINT));
constructor->Set(NanNew("WRITE_NO_COMPRESS"),
ctr->Set(NanNew("WRITE_NO_COMPRESS"),
NanNew<Uint32, uint32_t>(GRPC_WRITE_NO_COMPRESS));
exports->Set(String::NewSymbol("Call"), constructor);
exports->Set(NanNew("Call"), ctr);
constructor = new NanCallback(ctr);
}
bool Call::HasInstance(Handle<Value> val) {
@ -463,8 +462,8 @@ Handle<Value> Call::WrapStruct(grpc_call *call) {
return NanEscapeScope(NanNull());
}
const int argc = 1;
Handle<Value> argv[argc] = {External::New(reinterpret_cast<void *>(call))};
return NanEscapeScope(constructor->NewInstance(argc, argv));
Handle<Value> argv[argc] = {NanNew<External>(reinterpret_cast<void *>(call))};
return NanEscapeScope(constructor->GetFunction()->NewInstance(argc, argv));
}
NAN_METHOD(Call::New) {
@ -473,9 +472,10 @@ NAN_METHOD(Call::New) {
if (args.IsConstructCall()) {
Call *call;
if (args[0]->IsExternal()) {
Handle<External> ext = args[0].As<External>();
// This option is used for wrapping an existing call
grpc_call *call_value =
reinterpret_cast<grpc_call *>(External::Unwrap(args[0]));
reinterpret_cast<grpc_call *>(ext->Value());
call = new Call(call_value);
} else {
if (!Channel::HasInstance(args[0])) {
@ -500,15 +500,14 @@ NAN_METHOD(Call::New) {
wrapped_channel, CompletionQueueAsyncWorker::GetQueue(), *method,
channel->GetHost(), MillisecondsToTimespec(deadline));
call = new Call(wrapped_call);
args.This()->SetHiddenValue(String::NewSymbol("channel_"),
channel_object);
args.This()->SetHiddenValue(NanNew("channel_"), channel_object);
}
call->Wrap(args.This());
NanReturnValue(args.This());
} else {
const int argc = 4;
Local<Value> argv[argc] = {args[0], args[1], args[2], args[3]};
NanReturnValue(constructor->NewInstance(argc, argv));
NanReturnValue(constructor->GetFunction()->NewInstance(argc, argv));
}
}

@ -118,7 +118,7 @@ class Call : public ::node::ObjectWrap {
static NAN_METHOD(New);
static NAN_METHOD(StartBatch);
static NAN_METHOD(Cancel);
static v8::Persistent<v8::Function> constructor;
static NanCallback *constructor;
// Used for typechecking instances of this javascript class
static v8::Persistent<v8::FunctionTemplate> fun_tpl;

Loading…
Cancel
Save