The library now compiles with Node 0.11+ and all versions of io.js

pull/952/head
murgatroid99 10 years ago
parent 5f875d2986
commit f28066b930
  1. 8
      src/node/ext/call.cc
  2. 8
      src/node/ext/call.h
  3. 14
      src/node/ext/channel.cc
  4. 2
      src/node/ext/channel.h
  5. 56
      src/node/ext/credentials.cc
  6. 2
      src/node/ext/credentials.h
  7. 6
      src/node/ext/node_grpc.cc
  8. 27
      src/node/ext/server.cc
  9. 2
      src/node/ext/server.h
  10. 40
      src/node/ext/server_credentials.cc
  11. 2
      src/node/ext/server_credentials.h

@ -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;

@ -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 {

@ -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));
}
}

@ -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;

@ -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");

@ -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;

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

@ -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();

@ -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;

@ -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)));
}

@ -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;

Loading…
Cancel
Save