diff --git a/src/node/ext/byte_buffer.cc b/src/node/ext/byte_buffer.cc index c165d26e47e..5235c8e083d 100644 --- a/src/node/ext/byte_buffer.cc +++ b/src/node/ext/byte_buffer.cc @@ -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 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 buffer) { Handle ByteBufferToBuffer(grpc_byte_buffer *buffer) { NanEscapableScope(); if (buffer == NULL) { - NanReturnNull(); + return NanNull(); } size_t length = grpc_byte_buffer_length(buffer); char *result = reinterpret_cast(calloc(length, sizeof(char))); @@ -82,12 +81,14 @@ Handle ByteBufferToBuffer(grpc_byte_buffer *buffer) { Handle MakeFastBuffer(Handle slowBuffer) { NanEscapableScope(); - Handle globalObj = Context::GetCurrent()->Global(); + Handle globalObj = NanGetCurrentContext()->Global(); Handle bufferConstructor = Handle::Cast( globalObj->Get(NanNew("Buffer"))); - Handle consArgs[3] = { slowBuffer, - NanNew(Buffer::Length(slowBuffer)), - NanNew(0) }; + Handle consArgs[3] = { + slowBuffer, + NanNew(::node::Buffer::Length(slowBuffer)), + NanNew(0) + }; Handle fastBuffer = bufferConstructor->NewInstance(3, consArgs); return NanEscapeScope(fastBuffer); } diff --git a/src/node/ext/call.cc b/src/node/ext/call.cc index 9ed389f3bc5..1d85abb1d28 100644 --- a/src/node/ext/call.cc +++ b/src/node/ext/call.cc @@ -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 Call::constructor; +NanCallback *Call::constructor; Persistent Call::fun_tpl; @@ -101,9 +99,9 @@ bool CreateMetadataArray(Handle metadata, grpc_metadata_array *array, Handle 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 handle; NanAssignPersistent(handle, value); resources->handles.push_back(unique_ptr( @@ -140,7 +138,7 @@ Handle ParseMetadata(const grpc_metadata_array *metadata_array) { Handle metadata_object = NanNew(); for (unsigned int i = 0; i < length; i++) { grpc_metadata* elem = &metadata_elements[i]; - Handle key_string = String::New(elem->key); + Handle key_string = NanNew(elem->key); Handle array; if (metadata_object->Has(key_string)) { array = Handle::Cast(metadata_object->Get(key_string)); @@ -194,7 +192,7 @@ class SendMessageOp : public Op { } bool ParseOp(Handle value, grpc_op *out, shared_ptr 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 status_obj = NanNew(); status_obj->Set(NanNew("code"), NanNew(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 exports) { NanScope(); - Local tpl = FunctionTemplate::New(New); + Local tpl = NanNew(New); tpl->SetClassName(NanNew("Call")); tpl->InstanceTemplate()->SetInternalFieldCount(1); NanSetPrototypeTemplate(tpl, "startBatch", - FunctionTemplate::New(StartBatch)->GetFunction()); + NanNew(StartBatch)->GetFunction()); NanSetPrototypeTemplate(tpl, "cancel", - FunctionTemplate::New(Cancel)->GetFunction()); + NanNew(Cancel)->GetFunction()); NanAssignPersistent(fun_tpl, tpl); - NanAssignPersistent(constructor, tpl->GetFunction()); - constructor->Set(NanNew("WRITE_BUFFER_HINT"), - NanNew(GRPC_WRITE_BUFFER_HINT)); - constructor->Set(NanNew("WRITE_NO_COMPRESS"), - NanNew(GRPC_WRITE_NO_COMPRESS)); - exports->Set(String::NewSymbol("Call"), constructor); + Handle ctr = tpl->GetFunction(); + ctr->Set(NanNew("WRITE_BUFFER_HINT"), + NanNew(GRPC_WRITE_BUFFER_HINT)); + ctr->Set(NanNew("WRITE_NO_COMPRESS"), + NanNew(GRPC_WRITE_NO_COMPRESS)); + exports->Set(NanNew("Call"), ctr); + constructor = new NanCallback(ctr); } bool Call::HasInstance(Handle val) { @@ -463,8 +462,8 @@ Handle Call::WrapStruct(grpc_call *call) { return NanEscapeScope(NanNull()); } const int argc = 1; - Handle argv[argc] = {External::New(reinterpret_cast(call))}; - return NanEscapeScope(constructor->NewInstance(argc, argv)); + Handle argv[argc] = {NanNew(reinterpret_cast(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 ext = args[0].As(); // This option is used for wrapping an existing call grpc_call *call_value = - reinterpret_cast(External::Unwrap(args[0])); + reinterpret_cast(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 argv[argc] = {args[0], args[1], args[2], args[3]}; - NanReturnValue(constructor->NewInstance(argc, argv)); + NanReturnValue(constructor->GetFunction()->NewInstance(argc, argv)); } } diff --git a/src/node/ext/call.h b/src/node/ext/call.h index 933541ce5b6..2e9e1c5bf37 100644 --- a/src/node/ext/call.h +++ b/src/node/ext/call.h @@ -118,7 +118,7 @@ class Call : public ::node::ObjectWrap { static NAN_METHOD(New); static NAN_METHOD(StartBatch); static NAN_METHOD(Cancel); - static v8::Persistent constructor; + static NanCallback *constructor; // Used for typechecking instances of this javascript class static v8::Persistent fun_tpl;