diff --git a/src/node/ext/call.cc b/src/node/ext/call.cc index 1d85abb1d282f754ae3a94a08f84d08405cda920..afb654178318127ec38b454cc2379fd41ddf1eae 100644 --- a/src/node/ext/call.cc +++ b/src/node/ext/call.cc @@ -102,8 +102,8 @@ bool CreateMetadataArray(Handle<Object> metadata, grpc_metadata_array *array, if (::node::Buffer::HasInstance(value)) { current->value = ::node::Buffer::Data(value); current->value_length = ::node::Buffer::Length(value); - Persistent<Value> handle; - NanAssignPersistent(handle, value); + Persistent<Value> *handle = new Persistent<Value>(); + NanAssignPersistent(*handle, value); resources->handles.push_back(unique_ptr<PersistentHolder>( new PersistentHolder(handle))); } else if (value->IsString()) { @@ -196,8 +196,8 @@ class SendMessageOp : public Op { return false; } out->data.send_message = BufferToByteBuffer(value); - Persistent<Value> handle; - NanAssignPersistent(handle, value); + Persistent<Value> *handle = new Persistent<Value>(); + NanAssignPersistent(*handle, value); resources->handles.push_back(unique_ptr<PersistentHolder>( new PersistentHolder(handle))); return true; diff --git a/src/node/ext/call.h b/src/node/ext/call.h index 2e9e1c5bf37e8074f0db3dd649edff027acc541b..43142c7091fe6c30b434a03d413c22f844853771 100644 --- a/src/node/ext/call.h +++ b/src/node/ext/call.h @@ -40,6 +40,7 @@ #include <node.h> #include <nan.h> #include "grpc/grpc.h" +#include "grpc/support/log.h" #include "channel.h" @@ -54,16 +55,17 @@ v8::Handle<v8::Value> ParseMetadata(const grpc_metadata_array *metadata_array); class PersistentHolder { public: - explicit PersistentHolder(v8::Persistent<v8::Value> persist) : + explicit PersistentHolder(v8::Persistent<v8::Value> *persist) : persist(persist) { } ~PersistentHolder() { - NanDisposePersistent(persist); + NanDisposePersistent(*persist); + delete persist; } private: - v8::Persistent<v8::Value> persist; + v8::Persistent<v8::Value> *persist; }; struct Resources { diff --git a/src/node/ext/channel.cc b/src/node/ext/channel.cc index bc9461d7dfd39535c287c8246a3fe1010855edab..787e274973fdf7b9cd248a7090c0f08041a3caa3 100644 --- a/src/node/ext/channel.cc +++ b/src/node/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<Function> Channel::constructor; +NanCallback *Channel::constructor; Persistent<FunctionTemplate> Channel::fun_tpl; Channel::Channel(grpc_channel *channel, NanUtf8String *host) @@ -74,14 +73,15 @@ Channel::~Channel() { void Channel::Init(Handle<Object> exports) { NanScope(); - Local<FunctionTemplate> tpl = FunctionTemplate::New(New); + Local<FunctionTemplate> tpl = NanNew<FunctionTemplate>(New); tpl->SetClassName(NanNew("Channel")); tpl->InstanceTemplate()->SetInternalFieldCount(1); NanSetPrototypeTemplate(tpl, "close", - FunctionTemplate::New(Close)->GetFunction()); + NanNew<FunctionTemplate>(Close)->GetFunction()); NanAssignPersistent(fun_tpl, tpl); - NanAssignPersistent(constructor, tpl->GetFunction()); - exports->Set(NanNew("Channel"), constructor); + Handle<Function> ctr = tpl->GetFunction(); + constructor = new NanCallback(ctr); + exports->Set(NanNew("Channel"), ctr); } bool Channel::HasInstance(Handle<Value> val) { @@ -170,7 +170,7 @@ NAN_METHOD(Channel::New) { } else { const int argc = 2; Local<Value> argv[argc] = {args[0], args[1]}; - NanReturnValue(constructor->NewInstance(argc, argv)); + NanReturnValue(constructor->GetFunction()->NewInstance(argc, argv)); } } diff --git a/src/node/ext/channel.h b/src/node/ext/channel.h index bf793194d9a7ff1cb91bd90b5d15f043f83d983e..b3aa0f700fa98b16f47a4fa6bd4834b0f550a600 100644 --- a/src/node/ext/channel.h +++ b/src/node/ext/channel.h @@ -66,7 +66,7 @@ class Channel : public ::node::ObjectWrap { static NAN_METHOD(New); static NAN_METHOD(Close); - static v8::Persistent<v8::Function> constructor; + static NanCallback *constructor; static v8::Persistent<v8::FunctionTemplate> fun_tpl; grpc_channel *wrapped_channel; diff --git a/src/node/ext/credentials.cc b/src/node/ext/credentials.cc index 3f65d59c766be9641fefb804b4e1f26baf2fccd0..34872017ea186eb76e3f24a2f95f003f8e8e7f71 100644 --- a/src/node/ext/credentials.cc +++ b/src/node/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<Function> Credentials::constructor; +NanCallback *Credentials::constructor; Persistent<FunctionTemplate> Credentials::fun_tpl; Credentials::Credentials(grpc_credentials *credentials) @@ -68,24 +66,25 @@ Credentials::~Credentials() { void Credentials::Init(Handle<Object> exports) { NanScope(); - Local<FunctionTemplate> tpl = FunctionTemplate::New(New); + Local<FunctionTemplate> tpl = NanNew<FunctionTemplate>(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<Function> ctr = tpl->GetFunction(); + ctr->Set(NanNew("createDefault"), + NanNew<FunctionTemplate>(CreateDefault)->GetFunction()); + ctr->Set(NanNew("createSsl"), + NanNew<FunctionTemplate>(CreateSsl)->GetFunction()); + ctr->Set(NanNew("createComposite"), + NanNew<FunctionTemplate>(CreateComposite)->GetFunction()); + ctr->Set(NanNew("createGce"), + NanNew<FunctionTemplate>(CreateGce)->GetFunction()); + ctr->Set(NanNew("createFake"), + NanNew<FunctionTemplate>(CreateFake)->GetFunction()); + ctr->Set(NanNew("createIam"), + NanNew<FunctionTemplate>(CreateIam)->GetFunction()); + constructor = new NanCallback(ctr); + exports->Set(NanNew("Credentials"), ctr); } bool Credentials::HasInstance(Handle<Value> val) { @@ -100,8 +99,8 @@ Handle<Value> Credentials::WrapStruct(grpc_credentials *credentials) { } const int argc = 1; Handle<Value> argv[argc] = { - External::New(reinterpret_cast<void *>(credentials))}; - return NanEscapeScope(constructor->NewInstance(argc, argv)); + NanNew<External>(reinterpret_cast<void *>(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<External> ext = args[0].As<External>(); grpc_credentials *creds_value = - reinterpret_cast<grpc_credentials *>(External::Unwrap(args[0])); + reinterpret_cast<grpc_credentials *>(ext->Value()); Credentials *credentials = new Credentials(creds_value); credentials->Wrap(args.This()); NanReturnValue(args.This()); } else { const int argc = 1; Local<Value> 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/src/node/ext/credentials.h b/src/node/ext/credentials.h index e60be3d4e155b7581ff55e2649402cf2bf8e5b45..794736fe1ab51d74c5555a77a88f4ba21be2032f 100644 --- a/src/node/ext/credentials.h +++ b/src/node/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<v8::Function> constructor; + static NanCallback *constructor; // Used for typechecking instances of this javascript class static v8::Persistent<v8::FunctionTemplate> fun_tpl; diff --git a/src/node/ext/node_grpc.cc b/src/node/ext/node_grpc.cc index 9f5095839cb7404ffe21a5ee320a11049d1292b2..4e31cbaa277bc6c164787b661b3d04aa3d5f87f9 100644 --- a/src/node/ext/node_grpc.cc +++ b/src/node/ext/node_grpc.cc @@ -51,7 +51,7 @@ using v8::String; void InitStatusConstants(Handle<Object> exports) { NanScope(); - Handle<Object> status = Object::New(); + Handle<Object> status = NanNew<Object>(); exports->Set(NanNew("status"), status); Handle<Value> OK(NanNew<Uint32, uint32_t>(GRPC_STATUS_OK)); status->Set(NanNew("OK"), OK); @@ -100,7 +100,7 @@ void InitStatusConstants(Handle<Object> exports) { void InitCallErrorConstants(Handle<Object> exports) { NanScope(); - Handle<Object> call_error = Object::New(); + Handle<Object> call_error = NanNew<Object>(); exports->Set(NanNew("callError"), call_error); Handle<Value> OK(NanNew<Uint32, uint32_t>(GRPC_CALL_OK)); call_error->Set(NanNew("OK"), OK); @@ -131,7 +131,7 @@ void InitCallErrorConstants(Handle<Object> exports) { void InitOpTypeConstants(Handle<Object> exports) { NanScope(); - Handle<Object> op_type = Object::New(); + Handle<Object> op_type = NanNew<Object>(); exports->Set(NanNew("opType"), op_type); Handle<Value> SEND_INITIAL_METADATA( NanNew<Uint32, uint32_t>(GRPC_OP_SEND_INITIAL_METADATA)); diff --git a/src/node/ext/server.cc b/src/node/ext/server.cc index ab45da8d199692f0c90ebbcd55d65d76e697639b..5050042daa7c9dfdb2ed1556af45193e443d21ef 100644 --- a/src/node/ext/server.cc +++ b/src/node/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<Function> Server::constructor; +NanCallback *Server::constructor; Persistent<FunctionTemplate> Server::fun_tpl; class NewCallOp : public Op { @@ -121,28 +120,30 @@ Server::~Server() { grpc_server_destroy(wrapped_server); } void Server::Init(Handle<Object> exports) { NanScope(); - Local<FunctionTemplate> tpl = FunctionTemplate::New(New); - tpl->SetClassName(String::NewSymbol("Server")); + Local<FunctionTemplate> tpl = NanNew<FunctionTemplate>(New); + tpl->SetClassName(NanNew("Server")); tpl->InstanceTemplate()->SetInternalFieldCount(1); NanSetPrototypeTemplate(tpl, "requestCall", - FunctionTemplate::New(RequestCall)->GetFunction()); + NanNew<FunctionTemplate>(RequestCall)->GetFunction()); - NanSetPrototypeTemplate(tpl, "addHttp2Port", - FunctionTemplate::New(AddHttp2Port)->GetFunction()); + NanSetPrototypeTemplate( + tpl, "addHttp2Port", + NanNew<FunctionTemplate>(AddHttp2Port)->GetFunction()); NanSetPrototypeTemplate( tpl, "addSecureHttp2Port", - FunctionTemplate::New(AddSecureHttp2Port)->GetFunction()); + NanNew<FunctionTemplate>(AddSecureHttp2Port)->GetFunction()); NanSetPrototypeTemplate(tpl, "start", - FunctionTemplate::New(Start)->GetFunction()); + NanNew<FunctionTemplate>(Start)->GetFunction()); NanSetPrototypeTemplate(tpl, "shutdown", - FunctionTemplate::New(Shutdown)->GetFunction()); + NanNew<FunctionTemplate>(Shutdown)->GetFunction()); NanAssignPersistent(fun_tpl, tpl); - NanAssignPersistent(constructor, tpl->GetFunction()); - exports->Set(String::NewSymbol("Server"), constructor); + Handle<Function> ctr = tpl->GetFunction(); + constructor = new NanCallback(ctr); + exports->Set(NanNew("Server"), ctr); } bool Server::HasInstance(Handle<Value> val) { @@ -157,7 +158,7 @@ NAN_METHOD(Server::New) { if (!args.IsConstructCall()) { const int argc = 1; Local<Value> 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/src/node/ext/server.h b/src/node/ext/server.h index 2056fe7d3f8a5b14ff2ae948493c089175ee4c12..641d5ccb3e4f7cc5acaba05e22f946336f04e801 100644 --- a/src/node/ext/server.h +++ b/src/node/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<v8::Function> constructor; + static NanCallback *constructor; static v8::Persistent<v8::FunctionTemplate> fun_tpl; grpc_server *wrapped_server; diff --git a/src/node/ext/server_credentials.cc b/src/node/ext/server_credentials.cc index f75a2bf79c8f2cd2ec03e3e69311c43d530a654c..d2b63cdc4ec26b1983164b44c39f3899209a1fac 100644 --- a/src/node/ext/server_credentials.cc +++ b/src/node/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<Function> ServerCredentials::constructor; +NanCallback *ServerCredentials::constructor; Persistent<FunctionTemplate> ServerCredentials::fun_tpl; ServerCredentials::ServerCredentials(grpc_server_credentials *credentials) @@ -68,16 +66,17 @@ ServerCredentials::~ServerCredentials() { void ServerCredentials::Init(Handle<Object> exports) { NanScope(); - Local<FunctionTemplate> tpl = FunctionTemplate::New(New); + Local<FunctionTemplate> tpl = NanNew<FunctionTemplate>(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<Function> ctr = tpl->GetFunction(); + ctr->Set(NanNew("createSsl"), + NanNew<FunctionTemplate>(CreateSsl)->GetFunction()); + ctr->Set(NanNew("createFake"), + NanNew<FunctionTemplate>(CreateFake)->GetFunction()); + constructor = new NanCallback(ctr); + exports->Set(NanNew("ServerCredentials"), ctr); } bool ServerCredentials::HasInstance(Handle<Value> val) { @@ -93,8 +92,8 @@ Handle<Value> ServerCredentials::WrapStruct( } const int argc = 1; Handle<Value> argv[argc] = { - External::New(reinterpret_cast<void *>(credentials))}; - return NanEscapeScope(constructor->NewInstance(argc, argv)); + NanNew<External>(reinterpret_cast<void *>(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<External> ext = args[0].As<External>(); grpc_server_credentials *creds_value = - reinterpret_cast<grpc_server_credentials *>(External::Unwrap(args[0])); + reinterpret_cast<grpc_server_credentials *>(ext->Value()); ServerCredentials *credentials = new ServerCredentials(creds_value); credentials->Wrap(args.This()); NanReturnValue(args.This()); } else { const int argc = 1; Local<Value> 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/src/node/ext/server_credentials.h b/src/node/ext/server_credentials.h index f09902420c6e6413f02f4bfa086d4827294a66e6..aaa7ef297a40cc9f4d868429b0c08e42cc52a5aa 100644 --- a/src/node/ext/server_credentials.h +++ b/src/node/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<v8::Function> constructor; + static NanCallback *constructor; // Used for typechecking instances of this javascript class static v8::Persistent<v8::FunctionTemplate> fun_tpl;