mirror of
https://github.com/grpc/grpc-node.git
synced 2025-12-08 18:23:54 +00:00
Merge pull request #952 from murgatroid99/node_0_12_compatibility
Node 0.11+ compatibility
This commit is contained in:
commit
da7440e9af
@ -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);
|
||||
}
|
||||
|
||||
55
ext/call.cc
55
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<Function> Call::constructor;
|
||||
NanCallback *Call::constructor;
|
||||
Persistent<FunctionTemplate> Call::fun_tpl;
|
||||
|
||||
|
||||
@ -101,11 +99,11 @@ 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);
|
||||
Persistent<Value> handle;
|
||||
NanAssignPersistent(handle, value);
|
||||
if (::node::Buffer::HasInstance(value)) {
|
||||
current->value = ::node::Buffer::Data(value);
|
||||
current->value_length = ::node::Buffer::Length(value);
|
||||
Persistent<Value> *handle = new Persistent<Value>();
|
||||
NanAssignPersistent(*handle, value);
|
||||
resources->handles.push_back(unique_ptr<PersistentHolder>(
|
||||
new PersistentHolder(handle)));
|
||||
} else if (value->IsString()) {
|
||||
@ -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,12 +192,12 @@ 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);
|
||||
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;
|
||||
@ -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"),
|
||||
NanNew<Uint32, uint32_t>(GRPC_WRITE_BUFFER_HINT));
|
||||
constructor->Set(NanNew("WRITE_NO_COMPRESS"),
|
||||
NanNew<Uint32, uint32_t>(GRPC_WRITE_NO_COMPRESS));
|
||||
exports->Set(String::NewSymbol("Call"), constructor);
|
||||
Handle<Function> ctr = tpl->GetFunction();
|
||||
ctr->Set(NanNew("WRITE_BUFFER_HINT"),
|
||||
NanNew<Uint32, uint32_t>(GRPC_WRITE_BUFFER_HINT));
|
||||
ctr->Set(NanNew("WRITE_NO_COMPRESS"),
|
||||
NanNew<Uint32, uint32_t>(GRPC_WRITE_NO_COMPRESS));
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
10
ext/call.h
10
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 {
|
||||
@ -118,7 +120,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;
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
13
package.json
13
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/",
|
||||
@ -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"
|
||||
},
|
||||
"files": [
|
||||
"LICENSE",
|
||||
"README.md",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user