From e3eab63868589a690b43a797947e87e196670cb4 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Wed, 4 Mar 2015 11:28:06 -0800 Subject: [PATCH 1/4] Loosened some dependencies, specified compatible engines --- package.json | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 0ef1c990..13606956 100644 --- a/package.json +++ b/package.json @@ -24,20 +24,23 @@ "test": "node ./node_modules/mocha/bin/mocha && npm run-script lint" }, "dependencies": { - "bindings": "^1.2.1", - "jshint": "^2.5.5", - "nan": "~1.3.0", + "bindings": "^1.2.0", + "nan": "^1.5.0", "protobufjs": "murgatroid99/ProtoBuf.js", - "underscore": "^1.7.0", + "underscore": "^1.6.0", "underscore.string": "^3.0.0" }, "devDependencies": { "async": "^0.9.0", "google-auth-library": "^0.9.2", + "jshint": "^2.5.0", "minimist": "^1.1.0", "mocha": "~1.21.0", "strftime": "^0.8.2" }, + "engines": { + "node": ">=0.10.13 <0.11" + }, "files": [ "LICENSE", "README.md", From 820ff875c7cd20b759f9d669a25c0ab42ba5780f Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Wed, 4 Mar 2015 11:28:37 -0800 Subject: [PATCH 2/4] Updated some c++ files for 0.11/0.12 compatibility --- ext/byte_buffer.cc | 17 +++++++++-------- ext/call.cc | 47 +++++++++++++++++++++++----------------------- ext/call.h | 2 +- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/ext/byte_buffer.cc b/ext/byte_buffer.cc index c165d26e..5235c8e0 100644 --- a/ext/byte_buffer.cc +++ b/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/ext/call.cc b/ext/call.cc index 9ed389f3..1d85abb1 100644 --- a/ext/call.cc +++ b/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/ext/call.h b/ext/call.h index 933541ce..2e9e1c5b 100644 --- a/ext/call.h +++ b/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; From 1008c5a7302cc785f946ac6f793d0bf35bf845fc Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Wed, 4 Mar 2015 14:42:31 -0800 Subject: [PATCH 3/4] The library now compiles with Node 0.11+ and all versions of io.js --- ext/call.cc | 8 +++--- ext/call.h | 8 +++--- ext/channel.cc | 14 +++++----- ext/channel.h | 2 +- ext/credentials.cc | 56 +++++++++++++++++++-------------------- ext/credentials.h | 2 +- ext/node_grpc.cc | 6 ++--- ext/server.cc | 27 ++++++++++--------- ext/server.h | 2 +- ext/server_credentials.cc | 40 ++++++++++++++-------------- ext/server_credentials.h | 2 +- 11 files changed, 85 insertions(+), 82 deletions(-) diff --git a/ext/call.cc b/ext/call.cc index 1d85abb1..afb65417 100644 --- a/ext/call.cc +++ b/ext/call.cc @@ -102,8 +102,8 @@ bool CreateMetadataArray(Handle metadata, grpc_metadata_array *array, if (::node::Buffer::HasInstance(value)) { current->value = ::node::Buffer::Data(value); current->value_length = ::node::Buffer::Length(value); - Persistent handle; - NanAssignPersistent(handle, value); + Persistent *handle = new Persistent(); + NanAssignPersistent(*handle, value); resources->handles.push_back(unique_ptr( new PersistentHolder(handle))); } else if (value->IsString()) { @@ -196,8 +196,8 @@ class SendMessageOp : public Op { return false; } out->data.send_message = BufferToByteBuffer(value); - Persistent handle; - NanAssignPersistent(handle, value); + Persistent *handle = new Persistent(); + NanAssignPersistent(*handle, value); resources->handles.push_back(unique_ptr( new PersistentHolder(handle))); return true; diff --git a/ext/call.h b/ext/call.h index 2e9e1c5b..43142c70 100644 --- a/ext/call.h +++ b/ext/call.h @@ -40,6 +40,7 @@ #include #include #include "grpc/grpc.h" +#include "grpc/support/log.h" #include "channel.h" @@ -54,16 +55,17 @@ v8::Handle ParseMetadata(const grpc_metadata_array *metadata_array); class PersistentHolder { public: - explicit PersistentHolder(v8::Persistent persist) : + explicit PersistentHolder(v8::Persistent *persist) : persist(persist) { } ~PersistentHolder() { - NanDisposePersistent(persist); + NanDisposePersistent(*persist); + delete persist; } private: - v8::Persistent persist; + v8::Persistent *persist; }; struct Resources { diff --git a/ext/channel.cc b/ext/channel.cc index bc9461d7..787e2749 100644 --- a/ext/channel.cc +++ b/ext/channel.cc @@ -45,7 +45,6 @@ namespace grpc { namespace node { -using v8::Arguments; using v8::Array; using v8::Exception; using v8::Function; @@ -59,7 +58,7 @@ using v8::Persistent; using v8::String; using v8::Value; -Persistent Channel::constructor; +NanCallback *Channel::constructor; Persistent Channel::fun_tpl; Channel::Channel(grpc_channel *channel, NanUtf8String *host) @@ -74,14 +73,15 @@ Channel::~Channel() { void Channel::Init(Handle exports) { NanScope(); - Local tpl = FunctionTemplate::New(New); + Local tpl = NanNew(New); tpl->SetClassName(NanNew("Channel")); tpl->InstanceTemplate()->SetInternalFieldCount(1); NanSetPrototypeTemplate(tpl, "close", - FunctionTemplate::New(Close)->GetFunction()); + NanNew(Close)->GetFunction()); NanAssignPersistent(fun_tpl, tpl); - NanAssignPersistent(constructor, tpl->GetFunction()); - exports->Set(NanNew("Channel"), constructor); + Handle ctr = tpl->GetFunction(); + constructor = new NanCallback(ctr); + exports->Set(NanNew("Channel"), ctr); } bool Channel::HasInstance(Handle val) { @@ -170,7 +170,7 @@ NAN_METHOD(Channel::New) { } else { const int argc = 2; Local argv[argc] = {args[0], args[1]}; - NanReturnValue(constructor->NewInstance(argc, argv)); + NanReturnValue(constructor->GetFunction()->NewInstance(argc, argv)); } } diff --git a/ext/channel.h b/ext/channel.h index bf793194..b3aa0f70 100644 --- a/ext/channel.h +++ b/ext/channel.h @@ -66,7 +66,7 @@ class Channel : public ::node::ObjectWrap { static NAN_METHOD(New); static NAN_METHOD(Close); - static v8::Persistent constructor; + static NanCallback *constructor; static v8::Persistent fun_tpl; grpc_channel *wrapped_channel; diff --git a/ext/credentials.cc b/ext/credentials.cc index 3f65d59c..34872017 100644 --- a/ext/credentials.cc +++ b/ext/credentials.cc @@ -41,8 +41,6 @@ namespace grpc { namespace node { -using ::node::Buffer; -using v8::Arguments; using v8::Exception; using v8::External; using v8::Function; @@ -56,7 +54,7 @@ using v8::ObjectTemplate; using v8::Persistent; using v8::Value; -Persistent Credentials::constructor; +NanCallback *Credentials::constructor; Persistent Credentials::fun_tpl; Credentials::Credentials(grpc_credentials *credentials) @@ -68,24 +66,25 @@ Credentials::~Credentials() { void Credentials::Init(Handle exports) { NanScope(); - Local tpl = FunctionTemplate::New(New); + Local tpl = NanNew(New); tpl->SetClassName(NanNew("Credentials")); tpl->InstanceTemplate()->SetInternalFieldCount(1); NanAssignPersistent(fun_tpl, tpl); - NanAssignPersistent(constructor, tpl->GetFunction()); - constructor->Set(NanNew("createDefault"), - FunctionTemplate::New(CreateDefault)->GetFunction()); - constructor->Set(NanNew("createSsl"), - FunctionTemplate::New(CreateSsl)->GetFunction()); - constructor->Set(NanNew("createComposite"), - FunctionTemplate::New(CreateComposite)->GetFunction()); - constructor->Set(NanNew("createGce"), - FunctionTemplate::New(CreateGce)->GetFunction()); - constructor->Set(NanNew("createFake"), - FunctionTemplate::New(CreateFake)->GetFunction()); - constructor->Set(NanNew("createIam"), - FunctionTemplate::New(CreateIam)->GetFunction()); - exports->Set(NanNew("Credentials"), constructor); + Handle ctr = tpl->GetFunction(); + ctr->Set(NanNew("createDefault"), + NanNew(CreateDefault)->GetFunction()); + ctr->Set(NanNew("createSsl"), + NanNew(CreateSsl)->GetFunction()); + ctr->Set(NanNew("createComposite"), + NanNew(CreateComposite)->GetFunction()); + ctr->Set(NanNew("createGce"), + NanNew(CreateGce)->GetFunction()); + ctr->Set(NanNew("createFake"), + NanNew(CreateFake)->GetFunction()); + ctr->Set(NanNew("createIam"), + NanNew(CreateIam)->GetFunction()); + constructor = new NanCallback(ctr); + exports->Set(NanNew("Credentials"), ctr); } bool Credentials::HasInstance(Handle val) { @@ -100,8 +99,8 @@ Handle Credentials::WrapStruct(grpc_credentials *credentials) { } const int argc = 1; Handle argv[argc] = { - External::New(reinterpret_cast(credentials))}; - return NanEscapeScope(constructor->NewInstance(argc, argv)); + NanNew(reinterpret_cast(credentials))}; + return NanEscapeScope(constructor->GetFunction()->NewInstance(argc, argv)); } grpc_credentials *Credentials::GetWrappedCredentials() { @@ -116,15 +115,16 @@ NAN_METHOD(Credentials::New) { return NanThrowTypeError( "Credentials can only be created with the provided functions"); } + Handle ext = args[0].As(); grpc_credentials *creds_value = - reinterpret_cast(External::Unwrap(args[0])); + reinterpret_cast(ext->Value()); Credentials *credentials = new Credentials(creds_value); credentials->Wrap(args.This()); NanReturnValue(args.This()); } else { const int argc = 1; Local argv[argc] = {args[0]}; - NanReturnValue(constructor->NewInstance(argc, argv)); + NanReturnValue(constructor->GetFunction()->NewInstance(argc, argv)); } } @@ -137,19 +137,19 @@ NAN_METHOD(Credentials::CreateSsl) { NanScope(); char *root_certs = NULL; grpc_ssl_pem_key_cert_pair key_cert_pair = {NULL, NULL}; - if (Buffer::HasInstance(args[0])) { - root_certs = Buffer::Data(args[0]); + if (::node::Buffer::HasInstance(args[0])) { + root_certs = ::node::Buffer::Data(args[0]); } else if (!(args[0]->IsNull() || args[0]->IsUndefined())) { return NanThrowTypeError("createSsl's first argument must be a Buffer"); } - if (Buffer::HasInstance(args[1])) { - key_cert_pair.private_key = Buffer::Data(args[1]); + if (::node::Buffer::HasInstance(args[1])) { + key_cert_pair.private_key = ::node::Buffer::Data(args[1]); } else if (!(args[1]->IsNull() || args[1]->IsUndefined())) { return NanThrowTypeError( "createSSl's second argument must be a Buffer if provided"); } - if (Buffer::HasInstance(args[2])) { - key_cert_pair.cert_chain = Buffer::Data(args[2]); + if (::node::Buffer::HasInstance(args[2])) { + key_cert_pair.cert_chain = ::node::Buffer::Data(args[2]); } else if (!(args[2]->IsNull() || args[2]->IsUndefined())) { return NanThrowTypeError( "createSSl's third argument must be a Buffer if provided"); diff --git a/ext/credentials.h b/ext/credentials.h index e60be3d4..794736fe 100644 --- a/ext/credentials.h +++ b/ext/credentials.h @@ -68,7 +68,7 @@ class Credentials : public ::node::ObjectWrap { static NAN_METHOD(CreateGce); static NAN_METHOD(CreateFake); static NAN_METHOD(CreateIam); - static v8::Persistent constructor; + static NanCallback *constructor; // Used for typechecking instances of this javascript class static v8::Persistent fun_tpl; diff --git a/ext/node_grpc.cc b/ext/node_grpc.cc index 9f509583..4e31cbaa 100644 --- a/ext/node_grpc.cc +++ b/ext/node_grpc.cc @@ -51,7 +51,7 @@ using v8::String; void InitStatusConstants(Handle exports) { NanScope(); - Handle status = Object::New(); + Handle status = NanNew(); exports->Set(NanNew("status"), status); Handle OK(NanNew(GRPC_STATUS_OK)); status->Set(NanNew("OK"), OK); @@ -100,7 +100,7 @@ void InitStatusConstants(Handle exports) { void InitCallErrorConstants(Handle exports) { NanScope(); - Handle call_error = Object::New(); + Handle call_error = NanNew(); exports->Set(NanNew("callError"), call_error); Handle OK(NanNew(GRPC_CALL_OK)); call_error->Set(NanNew("OK"), OK); @@ -131,7 +131,7 @@ void InitCallErrorConstants(Handle exports) { void InitOpTypeConstants(Handle exports) { NanScope(); - Handle op_type = Object::New(); + Handle op_type = NanNew(); exports->Set(NanNew("opType"), op_type); Handle SEND_INITIAL_METADATA( NanNew(GRPC_OP_SEND_INITIAL_METADATA)); diff --git a/ext/server.cc b/ext/server.cc index ab45da8d..5050042d 100644 --- a/ext/server.cc +++ b/ext/server.cc @@ -53,7 +53,6 @@ namespace grpc { namespace node { using std::unique_ptr; -using v8::Arguments; using v8::Array; using v8::Boolean; using v8::Date; @@ -69,7 +68,7 @@ using v8::Persistent; using v8::String; using v8::Value; -Persistent Server::constructor; +NanCallback *Server::constructor; Persistent Server::fun_tpl; class NewCallOp : public Op { @@ -121,28 +120,30 @@ Server::~Server() { grpc_server_destroy(wrapped_server); } void Server::Init(Handle exports) { NanScope(); - Local tpl = FunctionTemplate::New(New); - tpl->SetClassName(String::NewSymbol("Server")); + Local tpl = NanNew(New); + tpl->SetClassName(NanNew("Server")); tpl->InstanceTemplate()->SetInternalFieldCount(1); NanSetPrototypeTemplate(tpl, "requestCall", - FunctionTemplate::New(RequestCall)->GetFunction()); + NanNew(RequestCall)->GetFunction()); - NanSetPrototypeTemplate(tpl, "addHttp2Port", - FunctionTemplate::New(AddHttp2Port)->GetFunction()); + NanSetPrototypeTemplate( + tpl, "addHttp2Port", + NanNew(AddHttp2Port)->GetFunction()); NanSetPrototypeTemplate( tpl, "addSecureHttp2Port", - FunctionTemplate::New(AddSecureHttp2Port)->GetFunction()); + NanNew(AddSecureHttp2Port)->GetFunction()); NanSetPrototypeTemplate(tpl, "start", - FunctionTemplate::New(Start)->GetFunction()); + NanNew(Start)->GetFunction()); NanSetPrototypeTemplate(tpl, "shutdown", - FunctionTemplate::New(Shutdown)->GetFunction()); + NanNew(Shutdown)->GetFunction()); NanAssignPersistent(fun_tpl, tpl); - NanAssignPersistent(constructor, tpl->GetFunction()); - exports->Set(String::NewSymbol("Server"), constructor); + Handle ctr = tpl->GetFunction(); + constructor = new NanCallback(ctr); + exports->Set(NanNew("Server"), ctr); } bool Server::HasInstance(Handle val) { @@ -157,7 +158,7 @@ NAN_METHOD(Server::New) { if (!args.IsConstructCall()) { const int argc = 1; Local argv[argc] = {args[0]}; - NanReturnValue(constructor->NewInstance(argc, argv)); + NanReturnValue(constructor->GetFunction()->NewInstance(argc, argv)); } grpc_server *wrapped_server; grpc_completion_queue *queue = CompletionQueueAsyncWorker::GetQueue(); diff --git a/ext/server.h b/ext/server.h index 2056fe7d..641d5ccb 100644 --- a/ext/server.h +++ b/ext/server.h @@ -67,7 +67,7 @@ class Server : public ::node::ObjectWrap { static NAN_METHOD(AddSecureHttp2Port); static NAN_METHOD(Start); static NAN_METHOD(Shutdown); - static v8::Persistent constructor; + static NanCallback *constructor; static v8::Persistent fun_tpl; grpc_server *wrapped_server; diff --git a/ext/server_credentials.cc b/ext/server_credentials.cc index f75a2bf7..d2b63cdc 100644 --- a/ext/server_credentials.cc +++ b/ext/server_credentials.cc @@ -41,8 +41,6 @@ namespace grpc { namespace node { -using ::node::Buffer; -using v8::Arguments; using v8::Exception; using v8::External; using v8::Function; @@ -56,7 +54,7 @@ using v8::ObjectTemplate; using v8::Persistent; using v8::Value; -Persistent ServerCredentials::constructor; +NanCallback *ServerCredentials::constructor; Persistent ServerCredentials::fun_tpl; ServerCredentials::ServerCredentials(grpc_server_credentials *credentials) @@ -68,16 +66,17 @@ ServerCredentials::~ServerCredentials() { void ServerCredentials::Init(Handle exports) { NanScope(); - Local tpl = FunctionTemplate::New(New); + Local tpl = NanNew(New); tpl->SetClassName(NanNew("ServerCredentials")); tpl->InstanceTemplate()->SetInternalFieldCount(1); NanAssignPersistent(fun_tpl, tpl); - NanAssignPersistent(constructor, tpl->GetFunction()); - constructor->Set(NanNew("createSsl"), - FunctionTemplate::New(CreateSsl)->GetFunction()); - constructor->Set(NanNew("createFake"), - FunctionTemplate::New(CreateFake)->GetFunction()); - exports->Set(NanNew("ServerCredentials"), constructor); + Handle ctr = tpl->GetFunction(); + ctr->Set(NanNew("createSsl"), + NanNew(CreateSsl)->GetFunction()); + ctr->Set(NanNew("createFake"), + NanNew(CreateFake)->GetFunction()); + constructor = new NanCallback(ctr); + exports->Set(NanNew("ServerCredentials"), ctr); } bool ServerCredentials::HasInstance(Handle val) { @@ -93,8 +92,8 @@ Handle ServerCredentials::WrapStruct( } const int argc = 1; Handle argv[argc] = { - External::New(reinterpret_cast(credentials))}; - return NanEscapeScope(constructor->NewInstance(argc, argv)); + NanNew(reinterpret_cast(credentials))}; + return NanEscapeScope(constructor->GetFunction()->NewInstance(argc, argv)); } grpc_server_credentials *ServerCredentials::GetWrappedServerCredentials() { @@ -109,15 +108,16 @@ NAN_METHOD(ServerCredentials::New) { return NanThrowTypeError( "ServerCredentials can only be created with the provide functions"); } + Handle ext = args[0].As(); grpc_server_credentials *creds_value = - reinterpret_cast(External::Unwrap(args[0])); + reinterpret_cast(ext->Value()); ServerCredentials *credentials = new ServerCredentials(creds_value); credentials->Wrap(args.This()); NanReturnValue(args.This()); } else { const int argc = 1; Local argv[argc] = {args[0]}; - NanReturnValue(constructor->NewInstance(argc, argv)); + NanReturnValue(constructor->GetFunction()->NewInstance(argc, argv)); } } @@ -126,20 +126,20 @@ NAN_METHOD(ServerCredentials::CreateSsl) { NanScope(); char *root_certs = NULL; grpc_ssl_pem_key_cert_pair key_cert_pair; - if (Buffer::HasInstance(args[0])) { - root_certs = Buffer::Data(args[0]); + if (::node::Buffer::HasInstance(args[0])) { + root_certs = ::node::Buffer::Data(args[0]); } else if (!(args[0]->IsNull() || args[0]->IsUndefined())) { return NanThrowTypeError( "createSSl's first argument must be a Buffer if provided"); } - if (!Buffer::HasInstance(args[1])) { + if (!::node::Buffer::HasInstance(args[1])) { return NanThrowTypeError("createSsl's second argument must be a Buffer"); } - key_cert_pair.private_key = Buffer::Data(args[1]); - if (!Buffer::HasInstance(args[2])) { + key_cert_pair.private_key = ::node::Buffer::Data(args[1]); + if (!::node::Buffer::HasInstance(args[2])) { return NanThrowTypeError("createSsl's third argument must be a Buffer"); } - key_cert_pair.cert_chain = Buffer::Data(args[2]); + key_cert_pair.cert_chain = ::node::Buffer::Data(args[2]); NanReturnValue(WrapStruct( grpc_ssl_server_credentials_create(root_certs, &key_cert_pair, 1))); } diff --git a/ext/server_credentials.h b/ext/server_credentials.h index f0990242..aaa7ef29 100644 --- a/ext/server_credentials.h +++ b/ext/server_credentials.h @@ -64,7 +64,7 @@ class ServerCredentials : public ::node::ObjectWrap { static NAN_METHOD(New); static NAN_METHOD(CreateSsl); static NAN_METHOD(CreateFake); - static v8::Persistent constructor; + static NanCallback *constructor; // Used for typechecking instances of this javascript class static v8::Persistent fun_tpl; From 59e0c87eb97b7e4cb34572c69aa7689d42fe430b Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Wed, 4 Mar 2015 14:54:32 -0800 Subject: [PATCH 4/4] Removes engine restriction from package.json, bumps version --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 13606956..20eb21fc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "grpc", - "version": "0.5.1", + "version": "0.5.2", "author": "Google Inc.", "description": "gRPC Library for Node", "homepage": "http://www.grpc.io/", @@ -39,7 +39,7 @@ "strftime": "^0.8.2" }, "engines": { - "node": ">=0.10.13 <0.11" + "node": ">=0.10.13" }, "files": [ "LICENSE",