aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar murgatroid99 <mlumish@google.com>2015-09-17 13:56:25 -0700
committerGravatar murgatroid99 <mlumish@google.com>2015-09-17 13:56:25 -0700
commit2b09783f8ad3aff8af6b1e5a9e3d799c4df1d4f1 (patch)
treea3335cdd2edf0ca19a140b3bc91d88c20145ce9a /src
parente8659971a9cedeccb90d39d2dfe784048baa2f19 (diff)
Update to nan 2.0
Diffstat (limited to 'src')
-rw-r--r--src/node/binding.gyp1
-rw-r--r--src/node/ext/byte_buffer.cc36
-rw-r--r--src/node/ext/byte_buffer.h6
-rw-r--r--src/node/ext/call.cc445
-rw-r--r--src/node/ext/call.h57
-rw-r--r--src/node/ext/channel.cc178
-rw-r--r--src/node/ext/channel.h10
-rw-r--r--src/node/ext/completion_queue_async_worker.cc27
-rw-r--r--src/node/ext/completion_queue_async_worker.h4
-rw-r--r--src/node/ext/credentials.cc192
-rw-r--r--src/node/ext/credentials.h12
-rw-r--r--src/node/ext/node_grpc.cc319
-rw-r--r--src/node/ext/server.cc202
-rw-r--r--src/node/ext/server.h10
-rw-r--r--src/node/ext/server_credentials.cc153
-rw-r--r--src/node/ext/server_credentials.h12
-rw-r--r--src/node/package.json2
17 files changed, 893 insertions, 773 deletions
diff --git a/src/node/binding.gyp b/src/node/binding.gyp
index 734dc8410b..a644030932 100644
--- a/src/node/binding.gyp
+++ b/src/node/binding.gyp
@@ -8,7 +8,6 @@
'-std=c++0x',
'-Wall',
'-pthread',
- '-pedantic',
'-g',
'-zdefs',
'-Werror',
diff --git a/src/node/ext/byte_buffer.cc b/src/node/ext/byte_buffer.cc
index 7eff11c2b3..e1786ddba7 100644
--- a/src/node/ext/byte_buffer.cc
+++ b/src/node/ext/byte_buffer.cc
@@ -44,15 +44,16 @@
namespace grpc {
namespace node {
+
using v8::Context;
using v8::Function;
-using v8::Handle;
+using v8::Local;
using v8::Object;
using v8::Number;
using v8::Value;
-grpc_byte_buffer *BufferToByteBuffer(Handle<Value> buffer) {
- NanScope();
+grpc_byte_buffer *BufferToByteBuffer(Local<Value> buffer) {
+ Nan::HandleScope scope;
int length = ::node::Buffer::Length(buffer);
char *data = ::node::Buffer::Data(buffer);
gpr_slice slice = gpr_slice_malloc(length);
@@ -62,10 +63,10 @@ grpc_byte_buffer *BufferToByteBuffer(Handle<Value> buffer) {
return byte_buffer;
}
-Handle<Value> ByteBufferToBuffer(grpc_byte_buffer *buffer) {
- NanEscapableScope();
+Local<Value> ByteBufferToBuffer(grpc_byte_buffer *buffer) {
+ Nan::EscapableHandleScope scope;
if (buffer == NULL) {
- return NanEscapeScope(NanNull());
+ return scope.Escape(Nan::Null());
}
size_t length = grpc_byte_buffer_length(buffer);
char *result = reinterpret_cast<char *>(calloc(length, sizeof(char)));
@@ -77,21 +78,22 @@ Handle<Value> ByteBufferToBuffer(grpc_byte_buffer *buffer) {
memcpy(result + offset, GPR_SLICE_START_PTR(next), GPR_SLICE_LENGTH(next));
offset += GPR_SLICE_LENGTH(next);
}
- return NanEscapeScope(MakeFastBuffer(NanNewBufferHandle(result, length)));
+ return scope.Escape(MakeFastBuffer(
+ Nan::NewBuffer(result, length).ToLocalChecked()));
}
-Handle<Value> MakeFastBuffer(Handle<Value> slowBuffer) {
- NanEscapableScope();
- Handle<Object> globalObj = NanGetCurrentContext()->Global();
- Handle<Function> bufferConstructor = Handle<Function>::Cast(
- globalObj->Get(NanNew("Buffer")));
- Handle<Value> consArgs[3] = {
+Local<Value> MakeFastBuffer(Local<Value> slowBuffer) {
+ Nan::EscapableHandleScope scope;
+ Local<Object> globalObj = Nan::GetCurrentContext()->Global();
+ Local<Function> bufferConstructor = Local<Function>::Cast(
+ globalObj->Get(Nan::New("Buffer").ToLocalChecked()));
+ Local<Value> consArgs[3] = {
slowBuffer,
- NanNew<Number>(::node::Buffer::Length(slowBuffer)),
- NanNew<Number>(0)
+ Nan::New<Number>(::node::Buffer::Length(slowBuffer)),
+ Nan::New<Number>(0)
};
- Handle<Object> fastBuffer = bufferConstructor->NewInstance(3, consArgs);
- return NanEscapeScope(fastBuffer);
+ Local<Object> fastBuffer = bufferConstructor->NewInstance(3, consArgs);
+ return scope.Escape(fastBuffer);
}
} // namespace node
} // namespace grpc
diff --git a/src/node/ext/byte_buffer.h b/src/node/ext/byte_buffer.h
index 5083674d39..55bc0ab377 100644
--- a/src/node/ext/byte_buffer.h
+++ b/src/node/ext/byte_buffer.h
@@ -45,14 +45,14 @@ namespace node {
/* Convert a Node.js Buffer to grpc_byte_buffer. Requires that
::node::Buffer::HasInstance(buffer) */
-grpc_byte_buffer *BufferToByteBuffer(v8::Handle<v8::Value> buffer);
+grpc_byte_buffer *BufferToByteBuffer(v8::Local<v8::Value> buffer);
/* Convert a grpc_byte_buffer to a Node.js Buffer */
-v8::Handle<v8::Value> ByteBufferToBuffer(grpc_byte_buffer *buffer);
+v8::Local<v8::Value> ByteBufferToBuffer(grpc_byte_buffer *buffer);
/* Convert a ::node::Buffer to a fast Buffer, as defined in the Node
Buffer documentation */
-v8::Handle<v8::Value> MakeFastBuffer(v8::Handle<v8::Value> slowBuffer);
+v8::Local<v8::Value> MakeFastBuffer(v8::Local<v8::Value> slowBuffer);
} // namespace node
} // namespace grpc
diff --git a/src/node/ext/call.cc b/src/node/ext/call.cc
index 560869e6fa..7e79a612ee 100644
--- a/src/node/ext/call.cc
+++ b/src/node/ext/call.cc
@@ -54,52 +54,61 @@ using std::vector;
namespace grpc {
namespace node {
+using Nan::Callback;
+using Nan::EscapableHandleScope;
+using Nan::HandleScope;
+using Nan::Maybe;
+using Nan::MaybeLocal;
+using Nan::ObjectWrap;
+using Nan::Persistent;
+using Nan::Utf8String;
+
using v8::Array;
using v8::Boolean;
using v8::Exception;
using v8::External;
using v8::Function;
using v8::FunctionTemplate;
-using v8::Handle;
-using v8::HandleScope;
using v8::Integer;
using v8::Local;
using v8::Number;
using v8::Object;
using v8::ObjectTemplate;
-using v8::Persistent;
using v8::Uint32;
using v8::String;
using v8::Value;
-NanCallback *Call::constructor;
+Callback *Call::constructor;
Persistent<FunctionTemplate> Call::fun_tpl;
bool EndsWith(const char *str, const char *substr) {
return strcmp(str+strlen(str)-strlen(substr), substr) == 0;
}
-bool CreateMetadataArray(Handle<Object> metadata, grpc_metadata_array *array,
+bool CreateMetadataArray(Local<Object> metadata, grpc_metadata_array *array,
shared_ptr<Resources> resources) {
- NanScope();
+ HandleScope scope;
grpc_metadata_array_init(array);
- Handle<Array> keys(metadata->GetOwnPropertyNames());
+ Local<Array> keys = Nan::GetOwnPropertyNames(metadata).ToLocalChecked();
for (unsigned int i = 0; i < keys->Length(); i++) {
- Handle<String> current_key(keys->Get(i)->ToString());
- if (!metadata->Get(current_key)->IsArray()) {
+ Local<String> current_key = Nan::To<String>(
+ Nan::Get(keys, i).ToLocalChecked()).ToLocalChecked();
+ Local<Value> value_array = Nan::Get(metadata, current_key).ToLocalChecked();
+ if (!value_array->IsArray()) {
return false;
}
- array->capacity += Local<Array>::Cast(metadata->Get(current_key))->Length();
+ array->capacity += Local<Array>::Cast(value_array)->Length();
}
array->metadata = reinterpret_cast<grpc_metadata*>(
gpr_malloc(array->capacity * sizeof(grpc_metadata)));
for (unsigned int i = 0; i < keys->Length(); i++) {
- Handle<String> current_key(keys->Get(i)->ToString());
- NanUtf8String *utf8_key = new NanUtf8String(current_key);
- resources->strings.push_back(unique_ptr<NanUtf8String>(utf8_key));
- Handle<Array> values = Local<Array>::Cast(metadata->Get(current_key));
+ Local<String> current_key(keys->Get(i)->ToString());
+ Utf8String *utf8_key = new Utf8String(current_key);
+ resources->strings.push_back(unique_ptr<Utf8String>(utf8_key));
+ Local<Array> values = Local<Array>::Cast(
+ Nan::Get(metadata, current_key).ToLocalChecked());
for (unsigned int j = 0; j < values->Length(); j++) {
- Handle<Value> value = values->Get(j);
+ Local<Value> value = Nan::Get(values, j).ToLocalChecked();
grpc_metadata *current = &array->metadata[array->count];
current->key = **utf8_key;
// Only allow binary headers for "-bin" keys
@@ -107,18 +116,16 @@ 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 = new Persistent<Value>();
- NanAssignPersistent(*handle, value);
- resources->handles.push_back(unique_ptr<PersistentHolder>(
- new PersistentHolder(handle)));
+ PersistentValue *handle = new PersistentValue(value);
+ resources->handles.push_back(unique_ptr<PersistentValue>(handle));
} else {
return false;
}
} else {
if (value->IsString()) {
- Handle<String> string_value = value->ToString();
- NanUtf8String *utf8_value = new NanUtf8String(string_value);
- resources->strings.push_back(unique_ptr<NanUtf8String>(utf8_value));
+ Local<String> string_value = Nan::To<String>(value).ToLocalChecked();
+ Utf8String *utf8_value = new Utf8String(string_value);
+ resources->strings.push_back(unique_ptr<Utf8String>(utf8_value));
current->value = **utf8_value;
current->value_length = string_value->Length();
} else {
@@ -131,8 +138,8 @@ bool CreateMetadataArray(Handle<Object> metadata, grpc_metadata_array *array,
return true;
}
-Handle<Value> ParseMetadata(const grpc_metadata_array *metadata_array) {
- NanEscapableScope();
+Local<Value> ParseMetadata(const grpc_metadata_array *metadata_array) {
+ EscapableHandleScope scope;
grpc_metadata *metadata_elements = metadata_array->metadata;
size_t length = metadata_array->count;
std::map<const char*, size_t> size_map;
@@ -142,49 +149,59 @@ Handle<Value> ParseMetadata(const grpc_metadata_array *metadata_array) {
const char *key = metadata_elements[i].key;
if (size_map.count(key)) {
size_map[key] += 1;
+ } else {
+ size_map[key] = 1;
}
index_map[key] = 0;
}
- Handle<Object> metadata_object = NanNew<Object>();
+ Local<Object> metadata_object = Nan::New<Object>();
for (unsigned int i = 0; i < length; i++) {
grpc_metadata* elem = &metadata_elements[i];
- 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));
+ Local<String> key_string = Nan::New(elem->key).ToLocalChecked();
+ Local<Array> array;
+ MaybeLocal<Value> maybe_array = Nan::Get(metadata_object, key_string);
+ if (maybe_array.IsEmpty() || !maybe_array.ToLocalChecked()->IsArray()) {
+ array = Nan::New<Array>(size_map[elem->key]);
+ Nan::Set(metadata_object, key_string, array);
} else {
- array = NanNew<Array>(size_map[elem->key]);
- metadata_object->Set(key_string, array);
+ array = Local<Array>::Cast(maybe_array.ToLocalChecked());
}
if (EndsWith(elem->key, "-bin")) {
- array->Set(index_map[elem->key],
- NanNewBufferHandle(elem->value, elem->value_length));
+ Nan::Set(array, index_map[elem->key],
+ Nan::CopyBuffer(elem->value,
+ elem->value_length).ToLocalChecked());
} else {
- array->Set(index_map[elem->key], NanNew(elem->value));
+ Nan::Set(array, index_map[elem->key],
+ Nan::New(elem->value).ToLocalChecked());
}
index_map[elem->key] += 1;
}
- return NanEscapeScope(metadata_object);
+ return scope.Escape(metadata_object);
}
-Handle<Value> Op::GetOpType() const {
- NanEscapableScope();
- return NanEscapeScope(NanNew<String>(GetTypeString()));
+Local<Value> Op::GetOpType() const {
+ EscapableHandleScope scope;
+ return scope.Escape(Nan::New(GetTypeString()).ToLocalChecked());
}
class SendMetadataOp : public Op {
public:
- Handle<Value> GetNodeValue() const {
- NanEscapableScope();
- return NanEscapeScope(NanTrue());
+ Local<Value> GetNodeValue() const {
+ EscapableHandleScope scope;
+ return scope.Escape(Nan::True());
}
- bool ParseOp(Handle<Value> value, grpc_op *out,
+ bool ParseOp(Local<Value> value, grpc_op *out,
shared_ptr<Resources> resources) {
if (!value->IsObject()) {
return false;
}
grpc_metadata_array array;
- if (!CreateMetadataArray(value->ToObject(), &array, resources)) {
+ MaybeLocal<Object> maybe_metadata = Nan::To<Object>(value);
+ if (maybe_metadata.IsEmpty()) {
+ return false;
+ }
+ if (!CreateMetadataArray(maybe_metadata.ToLocalChecked(),
+ &array, resources)) {
return false;
}
out->data.send_initial_metadata.count = array.count;
@@ -199,27 +216,28 @@ class SendMetadataOp : public Op {
class SendMessageOp : public Op {
public:
- Handle<Value> GetNodeValue() const {
- NanEscapableScope();
- return NanEscapeScope(NanTrue());
+ Local<Value> GetNodeValue() const {
+ EscapableHandleScope scope;
+ return scope.Escape(Nan::True());
}
- bool ParseOp(Handle<Value> value, grpc_op *out,
+ bool ParseOp(Local<Value> value, grpc_op *out,
shared_ptr<Resources> resources) {
if (!::node::Buffer::HasInstance(value)) {
return false;
}
- Handle<Object> object_value = value->ToObject();
- if (object_value->HasOwnProperty(NanNew("grpcWriteFlags"))) {
- Handle<Value> flag_value = object_value->Get(NanNew("grpcWriteFlags"));
+ Local<Object> object_value = Nan::To<Object>(value).ToLocalChecked();
+ MaybeLocal<Value> maybe_flag_value = Nan::Get(
+ object_value, Nan::New("grpcWriteFlags").ToLocalChecked());
+ if (!maybe_flag_value.IsEmpty()) {
+ Local<Value> flag_value = maybe_flag_value.ToLocalChecked();
if (flag_value->IsUint32()) {
- out->flags = flag_value->Uint32Value() & GRPC_WRITE_USED_MASK;
+ Maybe<uint32_t> maybe_flag = Nan::To<uint32_t>(flag_value);
+ out->flags = maybe_flag.FromMaybe(0) & GRPC_WRITE_USED_MASK;
}
}
out->data.send_message = BufferToByteBuffer(value);
- Persistent<Value> *handle = new Persistent<Value>();
- NanAssignPersistent(*handle, value);
- resources->handles.push_back(unique_ptr<PersistentHolder>(
- new PersistentHolder(handle)));
+ PersistentValue *handle = new PersistentValue(value);
+ resources->handles.push_back(unique_ptr<PersistentValue>(handle));
return true;
}
protected:
@@ -230,11 +248,11 @@ class SendMessageOp : public Op {
class SendClientCloseOp : public Op {
public:
- Handle<Value> GetNodeValue() const {
- NanEscapableScope();
- return NanEscapeScope(NanTrue());
+ Local<Value> GetNodeValue() const {
+ EscapableHandleScope scope;
+ return scope.Escape(Nan::True());
}
- bool ParseOp(Handle<Value> value, grpc_op *out,
+ bool ParseOp(Local<Value> value, grpc_op *out,
shared_ptr<Resources> resources) {
return true;
}
@@ -246,39 +264,55 @@ class SendClientCloseOp : public Op {
class SendServerStatusOp : public Op {
public:
- Handle<Value> GetNodeValue() const {
- NanEscapableScope();
- return NanEscapeScope(NanTrue());
+ Local<Value> GetNodeValue() const {
+ EscapableHandleScope scope;
+ return scope.Escape(Nan::True());
}
- bool ParseOp(Handle<Value> value, grpc_op *out,
+ bool ParseOp(Local<Value> value, grpc_op *out,
shared_ptr<Resources> resources) {
if (!value->IsObject()) {
return false;
}
- Handle<Object> server_status = value->ToObject();
- if (!server_status->Get(NanNew("metadata"))->IsObject()) {
+ Local<Object> server_status = Nan::To<Object>(value).ToLocalChecked();
+ MaybeLocal<Value> maybe_metadata = Nan::Get(
+ server_status, Nan::New("metadata").ToLocalChecked());
+ if (maybe_metadata.IsEmpty()) {
+ return false;
+ }
+ if (!maybe_metadata.ToLocalChecked()->IsObject()) {
+ return false;
+ }
+ Local<Object> metadata = Nan::To<Object>(
+ maybe_metadata.ToLocalChecked()).ToLocalChecked();
+ MaybeLocal<Value> maybe_code = Nan::Get(server_status,
+ Nan::New("code").ToLocalChecked());
+ if (maybe_code.IsEmpty()) {
return false;
}
- if (!server_status->Get(NanNew("code"))->IsUint32()) {
+ if (!maybe_code.ToLocalChecked()->IsUint32()) {
return false;
}
- if (!server_status->Get(NanNew("details"))->IsString()) {
+ uint32_t code = Nan::To<uint32_t>(maybe_code.ToLocalChecked()).FromJust();
+ MaybeLocal<Value> maybe_details = Nan::Get(
+ server_status, Nan::New("details").ToLocalChecked());
+ if (maybe_details.IsEmpty()) {
return false;
}
+ if (!maybe_details.ToLocalChecked()->IsString()) {
+ return false;
+ }
+ Local<String> details = Nan::To<String>(
+ maybe_details.ToLocalChecked()).ToLocalChecked();
grpc_metadata_array array;
- if (!CreateMetadataArray(server_status->Get(NanNew("metadata"))->
- ToObject(),
- &array, resources)) {
+ if (!CreateMetadataArray(metadata, &array, resources)) {
return false;
}
out->data.send_status_from_server.trailing_metadata_count = array.count;
out->data.send_status_from_server.trailing_metadata = array.metadata;
out->data.send_status_from_server.status =
- static_cast<grpc_status_code>(
- server_status->Get(NanNew("code"))->Uint32Value());
- NanUtf8String *str = new NanUtf8String(
- server_status->Get(NanNew("details")));
- resources->strings.push_back(unique_ptr<NanUtf8String>(str));
+ static_cast<grpc_status_code>(code);
+ Utf8String *str = new Utf8String(details);
+ resources->strings.push_back(unique_ptr<Utf8String>(str));
out->data.send_status_from_server.status_details = **str;
return true;
}
@@ -298,12 +332,12 @@ class GetMetadataOp : public Op {
grpc_metadata_array_destroy(&recv_metadata);
}
- Handle<Value> GetNodeValue() const {
- NanEscapableScope();
- return NanEscapeScope(ParseMetadata(&recv_metadata));
+ Local<Value> GetNodeValue() const {
+ EscapableHandleScope scope;
+ return scope.Escape(ParseMetadata(&recv_metadata));
}
- bool ParseOp(Handle<Value> value, grpc_op *out,
+ bool ParseOp(Local<Value> value, grpc_op *out,
shared_ptr<Resources> resources) {
out->data.recv_initial_metadata = &recv_metadata;
return true;
@@ -328,12 +362,12 @@ class ReadMessageOp : public Op {
gpr_free(recv_message);
}
}
- Handle<Value> GetNodeValue() const {
- NanEscapableScope();
- return NanEscapeScope(ByteBufferToBuffer(recv_message));
+ Local<Value> GetNodeValue() const {
+ EscapableHandleScope scope;
+ return scope.Escape(ByteBufferToBuffer(recv_message));
}
- bool ParseOp(Handle<Value> value, grpc_op *out,
+ bool ParseOp(Local<Value> value, grpc_op *out,
shared_ptr<Resources> resources) {
out->data.recv_message = &recv_message;
return true;
@@ -361,7 +395,7 @@ class ClientStatusOp : public Op {
gpr_free(status_details);
}
- bool ParseOp(Handle<Value> value, grpc_op *out,
+ bool ParseOp(Local<Value> value, grpc_op *out,
shared_ptr<Resources> resources) {
out->data.recv_status_on_client.trailing_metadata = &metadata_array;
out->data.recv_status_on_client.status = &status;
@@ -370,15 +404,18 @@ class ClientStatusOp : public Op {
return true;
}
- Handle<Value> GetNodeValue() const {
- NanEscapableScope();
- Handle<Object> status_obj = NanNew<Object>();
- status_obj->Set(NanNew("code"), NanNew<Number>(status));
+ Local<Value> GetNodeValue() const {
+ EscapableHandleScope scope;
+ Local<Object> status_obj = Nan::New<Object>();
+ Nan::Set(status_obj, Nan::New("code").ToLocalChecked(),
+ Nan::New<Number>(status));
if (status_details != NULL) {
- status_obj->Set(NanNew("details"), NanNew(status_details));
+ Nan::Set(status_obj, Nan::New("details").ToLocalChecked(),
+ Nan::New(status_details).ToLocalChecked());
}
- status_obj->Set(NanNew("metadata"), ParseMetadata(&metadata_array));
- return NanEscapeScope(status_obj);
+ Nan::Set(status_obj, Nan::New("metadata").ToLocalChecked(),
+ ParseMetadata(&metadata_array));
+ return scope.Escape(status_obj);
}
protected:
std::string GetTypeString() const {
@@ -393,12 +430,12 @@ class ClientStatusOp : public Op {
class ServerCloseResponseOp : public Op {
public:
- Handle<Value> GetNodeValue() const {
- NanEscapableScope();
- return NanEscapeScope(NanNew<Boolean>(cancelled));
+ Local<Value> GetNodeValue() const {
+ EscapableHandleScope scope;
+ return scope.Escape(Nan::New<Boolean>(cancelled));
}
- bool ParseOp(Handle<Value> value, grpc_op *out,
+ bool ParseOp(Local<Value> value, grpc_op *out,
shared_ptr<Resources> resources) {
out->data.recv_close_on_server.cancelled = &cancelled;
return true;
@@ -413,7 +450,7 @@ class ServerCloseResponseOp : public Op {
int cancelled;
};
-tag::tag(NanCallback *callback, OpVec *ops,
+tag::tag(Callback *callback, OpVec *ops,
shared_ptr<Resources> resources) :
callback(callback), ops(ops), resources(resources){
}
@@ -423,19 +460,19 @@ tag::~tag() {
delete ops;
}
-Handle<Value> GetTagNodeValue(void *tag) {
- NanEscapableScope();
+Local<Value> GetTagNodeValue(void *tag) {
+ EscapableHandleScope scope;
struct tag *tag_struct = reinterpret_cast<struct tag *>(tag);
- Handle<Object> tag_obj = NanNew<Object>();
+ Local<Object> tag_obj = Nan::New<Object>();
for (vector<unique_ptr<Op> >::iterator it = tag_struct->ops->begin();
it != tag_struct->ops->end(); ++it) {
Op *op_ptr = it->get();
- tag_obj->Set(op_ptr->GetOpType(), op_ptr->GetNodeValue());
+ Nan::Set(tag_obj, op_ptr->GetOpType(), op_ptr->GetNodeValue());
}
- return NanEscapeScope(tag_obj);
+ return scope.Escape(tag_obj);
}
-NanCallback *GetTagCallback(void *tag) {
+Callback *GetTagCallback(void *tag) {
struct tag *tag_struct = reinterpret_cast<struct tag *>(tag);
return tag_struct->callback;
}
@@ -452,140 +489,149 @@ Call::~Call() {
grpc_call_destroy(wrapped_call);
}
-void Call::Init(Handle<Object> exports) {
- NanScope();
- Local<FunctionTemplate> tpl = NanNew<FunctionTemplate>(New);
- tpl->SetClassName(NanNew("Call"));
+void Call::Init(Local<Object> exports) {
+ HandleScope scope;
+ Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
+ tpl->SetClassName(Nan::New("Call").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
- NanSetPrototypeTemplate(tpl, "startBatch",
- NanNew<FunctionTemplate>(StartBatch)->GetFunction());
- NanSetPrototypeTemplate(tpl, "cancel",
- NanNew<FunctionTemplate>(Cancel)->GetFunction());
- NanSetPrototypeTemplate(
- tpl, "cancelWithStatus",
- NanNew<FunctionTemplate>(CancelWithStatus)->GetFunction());
- NanSetPrototypeTemplate(tpl, "getPeer",
- NanNew<FunctionTemplate>(GetPeer)->GetFunction());
- NanAssignPersistent(fun_tpl, tpl);
- Handle<Function> ctr = tpl->GetFunction();
- exports->Set(NanNew("Call"), ctr);
- constructor = new NanCallback(ctr);
+ Nan::SetPrototypeMethod(tpl, "startBatch", StartBatch);
+ Nan::SetPrototypeMethod(tpl, "cancel", Cancel);
+ Nan::SetPrototypeMethod(tpl, "cancelWithStatus", CancelWithStatus);
+ Nan::SetPrototypeMethod(tpl, "getPeer", GetPeer);
+ fun_tpl.Reset(tpl);
+ Local<Function> ctr = Nan::GetFunction(tpl).ToLocalChecked();
+ Nan::Set(exports, Nan::New("Call").ToLocalChecked(), ctr);
+ constructor = new Callback(ctr);
}
-bool Call::HasInstance(Handle<Value> val) {
- NanScope();
- return NanHasInstance(fun_tpl, val);
+bool Call::HasInstance(Local<Value> val) {
+ HandleScope scope;
+ return Nan::New(fun_tpl)->HasInstance(val);
}
-Handle<Value> Call::WrapStruct(grpc_call *call) {
- NanEscapableScope();
+Local<Value> Call::WrapStruct(grpc_call *call) {
+ EscapableHandleScope scope;
if (call == NULL) {
- return NanEscapeScope(NanNull());
+ return scope.Escape(Nan::Null());
}
const int argc = 1;
- Handle<Value> argv[argc] = {NanNew<External>(reinterpret_cast<void *>(call))};
- return NanEscapeScope(constructor->GetFunction()->NewInstance(argc, argv));
+ Local<Value> argv[argc] = {Nan::New<External>(
+ reinterpret_cast<void *>(call))};
+ MaybeLocal<Object> maybe_instance = Nan::NewInstance(
+ constructor->GetFunction(), argc, argv);
+ if (maybe_instance.IsEmpty()) {
+ return scope.Escape(Nan::Null());
+ } else {
+ return scope.Escape(maybe_instance.ToLocalChecked());
+ }
}
NAN_METHOD(Call::New) {
- NanScope();
-
- if (args.IsConstructCall()) {
+ if (info.IsConstructCall()) {
Call *call;
- if (args[0]->IsExternal()) {
- Handle<External> ext = args[0].As<External>();
+ if (info[0]->IsExternal()) {
+ Local<External> ext = info[0].As<External>();
// This option is used for wrapping an existing call
grpc_call *call_value =
reinterpret_cast<grpc_call *>(ext->Value());
call = new Call(call_value);
} else {
- if (!Channel::HasInstance(args[0])) {
- return NanThrowTypeError("Call's first argument must be a Channel");
+ if (!Channel::HasInstance(info[0])) {
+ return Nan::ThrowTypeError("Call's first argument must be a Channel");
}
- if (!args[1]->IsString()) {
- return NanThrowTypeError("Call's second argument must be a string");
+ if (!info[1]->IsString()) {
+ return Nan::ThrowTypeError("Call's second argument must be a string");
}
- if (!(args[2]->IsNumber() || args[2]->IsDate())) {
- return NanThrowTypeError(
+ if (!(info[2]->IsNumber() || info[2]->IsDate())) {
+ return Nan::ThrowTypeError(
"Call's third argument must be a date or a number");
}
// These arguments are at the end because they are optional
grpc_call *parent_call = NULL;
- if (Call::HasInstance(args[4])) {
- Call *parent_obj = ObjectWrap::Unwrap<Call>(args[4]->ToObject());
+ if (Call::HasInstance(info[4])) {
+ Call *parent_obj = ObjectWrap::Unwrap<Call>(
+ Nan::To<Object>(info[4]).ToLocalChecked());
parent_call = parent_obj->wrapped_call;
- } else if (!(args[4]->IsUndefined() || args[4]->IsNull())) {
- return NanThrowTypeError(
+ } else if (!(info[4]->IsUndefined() || info[4]->IsNull())) {
+ return Nan::ThrowTypeError(
"Call's fifth argument must be another call, if provided");
}
gpr_uint32 propagate_flags = GRPC_PROPAGATE_DEFAULTS;
- if (args[5]->IsUint32()) {
- propagate_flags = args[5]->Uint32Value();
- } else if (!(args[5]->IsUndefined() || args[5]->IsNull())) {
- return NanThrowTypeError(
+ if (info[5]->IsUint32()) {
+ propagate_flags = Nan::To<uint32_t>(info[5]).FromJust();
+ } else if (!(info[5]->IsUndefined() || info[5]->IsNull())) {
+ return Nan::ThrowTypeError(
"Call's sixth argument must be propagate flags, if provided");
}
- Handle<Object> channel_object = args[0]->ToObject();
+ Local<Object> channel_object = Nan::To<Object>(info[0]).ToLocalChecked();
Channel *channel = ObjectWrap::Unwrap<Channel>(channel_object);
if (channel->GetWrappedChannel() == NULL) {
- return NanThrowError("Call cannot be created from a closed channel");
+ return Nan::ThrowError("Call cannot be created from a closed channel");
}
- NanUtf8String method(args[1]);
- double deadline = args[2]->NumberValue();
+ Utf8String method(info[1]);
+ double deadline = Nan::To<double>(info[2]).FromJust();
grpc_channel *wrapped_channel = channel->GetWrappedChannel();
grpc_call *wrapped_call;
- if (args[3]->IsString()) {
- NanUtf8String host_override(args[3]);
+ if (info[3]->IsString()) {
+ Utf8String host_override(info[3]);
wrapped_call = grpc_channel_create_call(
wrapped_channel, parent_call, propagate_flags,
CompletionQueueAsyncWorker::GetQueue(), *method,
*host_override, MillisecondsToTimespec(deadline), NULL);
- } else if (args[3]->IsUndefined() || args[3]->IsNull()) {
+ } else if (info[3]->IsUndefined() || info[3]->IsNull()) {
wrapped_call = grpc_channel_create_call(
wrapped_channel, parent_call, propagate_flags,
CompletionQueueAsyncWorker::GetQueue(), *method,
NULL, MillisecondsToTimespec(deadline), NULL);
} else {
- return NanThrowTypeError("Call's fourth argument must be a string");
+ return Nan::ThrowTypeError("Call's fourth argument must be a string");
}
call = new Call(wrapped_call);
- args.This()->SetHiddenValue(NanNew("channel_"), channel_object);
+ info.This()->SetHiddenValue(Nan::New("channel_").ToLocalChecked(),
+ channel_object);
}
- call->Wrap(args.This());
- NanReturnValue(args.This());
+ call->Wrap(info.This());
+ info.GetReturnValue().Set(info.This());
} else {
const int argc = 4;
- Local<Value> argv[argc] = {args[0], args[1], args[2], args[3]};
- NanReturnValue(constructor->GetFunction()->NewInstance(argc, argv));
+ Local<Value> argv[argc] = {info[0], info[1], info[2], info[3]};
+ MaybeLocal<Object> maybe_instance = constructor->GetFunction()->NewInstance(
+ argc, argv);
+ if (maybe_instance.IsEmpty()) {
+ // There's probably a pending exception
+ return;
+ } else {
+ info.GetReturnValue().Set(maybe_instance.ToLocalChecked());
+ }
}
}
NAN_METHOD(Call::StartBatch) {
- NanScope();
- if (!HasInstance(args.This())) {
- return NanThrowTypeError("startBatch can only be called on Call objects");
+ if (!Call::HasInstance(info.This())) {
+ return Nan::ThrowTypeError("startBatch can only be called on Call objects");
}
- if (!args[0]->IsObject()) {
- return NanThrowError("startBatch's first argument must be an object");
+ if (!info[0]->IsObject()) {
+ return Nan::ThrowError("startBatch's first argument must be an object");
}
- if (!args[1]->IsFunction()) {
- return NanThrowError("startBatch's second argument must be a callback");
+ if (!info[1]->IsFunction()) {
+ return Nan::ThrowError("startBatch's second argument must be a callback");
}
- Handle<Function> callback_func = args[1].As<Function>();
- Call *call = ObjectWrap::Unwrap<Call>(args.This());
+ Local<Function> callback_func = info[1].As<Function>();
+ Call *call = ObjectWrap::Unwrap<Call>(info.This());
shared_ptr<Resources> resources(new Resources);
- Handle<Object> obj = args[0]->ToObject();
- Handle<Array> keys = obj->GetOwnPropertyNames();
+ Local<Object> obj = Nan::To<Object>(info[0]).ToLocalChecked();
+ Local<Array> keys = Nan::GetOwnPropertyNames(obj).ToLocalChecked();
size_t nops = keys->Length();
vector<grpc_op> ops(nops);
unique_ptr<OpVec> op_vector(new OpVec());
for (unsigned int i = 0; i < nops; i++) {
unique_ptr<Op> op;
- if (!keys->Get(i)->IsUint32()) {
- return NanThrowError(
+ MaybeLocal<Value> maybe_key = Nan::Get(keys, i);
+ if (maybe_key.IsEmpty() || (!maybe_key.ToLocalChecked()->IsUint32())) {
+ return Nan::ThrowError(
"startBatch's first argument's keys must be integers");
}
- uint32_t type = keys->Get(i)->Uint32Value();
+ uint32_t type = Nan::To<uint32_t>(maybe_key.ToLocalChecked()).FromJust();
ops[i].op = static_cast<grpc_op_type>(type);
ops[i].flags = 0;
ops[i].reserved = NULL;
@@ -615,67 +661,64 @@ NAN_METHOD(Call::StartBatch) {
op.reset(new ServerCloseResponseOp());
break;
default:
- return NanThrowError("Argument object had an unrecognized key");
+ return Nan::ThrowError("Argument object had an unrecognized key");
}
if (!op->ParseOp(obj->Get(type), &ops[i], resources)) {
- return NanThrowTypeError("Incorrectly typed arguments to startBatch");
+ return Nan::ThrowTypeError("Incorrectly typed arguments to startBatch");
}
op_vector->push_back(std::move(op));
}
- NanCallback *callback = new NanCallback(callback_func);
+ Callback *callback = new Callback(callback_func);
grpc_call_error error = grpc_call_start_batch(
call->wrapped_call, &ops[0], nops, new struct tag(
callback, op_vector.release(), resources), NULL);
if (error != GRPC_CALL_OK) {
- return NanThrowError(nanErrorWithCode("startBatch failed", error));
+ return Nan::ThrowError(nanErrorWithCode("startBatch failed", error));
}
CompletionQueueAsyncWorker::Next();
- NanReturnUndefined();
}
NAN_METHOD(Call::Cancel) {
- NanScope();
- if (!HasInstance(args.This())) {
- return NanThrowTypeError("cancel can only be called on Call objects");
+ if (!Call::HasInstance(info.This())) {
+ return Nan::ThrowTypeError("cancel can only be called on Call objects");
}
- Call *call = ObjectWrap::Unwrap<Call>(args.This());
+ Call *call = ObjectWrap::Unwrap<Call>(info.This());
grpc_call_error error = grpc_call_cancel(call->wrapped_call, NULL);
if (error != GRPC_CALL_OK) {
- return NanThrowError(nanErrorWithCode("cancel failed", error));
+ return Nan::ThrowError(nanErrorWithCode("cancel failed", error));
}
- NanReturnUndefined();
}
NAN_METHOD(Call::CancelWithStatus) {
- NanScope();
- if (!HasInstance(args.This())) {
- return NanThrowTypeError("cancel can only be called on Call objects");
+ Nan::HandleScope scope;
+ if (!HasInstance(info.This())) {
+ return Nan::ThrowTypeError("cancel can only be called on Call objects");
}
- if (!args[0]->IsUint32()) {
- return NanThrowTypeError(
+ if (!info[0]->IsUint32()) {
+ return Nan::ThrowTypeError(
"cancelWithStatus's first argument must be a status code");
}
- if (!args[1]->IsString()) {
- return NanThrowTypeError(
+ if (!info[1]->IsString()) {
+ return Nan::ThrowTypeError(
"cancelWithStatus's second argument must be a string");
}
- Call *call = ObjectWrap::Unwrap<Call>(args.This());
- grpc_status_code code = static_cast<grpc_status_code>(args[0]->Uint32Value());
- NanUtf8String details(args[0]);
+ Call *call = ObjectWrap::Unwrap<Call>(info.This());
+ grpc_status_code code = static_cast<grpc_status_code>(
+ Nan::To<uint32_t>(info[0]).FromJust());
+ Utf8String details(info[0]);
grpc_call_cancel_with_status(call->wrapped_call, code, *details, NULL);
- NanReturnUndefined();
}
NAN_METHOD(Call::GetPeer) {
- NanScope();
- if (!HasInstance(args.This())) {
- return NanThrowTypeError("getPeer can only be called on Call objects");
+ Nan::HandleScope scope;
+ if (!HasInstance(info.This())) {
+ return Nan::ThrowTypeError("getPeer can only be called on Call objects");
}
- Call *call = ObjectWrap::Unwrap<Call>(args.This());
+ Call *call = ObjectWrap::Unwrap<Call>(info.This());
char *peer = grpc_call_get_peer(call->wrapped_call);
- Handle<Value> peer_value = NanNew(peer);
+ Local<Value> peer_value = Nan::New(peer).ToLocalChecked();
gpr_free(peer);
- NanReturnValue(peer_value);
+ info.GetReturnValue().Set(peer_value);
}
} // namespace node
diff --git a/src/node/ext/call.h b/src/node/ext/call.h
index 89f81dcf4d..1f387edc64 100644
--- a/src/node/ext/call.h
+++ b/src/node/ext/call.h
@@ -51,6 +51,8 @@ namespace node {
using std::unique_ptr;
using std::shared_ptr;
+typedef Nan::Persistent<v8::Value, Nan::CopyablePersistentTraits<v8::Value>> PersistentValue;
+
/**
* Helper function for throwing errors with a grpc_call_error value.
* Modified from the answer by Gus Goose to
@@ -58,40 +60,25 @@ using std::shared_ptr;
*/
inline v8::Local<v8::Value> nanErrorWithCode(const char *msg,
grpc_call_error code) {
- NanEscapableScope();
- v8::Local<v8::Object> err = NanError(msg).As<v8::Object>();
- err->Set(NanNew("code"), NanNew<v8::Uint32>(code));
- return NanEscapeScope(err);
+ Nan::EscapableHandleScope scope;
+ v8::Local<v8::Object> err = Nan::Error(msg).As<v8::Object>();
+ Nan::Set(err, Nan::New("code").ToLocalChecked(), Nan::New<v8::Uint32>(code));
+ return scope.Escape(err);
}
-v8::Handle<v8::Value> ParseMetadata(const grpc_metadata_array *metadata_array);
-
-class PersistentHolder {
- public:
- explicit PersistentHolder(v8::Persistent<v8::Value> *persist) :
- persist(persist) {
- }
-
- ~PersistentHolder() {
- NanDisposePersistent(*persist);
- delete persist;
- }
-
- private:
- v8::Persistent<v8::Value> *persist;
-};
+v8::Local<v8::Value> ParseMetadata(const grpc_metadata_array *metadata_array);
struct Resources {
- std::vector<unique_ptr<NanUtf8String> > strings;
- std::vector<unique_ptr<PersistentHolder> > handles;
+ std::vector<unique_ptr<Nan::Utf8String> > strings;
+ std::vector<unique_ptr<PersistentValue> > handles;
};
class Op {
public:
- virtual v8::Handle<v8::Value> GetNodeValue() const = 0;
- virtual bool ParseOp(v8::Handle<v8::Value> value, grpc_op *out,
+ virtual v8::Local<v8::Value> GetNodeValue() const = 0;
+ virtual bool ParseOp(v8::Local<v8::Value> value, grpc_op *out,
shared_ptr<Resources> resources) = 0;
- v8::Handle<v8::Value> GetOpType() const;
+ v8::Local<v8::Value> GetOpType() const;
protected:
virtual std::string GetTypeString() const = 0;
@@ -100,27 +87,27 @@ class Op {
typedef std::vector<unique_ptr<Op>> OpVec;
struct tag {
- tag(NanCallback *callback, OpVec *ops,
+ tag(Nan::Callback *callback, OpVec *ops,
shared_ptr<Resources> resources);
~tag();
- NanCallback *callback;
+ Nan::Callback *callback;
OpVec *ops;
shared_ptr<Resources> resources;
};
-v8::Handle<v8::Value> GetTagNodeValue(void *tag);
+v8::Local<v8::Value> GetTagNodeValue(void *tag);
-NanCallback *GetTagCallback(void *tag);
+Nan::Callback *GetTagCallback(void *tag);
void DestroyTag(void *tag);
/* Wrapper class for grpc_call structs. */
-class Call : public ::node::ObjectWrap {
+class Call : public Nan::ObjectWrap {
public:
- static void Init(v8::Handle<v8::Object> exports);
- static bool HasInstance(v8::Handle<v8::Value> val);
+ static void Init(v8::Local<v8::Object> exports);
+ static bool HasInstance(v8::Local<v8::Value> val);
/* Wrap a grpc_call struct in a javascript object */
- static v8::Handle<v8::Value> WrapStruct(grpc_call *call);
+ static v8::Local<v8::Value> WrapStruct(grpc_call *call);
private:
explicit Call(grpc_call *call);
@@ -135,9 +122,9 @@ class Call : public ::node::ObjectWrap {
static NAN_METHOD(Cancel);
static NAN_METHOD(CancelWithStatus);
static NAN_METHOD(GetPeer);
- static NanCallback *constructor;
+ static Nan::Callback *constructor;
// Used for typechecking instances of this javascript class
- static v8::Persistent<v8::FunctionTemplate> fun_tpl;
+ static Nan::Persistent<v8::FunctionTemplate> fun_tpl;
grpc_call *wrapped_call;
};
diff --git a/src/node/ext/channel.cc b/src/node/ext/channel.cc
index 9aed96bbf5..6eb1e77688 100644
--- a/src/node/ext/channel.cc
+++ b/src/node/ext/channel.cc
@@ -48,21 +48,27 @@
namespace grpc {
namespace node {
+using Nan::Callback;
+using Nan::EscapableHandleScope;
+using Nan::HandleScope;
+using Nan::Maybe;
+using Nan::MaybeLocal;
+using Nan::ObjectWrap;
+using Nan::Persistent;
+using Nan::Utf8String;
+
using v8::Array;
using v8::Exception;
using v8::Function;
using v8::FunctionTemplate;
-using v8::Handle;
-using v8::HandleScope;
using v8::Integer;
using v8::Local;
using v8::Number;
using v8::Object;
-using v8::Persistent;
using v8::String;
using v8::Value;
-NanCallback *Channel::constructor;
+Callback *Channel::constructor;
Persistent<FunctionTemplate> Channel::fun_tpl;
Channel::Channel(grpc_channel *channel) : wrapped_channel(channel) {}
@@ -73,88 +79,89 @@ Channel::~Channel() {
}
}
-void Channel::Init(Handle<Object> exports) {
- NanScope();
- Local<FunctionTemplate> tpl = NanNew<FunctionTemplate>(New);
- tpl->SetClassName(NanNew("Channel"));
+void Channel::Init(Local<Object> exports) {
+ Nan::HandleScope scope;
+ Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
+ tpl->SetClassName(Nan::New("Channel").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
- NanSetPrototypeTemplate(tpl, "close",
- NanNew<FunctionTemplate>(Close)->GetFunction());
- NanSetPrototypeTemplate(tpl, "getTarget",
- NanNew<FunctionTemplate>(GetTarget)->GetFunction());
- NanSetPrototypeTemplate(
- tpl, "getConnectivityState",
- NanNew<FunctionTemplate>(GetConnectivityState)->GetFunction());
- NanSetPrototypeTemplate(
- tpl, "watchConnectivityState",
- NanNew<FunctionTemplate>(WatchConnectivityState)->GetFunction());
- NanAssignPersistent(fun_tpl, tpl);
- Handle<Function> ctr = tpl->GetFunction();
- constructor = new NanCallback(ctr);
- exports->Set(NanNew("Channel"), ctr);
+ Nan::SetPrototypeMethod(tpl, "close", Close);
+ Nan::SetPrototypeMethod(tpl, "getTarget", GetTarget);
+ Nan::SetPrototypeMethod(tpl, "getConnectivityState", GetConnectivityState);
+ Nan::SetPrototypeMethod(tpl, "watchConnectivityState",
+ WatchConnectivityState);
+ fun_tpl.Reset(tpl);
+ Local<Function> ctr = Nan::GetFunction(tpl).ToLocalChecked();
+ Nan::Set(exports, Nan::New("Channel").ToLocalChecked(), ctr);
+ constructor = new Callback(ctr);
}
-bool Channel::HasInstance(Handle<Value> val) {
- NanScope();
- return NanHasInstance(fun_tpl, val);
+bool Channel::HasInstance(Local<Value> val) {
+ HandleScope scope;
+ return Nan::New(fun_tpl)->HasInstance(val);
}
grpc_channel *Channel::GetWrappedChannel() { return this->wrapped_channel; }
NAN_METHOD(Channel::New) {
- NanScope();
-
- if (args.IsConstructCall()) {
- if (!args[0]->IsString()) {
- return NanThrowTypeError(
+ if (info.IsConstructCall()) {
+ if (!info[0]->IsString()) {
+ return Nan::ThrowTypeError(
"Channel expects a string, a credential and an object");
}
grpc_channel *wrapped_channel;
// Owned by the Channel object
- NanUtf8String host(args[0]);
+ Utf8String host(info[0]);
grpc_credentials *creds;
- if (!Credentials::HasInstance(args[1])) {
- return NanThrowTypeError(
+ if (!Credentials::HasInstance(info[1])) {
+ return Nan::ThrowTypeError(
"Channel's second argument must be a credential");
}
Credentials *creds_object = ObjectWrap::Unwrap<Credentials>(
- args[1]->ToObject());
+ Nan::To<Object>(info[1]).ToLocalChecked());
creds = creds_object->GetWrappedCredentials();
grpc_channel_args *channel_args_ptr;
- if (args[2]->IsUndefined()) {
+ if (info[2]->IsUndefined()) {
channel_args_ptr = NULL;
wrapped_channel = grpc_insecure_channel_create(*host, NULL, NULL);
- } else if (args[2]->IsObject()) {
- Handle<Object> args_hash(args[2]->ToObject()->Clone());
- Handle<Array> keys(args_hash->GetOwnPropertyNames());
+ } else if (info[2]->IsObject()) {
+ Local<Object> args_hash = Nan::To<Object>(info[2]).ToLocalChecked();
+ Local<Array> keys(Nan::GetOwnPropertyNames(args_hash).ToLocalChecked());
grpc_channel_args channel_args;
channel_args.num_args = keys->Length();
channel_args.args = reinterpret_cast<grpc_arg *>(
calloc(channel_args.num_args, sizeof(grpc_arg)));
/* These are used to keep all strings until then end of the block, then
destroy them */
- std::vector<NanUtf8String *> key_strings(keys->Length());
- std::vector<NanUtf8String *> value_strings(keys->Length());
+ std::vector<Nan::Utf8String *> key_strings(keys->Length());
+ std::vector<Nan::Utf8String *> value_strings(keys->Length());
for (unsigned int i = 0; i < channel_args.num_args; i++) {
- Handle<String> current_key(keys->Get(i)->ToString());
- Handle<Value> current_value(args_hash->Get(current_key));
- key_strings[i] = new NanUtf8String(current_key);
+ MaybeLocal<String> maybe_key = Nan::To<String>(
+ Nan::Get(keys, i).ToLocalChecked());
+ if (maybe_key.IsEmpty()) {
+ free(channel_args.args);
+ return Nan::ThrowTypeError("Arg keys must be strings");
+ }
+ Local<String> current_key = maybe_key.ToLocalChecked();
+ Local<Value> current_value = Nan::Get(args_hash,
+ current_key).ToLocalChecked();
+ key_strings[i] = new Nan::Utf8String(current_key);
channel_args.args[i].key = **key_strings[i];
if (current_value->IsInt32()) {
channel_args.args[i].type = GRPC_ARG_INTEGER;
- channel_args.args[i].value.integer = current_value->Int32Value();
+ channel_args.args[i].value.integer = Nan::To<int32_t>(
+ current_value).FromJust();
} else if (current_value->IsString()) {
channel_args.args[i].type = GRPC_ARG_STRING;
- value_strings[i] = new NanUtf8String(current_value);
+ value_strings[i] = new Nan::Utf8String(current_value);
channel_args.args[i].value.string = **value_strings[i];
} else {
free(channel_args.args);
- return NanThrowTypeError("Arg values must be strings");
+ return Nan::ThrowTypeError("Arg values must be strings");
}
}
channel_args_ptr = &channel_args;
} else {
- return NanThrowTypeError("Channel expects a string and an object");
+ return Nan::ThrowTypeError("Channel expects a string and an object");
}
if (creds == NULL) {
wrapped_channel = grpc_insecure_channel_create(*host, channel_args_ptr,
@@ -167,73 +174,79 @@ NAN_METHOD(Channel::New) {
free(channel_args_ptr->args);
}
Channel *channel = new Channel(wrapped_channel);
- channel->Wrap(args.This());
- NanReturnValue(args.This());
+ channel->Wrap(info.This());
+ info.GetReturnValue().Set(info.This());
+ return;
} else {
const int argc = 3;
- Local<Value> argv[argc] = {args[0], args[1], args[2]};
- NanReturnValue(constructor->GetFunction()->NewInstance(argc, argv));
+ Local<Value> argv[argc] = {info[0], info[1], info[2]};
+ MaybeLocal<Object> maybe_instance = constructor->GetFunction()->NewInstance(
+ argc, argv);
+ if (maybe_instance.IsEmpty()) {
+ // There's probably a pending exception
+ return;
+ } else {
+ info.GetReturnValue().Set(maybe_instance.ToLocalChecked());
+ }
}
}
NAN_METHOD(Channel::Close) {
- NanScope();
- if (!HasInstance(args.This())) {
- return NanThrowTypeError("close can only be called on Channel objects");
+ if (!HasInstance(info.This())) {
+ return Nan::ThrowTypeError("close can only be called on Channel objects");
}
- Channel *channel = ObjectWrap::Unwrap<Channel>(args.This());
+ Channel *channel = ObjectWrap::Unwrap<Channel>(info.This());
if (channel->wrapped_channel != NULL) {
grpc_channel_destroy(channel->wrapped_channel);
channel->wrapped_channel = NULL;
}
- NanReturnUndefined();
}
NAN_METHOD(Channel::GetTarget) {
- NanScope();
- if (!HasInstance(args.This())) {
- return NanThrowTypeError("getTarget can only be called on Channel objects");
+ if (!HasInstance(info.This())) {
+ return Nan::ThrowTypeError("getTarget can only be called on Channel objects");
}
- Channel *channel = ObjectWrap::Unwrap<Channel>(args.This());
- NanReturnValue(NanNew(grpc_channel_get_target(channel->wrapped_channel)));
+ Channel *channel = ObjectWrap::Unwrap<Channel>(info.This());
+ info.GetReturnValue().Set(Nan::New(
+ grpc_channel_get_target(channel->wrapped_channel)).ToLocalChecked());
}
NAN_METHOD(Channel::GetConnectivityState) {
- NanScope();
- if (!HasInstance(args.This())) {
- return NanThrowTypeError(
+ if (!HasInstance(info.This())) {
+ return Nan::ThrowTypeError(
"getConnectivityState can only be called on Channel objects");
}
- Channel *channel = ObjectWrap::Unwrap<Channel>(args.This());
- int try_to_connect = (int)args[0]->Equals(NanTrue());
- NanReturnValue(grpc_channel_check_connectivity_state(channel->wrapped_channel,
- try_to_connect));
+ Channel *channel = ObjectWrap::Unwrap<Channel>(info.This());
+ int try_to_connect = (int)info[0]->Equals(Nan::True());
+ info.GetReturnValue().Set(
+ grpc_channel_check_connectivity_state(channel->wrapped_channel,
+ try_to_connect));
}
NAN_METHOD(Channel::WatchConnectivityState) {
- NanScope();
- if (!HasInstance(args.This())) {
- return NanThrowTypeError(
+ if (!HasInstance(info.This())) {
+ return Nan::ThrowTypeError(
"watchConnectivityState can only be called on Channel objects");
}
- if (!args[0]->IsUint32()) {
- return NanThrowTypeError(
+ if (!info[0]->IsUint32()) {
+ return Nan::ThrowTypeError(
"watchConnectivityState's first argument must be a channel state");
}
- if (!(args[1]->IsNumber() || args[1]->IsDate())) {
- return NanThrowTypeError(
+ if (!(info[1]->IsNumber() || info[1]->IsDate())) {
+ return Nan::ThrowTypeError(
"watchConnectivityState's second argument must be a date or a number");
}
- if (!args[2]->IsFunction()) {
- return NanThrowTypeError(
+ if (!info[2]->IsFunction()) {
+ return Nan::ThrowTypeError(
"watchConnectivityState's third argument must be a callback");
}
grpc_connectivity_state last_state =
- static_cast<grpc_connectivity_state>(args[0]->Uint32Value());
- double deadline = args[1]->NumberValue();
- Handle<Function> callback_func = args[2].As<Function>();
- NanCallback *callback = new NanCallback(callback_func);
- Channel *channel = ObjectWrap::Unwrap<Channel>(args.This());
+ static_cast<grpc_connectivity_state>(
+ Nan::To<uint32_t>(info[0]).FromJust());
+ double deadline = Nan::To<double>(info[1]).FromJust();
+ Local<Function> callback_func = info[2].As<Function>();
+ Nan::Callback *callback = new Callback(callback_func);
+ Channel *channel = ObjectWrap::Unwrap<Channel>(info.This());
unique_ptr<OpVec> ops(new OpVec());
grpc_channel_watch_connectivity_state(
channel->wrapped_channel, last_state, MillisecondsToTimespec(deadline),
@@ -242,7 +255,6 @@ NAN_METHOD(Channel::WatchConnectivityState) {
ops.release(),
shared_ptr<Resources>(nullptr)));
CompletionQueueAsyncWorker::Next();
- NanReturnUndefined();
}
} // namespace node
diff --git a/src/node/ext/channel.h b/src/node/ext/channel.h
index 458f71d093..0062fd03f4 100644
--- a/src/node/ext/channel.h
+++ b/src/node/ext/channel.h
@@ -42,10 +42,10 @@ namespace grpc {
namespace node {
/* Wrapper class for grpc_channel structs */
-class Channel : public ::node::ObjectWrap {
+class Channel : public Nan::ObjectWrap {
public:
- static void Init(v8::Handle<v8::Object> exports);
- static bool HasInstance(v8::Handle<v8::Value> val);
+ static void Init(v8::Local<v8::Object> exports);
+ static bool HasInstance(v8::Local<v8::Value> val);
/* This is used to typecheck javascript objects before converting them to
this type */
static v8::Persistent<v8::Value> prototype;
@@ -66,8 +66,8 @@ class Channel : public ::node::ObjectWrap {
static NAN_METHOD(GetTarget);
static NAN_METHOD(GetConnectivityState);
static NAN_METHOD(WatchConnectivityState);
- static NanCallback *constructor;
- static v8::Persistent<v8::FunctionTemplate> fun_tpl;
+ static Nan::Callback *constructor;
+ static Nan::Persistent<v8::FunctionTemplate> fun_tpl;
grpc_channel *wrapped_channel;
};
diff --git a/src/node/ext/completion_queue_async_worker.cc b/src/node/ext/completion_queue_async_worker.cc
index bf2cd946a5..3a79f7c45d 100644
--- a/src/node/ext/completion_queue_async_worker.cc
+++ b/src/node/ext/completion_queue_async_worker.cc
@@ -46,9 +46,8 @@ namespace node {
const int max_queue_threads = 2;
using v8::Function;
-using v8::Handle;
+using v8::Local;
using v8::Object;
-using v8::Persistent;
using v8::Value;
grpc_completion_queue *CompletionQueueAsyncWorker::queue;
@@ -57,7 +56,7 @@ int CompletionQueueAsyncWorker::current_threads;
int CompletionQueueAsyncWorker::waiting_next_calls;
CompletionQueueAsyncWorker::CompletionQueueAsyncWorker()
- : NanAsyncWorker(NULL) {}
+ : Nan::AsyncWorker(NULL) {}
CompletionQueueAsyncWorker::~CompletionQueueAsyncWorker() {}
@@ -72,42 +71,42 @@ void CompletionQueueAsyncWorker::Execute() {
grpc_completion_queue *CompletionQueueAsyncWorker::GetQueue() { return queue; }
void CompletionQueueAsyncWorker::Next() {
- NanScope();
+ Nan::HandleScope scope;
if (current_threads < max_queue_threads) {
CompletionQueueAsyncWorker *worker = new CompletionQueueAsyncWorker();
- NanAsyncQueueWorker(worker);
+ Nan::AsyncQueueWorker(worker);
} else {
waiting_next_calls += 1;
}
}
-void CompletionQueueAsyncWorker::Init(Handle<Object> exports) {
- NanScope();
+void CompletionQueueAsyncWorker::Init(Local<Object> exports) {
+ Nan::HandleScope scope;
current_threads = 0;
waiting_next_calls = 0;
queue = grpc_completion_queue_create(NULL);
}
void CompletionQueueAsyncWorker::HandleOKCallback() {
- NanScope();
+ Nan::HandleScope scope;
if (waiting_next_calls > 0) {
waiting_next_calls -= 1;
CompletionQueueAsyncWorker *worker = new CompletionQueueAsyncWorker();
- NanAsyncQueueWorker(worker);
+ Nan::AsyncQueueWorker(worker);
} else {
current_threads -= 1;
}
- NanCallback *callback = GetTagCallback(result.tag);
- Handle<Value> argv[] = {NanNull(), GetTagNodeValue(result.tag)};
+ Nan::Callback *callback = GetTagCallback(result.tag);
+ Local<Value> argv[] = {Nan::Null(), GetTagNodeValue(result.tag)};
callback->Call(2, argv);
DestroyTag(result.tag);
}
void CompletionQueueAsyncWorker::HandleErrorCallback() {
- NanScope();
- NanCallback *callback = GetTagCallback(result.tag);
- Handle<Value> argv[] = {NanError(ErrorMessage())};
+ Nan::HandleScope scope;
+ Nan::Callback *callback = GetTagCallback(result.tag);
+ Local<Value> argv[] = {Nan::Error(ErrorMessage())};
callback->Call(1, argv);
diff --git a/src/node/ext/completion_queue_async_worker.h b/src/node/ext/completion_queue_async_worker.h
index 27fedf2fce..6e54116765 100644
--- a/src/node/ext/completion_queue_async_worker.h
+++ b/src/node/ext/completion_queue_async_worker.h
@@ -42,7 +42,7 @@ namespace node {
/* A worker that asynchronously calls completion_queue_next, and queues onto the
node event loop a call to the function stored in the event's tag. */
-class CompletionQueueAsyncWorker : public NanAsyncWorker {
+class CompletionQueueAsyncWorker : public Nan::AsyncWorker {
public:
CompletionQueueAsyncWorker();
@@ -59,7 +59,7 @@ class CompletionQueueAsyncWorker : public NanAsyncWorker {
static void Next();
/* Initialize the CompletionQueueAsyncWorker class */
- static void Init(v8::Handle<v8::Object> exports);
+ static void Init(v8::Local<v8::Object> exports);
protected:
/* Called when Execute has succeeded (completed without setting an error
diff --git a/src/node/ext/credentials.cc b/src/node/ext/credentials.cc
index c3b04dcea7..4f41c92f6a 100644
--- a/src/node/ext/credentials.cc
+++ b/src/node/ext/credentials.cc
@@ -41,20 +41,26 @@
namespace grpc {
namespace node {
+using Nan::Callback;
+using Nan::EscapableHandleScope;
+using Nan::HandleScope;
+using Nan::Maybe;
+using Nan::MaybeLocal;
+using Nan::ObjectWrap;
+using Nan::Persistent;
+using Nan::Utf8String;
+
using v8::Exception;
using v8::External;
using v8::Function;
using v8::FunctionTemplate;
-using v8::Handle;
-using v8::HandleScope;
using v8::Integer;
using v8::Local;
using v8::Object;
using v8::ObjectTemplate;
-using v8::Persistent;
using v8::Value;
-NanCallback *Credentials::constructor;
+Nan::Callback *Credentials::constructor;
Persistent<FunctionTemplate> Credentials::fun_tpl;
Credentials::Credentials(grpc_credentials *credentials)
@@ -64,40 +70,52 @@ Credentials::~Credentials() {
grpc_credentials_release(wrapped_credentials);
}
-void Credentials::Init(Handle<Object> exports) {
- NanScope();
- Local<FunctionTemplate> tpl = NanNew<FunctionTemplate>(New);
- tpl->SetClassName(NanNew("Credentials"));
+void Credentials::Init(Local<Object> exports) {
+ HandleScope scope;
+ Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
+ tpl->SetClassName(Nan::New("Credentials").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
- NanAssignPersistent(fun_tpl, tpl);
- 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("createIam"),
- NanNew<FunctionTemplate>(CreateIam)->GetFunction());
- ctr->Set(NanNew("createInsecure"),
- NanNew<FunctionTemplate>(CreateInsecure)->GetFunction());
- constructor = new NanCallback(ctr);
- exports->Set(NanNew("Credentials"), ctr);
+ fun_tpl.Reset(tpl);
+ Local<Function> ctr = Nan::GetFunction(tpl).ToLocalChecked();
+ Nan::Set(ctr, Nan::New("createDefault").ToLocalChecked(),
+ Nan::GetFunction(
+ Nan::New<FunctionTemplate>(CreateDefault)).ToLocalChecked());
+ Nan::Set(ctr, Nan::New("createSsl").ToLocalChecked(),
+ Nan::GetFunction(
+ Nan::New<FunctionTemplate>(CreateSsl)).ToLocalChecked());
+ Nan::Set(ctr, Nan::New("createComposite").ToLocalChecked(),
+ Nan::GetFunction(
+ Nan::New<FunctionTemplate>(CreateComposite)).ToLocalChecked());
+ Nan::Set(ctr, Nan::New("createGce").ToLocalChecked(),
+ Nan::GetFunction(
+ Nan::New<FunctionTemplate>(CreateGce)).ToLocalChecked());
+ Nan::Set(ctr, Nan::New("createIam").ToLocalChecked(),
+ Nan::GetFunction(
+ Nan::New<FunctionTemplate>(CreateIam)).ToLocalChecked());
+ Nan::Set(ctr, Nan::New("createInsecure").ToLocalChecked(),
+ Nan::GetFunction(
+ Nan::New<FunctionTemplate>(CreateInsecure)).ToLocalChecked());
+ Nan::Set(exports, Nan::New("Credentials").ToLocalChecked(), ctr);
+ constructor = new Nan::Callback(ctr);
}
-bool Credentials::HasInstance(Handle<Value> val) {
- NanScope();
- return NanHasInstance(fun_tpl, val);
+bool Credentials::HasInstance(Local<Value> val) {
+ HandleScope scope;
+ return Nan::New(fun_tpl)->HasInstance(val);
}
-Handle<Value> Credentials::WrapStruct(grpc_credentials *credentials) {
- NanEscapableScope();
+Local<Value> Credentials::WrapStruct(grpc_credentials *credentials) {
+ EscapableHandleScope scope;
const int argc = 1;
- Handle<Value> argv[argc] = {
- NanNew<External>(reinterpret_cast<void *>(credentials))};
- return NanEscapeScope(constructor->GetFunction()->NewInstance(argc, argv));
+ Local<Value> argv[argc] = {
+ Nan::New<External>(reinterpret_cast<void *>(credentials))};
+ MaybeLocal<Object> maybe_instance = Nan::NewInstance(
+ constructor->GetFunction(), argc, argv);
+ if (maybe_instance.IsEmpty()) {
+ return scope.Escape(Nan::Null());
+ } else {
+ return scope.Escape(maybe_instance.ToLocalChecked());
+ }
}
grpc_credentials *Credentials::GetWrappedCredentials() {
@@ -105,115 +123,123 @@ grpc_credentials *Credentials::GetWrappedCredentials() {
}
NAN_METHOD(Credentials::New) {
- NanScope();
-
- if (args.IsConstructCall()) {
- if (!args[0]->IsExternal()) {
- return NanThrowTypeError(
+ if (info.IsConstructCall()) {
+ if (!info[0]->IsExternal()) {
+ return Nan::ThrowTypeError(
"Credentials can only be created with the provided functions");
}
- Handle<External> ext = args[0].As<External>();
+ Local<External> ext = info[0].As<External>();
grpc_credentials *creds_value =
reinterpret_cast<grpc_credentials *>(ext->Value());
Credentials *credentials = new Credentials(creds_value);
- credentials->Wrap(args.This());
- NanReturnValue(args.This());
+ credentials->Wrap(info.This());
+ info.GetReturnValue().Set(info.This());
+ return;
} else {
const int argc = 1;
- Local<Value> argv[argc] = {args[0]};
- NanReturnValue(constructor->GetFunction()->NewInstance(argc, argv));
+ Local<Value> argv[argc] = {info[0]};
+ MaybeLocal<Object> maybe_instance = constructor->GetFunction()->NewInstance(
+ argc, argv);
+ if (maybe_instance.IsEmpty()) {
+ // There's probably a pending exception
+ return;
+ } else {
+ info.GetReturnValue().Set(maybe_instance.ToLocalChecked());
+ }
}
}
NAN_METHOD(Credentials::CreateDefault) {
- NanScope();
grpc_credentials *creds = grpc_google_default_credentials_create();
if (creds == NULL) {
- NanReturnNull();
+ info.GetReturnValue().SetNull();
+ } else {
+ info.GetReturnValue().Set(WrapStruct(creds));
}
- NanReturnValue(WrapStruct(creds));
}
NAN_METHOD(Credentials::CreateSsl) {
- NanScope();
char *root_certs = NULL;
grpc_ssl_pem_key_cert_pair key_cert_pair = {NULL, NULL};
- 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 (::node::Buffer::HasInstance(info[0])) {
+ root_certs = ::node::Buffer::Data(info[0]);
+ } else if (!(info[0]->IsNull() || info[0]->IsUndefined())) {
+ return Nan::ThrowTypeError("createSsl's first argument must be a Buffer");
}
- 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(
+ if (::node::Buffer::HasInstance(info[1])) {
+ key_cert_pair.private_key = ::node::Buffer::Data(info[1]);
+ } else if (!(info[1]->IsNull() || info[1]->IsUndefined())) {
+ return Nan::ThrowTypeError(
"createSSl's second argument must be a Buffer if provided");
}
- 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(
+ if (::node::Buffer::HasInstance(info[2])) {
+ key_cert_pair.cert_chain = ::node::Buffer::Data(info[2]);
+ } else if (!(info[2]->IsNull() || info[2]->IsUndefined())) {
+ return Nan::ThrowTypeError(
"createSSl's third argument must be a Buffer if provided");
}
grpc_credentials *creds = grpc_ssl_credentials_create(
root_certs, key_cert_pair.private_key == NULL ? NULL : &key_cert_pair,
NULL);
if (creds == NULL) {
- NanReturnNull();
+ info.GetReturnValue().SetNull();
+ } else {
+ info.GetReturnValue().Set(WrapStruct(creds));
}
- NanReturnValue(WrapStruct(creds));
}
NAN_METHOD(Credentials::CreateComposite) {
- NanScope();
- if (!HasInstance(args[0])) {
- return NanThrowTypeError(
+ if (!HasInstance(info[0])) {
+ return Nan::ThrowTypeError(
"createComposite's first argument must be a Credentials object");
}
- if (!HasInstance(args[1])) {
- return NanThrowTypeError(
+ if (!HasInstance(info[1])) {
+ return Nan::ThrowTypeError(
"createComposite's second argument must be a Credentials object");
}
- Credentials *creds1 = ObjectWrap::Unwrap<Credentials>(args[0]->ToObject());
- Credentials *creds2 = ObjectWrap::Unwrap<Credentials>(args[1]->ToObject());
+ Credentials *creds1 = ObjectWrap::Unwrap<Credentials>(
+ Nan::To<Object>(info[0]).ToLocalChecked());
+ Credentials *creds2 = ObjectWrap::Unwrap<Credentials>(
+ Nan::To<Object>(info[1]).ToLocalChecked());
grpc_credentials *creds = grpc_composite_credentials_create(
creds1->wrapped_credentials, creds2->wrapped_credentials, NULL);
if (creds == NULL) {
- NanReturnNull();
+ info.GetReturnValue().SetNull();
+ } else {
+ info.GetReturnValue().Set(WrapStruct(creds));
}
- NanReturnValue(WrapStruct(creds));
}
NAN_METHOD(Credentials::CreateGce) {
- NanScope();
+ Nan::HandleScope scope;
grpc_credentials *creds = grpc_google_compute_engine_credentials_create(NULL);
if (creds == NULL) {
- NanReturnNull();
+ info.GetReturnValue().SetNull();
+ } else {
+ info.GetReturnValue().Set(WrapStruct(creds));
}
- NanReturnValue(WrapStruct(creds));
}
NAN_METHOD(Credentials::CreateIam) {
- NanScope();
- if (!args[0]->IsString()) {
- return NanThrowTypeError("createIam's first argument must be a string");
+ if (!info[0]->IsString()) {
+ return Nan::ThrowTypeError("createIam's first argument must be a string");
}
- if (!args[1]->IsString()) {
- return NanThrowTypeError("createIam's second argument must be a string");
+ if (!info[1]->IsString()) {
+ return Nan::ThrowTypeError("createIam's second argument must be a string");
}
- NanUtf8String auth_token(args[0]);
- NanUtf8String auth_selector(args[1]);
+ Utf8String auth_token(info[0]);
+ Utf8String auth_selector(info[1]);
grpc_credentials *creds =
grpc_google_iam_credentials_create(*auth_token, *auth_selector, NULL);
if (creds == NULL) {
- NanReturnNull();
+ info.GetReturnValue().SetNull();
+ } else {
+ info.GetReturnValue().Set(WrapStruct(creds));
}
- NanReturnValue(WrapStruct(creds));
}
NAN_METHOD(Credentials::CreateInsecure) {
- NanScope();
- NanReturnValue(WrapStruct(NULL));
+ info.GetReturnValue().Set(WrapStruct(NULL));
}
} // namespace node
diff --git a/src/node/ext/credentials.h b/src/node/ext/credentials.h
index 62957e61c3..1b211175d4 100644
--- a/src/node/ext/credentials.h
+++ b/src/node/ext/credentials.h
@@ -43,12 +43,12 @@ namespace grpc {
namespace node {
/* Wrapper class for grpc_credentials structs */
-class Credentials : public ::node::ObjectWrap {
+class Credentials : public Nan::ObjectWrap {
public:
- static void Init(v8::Handle<v8::Object> exports);
- static bool HasInstance(v8::Handle<v8::Value> val);
+ static void Init(v8::Local<v8::Object> exports);
+ static bool HasInstance(v8::Local<v8::Value> val);
/* Wrap a grpc_credentials struct in a javascript object */
- static v8::Handle<v8::Value> WrapStruct(grpc_credentials *credentials);
+ static v8::Local<v8::Value> WrapStruct(grpc_credentials *credentials);
/* Returns the grpc_credentials struct that this object wraps */
grpc_credentials *GetWrappedCredentials();
@@ -69,9 +69,9 @@ class Credentials : public ::node::ObjectWrap {
static NAN_METHOD(CreateFake);
static NAN_METHOD(CreateIam);
static NAN_METHOD(CreateInsecure);
- static NanCallback *constructor;
+ static Nan::Callback *constructor;
// Used for typechecking instances of this javascript class
- static v8::Persistent<v8::FunctionTemplate> fun_tpl;
+ static Nan::Persistent<v8::FunctionTemplate> fun_tpl;
grpc_credentials *wrapped_credentials;
};
diff --git a/src/node/ext/node_grpc.cc b/src/node/ext/node_grpc.cc
index 0cf30da922..caca0fc452 100644
--- a/src/node/ext/node_grpc.cc
+++ b/src/node/ext/node_grpc.cc
@@ -43,171 +43,194 @@
#include "credentials.h"
#include "server_credentials.h"
-using v8::Handle;
+using v8::Local;
using v8::Value;
using v8::Object;
using v8::Uint32;
using v8::String;
-void InitStatusConstants(Handle<Object> exports) {
- NanScope();
- 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);
- Handle<Value> CANCELLED(NanNew<Uint32, uint32_t>(GRPC_STATUS_CANCELLED));
- status->Set(NanNew("CANCELLED"), CANCELLED);
- Handle<Value> UNKNOWN(NanNew<Uint32, uint32_t>(GRPC_STATUS_UNKNOWN));
- status->Set(NanNew("UNKNOWN"), UNKNOWN);
- Handle<Value> INVALID_ARGUMENT(
- NanNew<Uint32, uint32_t>(GRPC_STATUS_INVALID_ARGUMENT));
- status->Set(NanNew("INVALID_ARGUMENT"), INVALID_ARGUMENT);
- Handle<Value> DEADLINE_EXCEEDED(
- NanNew<Uint32, uint32_t>(GRPC_STATUS_DEADLINE_EXCEEDED));
- status->Set(NanNew("DEADLINE_EXCEEDED"), DEADLINE_EXCEEDED);
- Handle<Value> NOT_FOUND(NanNew<Uint32, uint32_t>(GRPC_STATUS_NOT_FOUND));
- status->Set(NanNew("NOT_FOUND"), NOT_FOUND);
- Handle<Value> ALREADY_EXISTS(
- NanNew<Uint32, uint32_t>(GRPC_STATUS_ALREADY_EXISTS));
- status->Set(NanNew("ALREADY_EXISTS"), ALREADY_EXISTS);
- Handle<Value> PERMISSION_DENIED(
- NanNew<Uint32, uint32_t>(GRPC_STATUS_PERMISSION_DENIED));
- status->Set(NanNew("PERMISSION_DENIED"), PERMISSION_DENIED);
- Handle<Value> UNAUTHENTICATED(
- NanNew<Uint32, uint32_t>(GRPC_STATUS_UNAUTHENTICATED));
- status->Set(NanNew("UNAUTHENTICATED"), UNAUTHENTICATED);
- Handle<Value> RESOURCE_EXHAUSTED(
- NanNew<Uint32, uint32_t>(GRPC_STATUS_RESOURCE_EXHAUSTED));
- status->Set(NanNew("RESOURCE_EXHAUSTED"), RESOURCE_EXHAUSTED);
- Handle<Value> FAILED_PRECONDITION(
- NanNew<Uint32, uint32_t>(GRPC_STATUS_FAILED_PRECONDITION));
- status->Set(NanNew("FAILED_PRECONDITION"), FAILED_PRECONDITION);
- Handle<Value> ABORTED(NanNew<Uint32, uint32_t>(GRPC_STATUS_ABORTED));
- status->Set(NanNew("ABORTED"), ABORTED);
- Handle<Value> OUT_OF_RANGE(
- NanNew<Uint32, uint32_t>(GRPC_STATUS_OUT_OF_RANGE));
- status->Set(NanNew("OUT_OF_RANGE"), OUT_OF_RANGE);
- Handle<Value> UNIMPLEMENTED(
- NanNew<Uint32, uint32_t>(GRPC_STATUS_UNIMPLEMENTED));
- status->Set(NanNew("UNIMPLEMENTED"), UNIMPLEMENTED);
- Handle<Value> INTERNAL(NanNew<Uint32, uint32_t>(GRPC_STATUS_INTERNAL));
- status->Set(NanNew("INTERNAL"), INTERNAL);
- Handle<Value> UNAVAILABLE(NanNew<Uint32, uint32_t>(GRPC_STATUS_UNAVAILABLE));
- status->Set(NanNew("UNAVAILABLE"), UNAVAILABLE);
- Handle<Value> DATA_LOSS(NanNew<Uint32, uint32_t>(GRPC_STATUS_DATA_LOSS));
- status->Set(NanNew("DATA_LOSS"), DATA_LOSS);
+void InitStatusConstants(Local<Object> exports) {
+ Nan::HandleScope scope;
+ Local<Object> status = Nan::New<Object>();
+ Nan::Set(exports, Nan::New("status").ToLocalChecked(), status);
+ Local<Value> OK(Nan::New<Uint32, uint32_t>(GRPC_STATUS_OK));
+ Nan::Set(status, Nan::New("OK").ToLocalChecked(), OK);
+ Local<Value> CANCELLED(Nan::New<Uint32, uint32_t>(GRPC_STATUS_CANCELLED));
+ Nan::Set(status, Nan::New("CANCELLED").ToLocalChecked(), CANCELLED);
+ Local<Value> UNKNOWN(Nan::New<Uint32, uint32_t>(GRPC_STATUS_UNKNOWN));
+ Nan::Set(status, Nan::New("UNKNOWN").ToLocalChecked(), UNKNOWN);
+ Local<Value> INVALID_ARGUMENT(
+ Nan::New<Uint32, uint32_t>(GRPC_STATUS_INVALID_ARGUMENT));
+ Nan::Set(status, Nan::New("INVALID_ARGUMENT").ToLocalChecked(),
+ INVALID_ARGUMENT);
+ Local<Value> DEADLINE_EXCEEDED(
+ Nan::New<Uint32, uint32_t>(GRPC_STATUS_DEADLINE_EXCEEDED));
+ Nan::Set(status, Nan::New("DEADLINE_EXCEEDED").ToLocalChecked(),
+ DEADLINE_EXCEEDED);
+ Local<Value> NOT_FOUND(Nan::New<Uint32, uint32_t>(GRPC_STATUS_NOT_FOUND));
+ Nan::Set(status, Nan::New("NOT_FOUND").ToLocalChecked(), NOT_FOUND);
+ Local<Value> ALREADY_EXISTS(
+ Nan::New<Uint32, uint32_t>(GRPC_STATUS_ALREADY_EXISTS));
+ Nan::Set(status, Nan::New("ALREADY_EXISTS").ToLocalChecked(), ALREADY_EXISTS);
+ Local<Value> PERMISSION_DENIED(
+ Nan::New<Uint32, uint32_t>(GRPC_STATUS_PERMISSION_DENIED));
+ Nan::Set(status, Nan::New("PERMISSION_DENIED").ToLocalChecked(),
+ PERMISSION_DENIED);
+ Local<Value> UNAUTHENTICATED(
+ Nan::New<Uint32, uint32_t>(GRPC_STATUS_UNAUTHENTICATED));
+ Nan::Set(status, Nan::New("UNAUTHENTICATED").ToLocalChecked(),
+ UNAUTHENTICATED);
+ Local<Value> RESOURCE_EXHAUSTED(
+ Nan::New<Uint32, uint32_t>(GRPC_STATUS_RESOURCE_EXHAUSTED));
+ Nan::Set(status, Nan::New("RESOURCE_EXHAUSTED").ToLocalChecked(),
+ RESOURCE_EXHAUSTED);
+ Local<Value> FAILED_PRECONDITION(
+ Nan::New<Uint32, uint32_t>(GRPC_STATUS_FAILED_PRECONDITION));
+ Nan::Set(status, Nan::New("FAILED_PRECONDITION").ToLocalChecked(),
+ FAILED_PRECONDITION);
+ Local<Value> ABORTED(Nan::New<Uint32, uint32_t>(GRPC_STATUS_ABORTED));
+ Nan::Set(status, Nan::New("ABORTED").ToLocalChecked(), ABORTED);
+ Local<Value> OUT_OF_RANGE(
+ Nan::New<Uint32, uint32_t>(GRPC_STATUS_OUT_OF_RANGE));
+ Nan::Set(status, Nan::New("OUT_OF_RANGE").ToLocalChecked(), OUT_OF_RANGE);
+ Local<Value> UNIMPLEMENTED(
+ Nan::New<Uint32, uint32_t>(GRPC_STATUS_UNIMPLEMENTED));
+ Nan::Set(status, Nan::New("UNIMPLEMENTED").ToLocalChecked(), UNIMPLEMENTED);
+ Local<Value> INTERNAL(Nan::New<Uint32, uint32_t>(GRPC_STATUS_INTERNAL));
+ Nan::Set(status, Nan::New("INTERNAL").ToLocalChecked(), INTERNAL);
+ Local<Value> UNAVAILABLE(Nan::New<Uint32, uint32_t>(GRPC_STATUS_UNAVAILABLE));
+ Nan::Set(status, Nan::New("UNAVAILABLE").ToLocalChecked(), UNAVAILABLE);
+ Local<Value> DATA_LOSS(Nan::New<Uint32, uint32_t>(GRPC_STATUS_DATA_LOSS));
+ Nan::Set(status, Nan::New("DATA_LOSS").ToLocalChecked(), DATA_LOSS);
}
-void InitCallErrorConstants(Handle<Object> exports) {
- NanScope();
- 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);
- Handle<Value> ERROR(NanNew<Uint32, uint32_t>(GRPC_CALL_ERROR));
- call_error->Set(NanNew("ERROR"), ERROR);
- Handle<Value> NOT_ON_SERVER(
- NanNew<Uint32, uint32_t>(GRPC_CALL_ERROR_NOT_ON_SERVER));
- call_error->Set(NanNew("NOT_ON_SERVER"), NOT_ON_SERVER);
- Handle<Value> NOT_ON_CLIENT(
- NanNew<Uint32, uint32_t>(GRPC_CALL_ERROR_NOT_ON_CLIENT));
- call_error->Set(NanNew("NOT_ON_CLIENT"), NOT_ON_CLIENT);
- Handle<Value> ALREADY_INVOKED(
- NanNew<Uint32, uint32_t>(GRPC_CALL_ERROR_ALREADY_INVOKED));
- call_error->Set(NanNew("ALREADY_INVOKED"), ALREADY_INVOKED);
- Handle<Value> NOT_INVOKED(
- NanNew<Uint32, uint32_t>(GRPC_CALL_ERROR_NOT_INVOKED));
- call_error->Set(NanNew("NOT_INVOKED"), NOT_INVOKED);
- Handle<Value> ALREADY_FINISHED(
- NanNew<Uint32, uint32_t>(GRPC_CALL_ERROR_ALREADY_FINISHED));
- call_error->Set(NanNew("ALREADY_FINISHED"), ALREADY_FINISHED);
- Handle<Value> TOO_MANY_OPERATIONS(
- NanNew<Uint32, uint32_t>(GRPC_CALL_ERROR_TOO_MANY_OPERATIONS));
- call_error->Set(NanNew("TOO_MANY_OPERATIONS"), TOO_MANY_OPERATIONS);
- Handle<Value> INVALID_FLAGS(
- NanNew<Uint32, uint32_t>(GRPC_CALL_ERROR_INVALID_FLAGS));
- call_error->Set(NanNew("INVALID_FLAGS"), INVALID_FLAGS);
+void InitCallErrorConstants(Local<Object> exports) {
+ Nan::HandleScope scope;
+ Local<Object> call_error = Nan::New<Object>();
+ Nan::Set(exports, Nan::New("callError").ToLocalChecked(), call_error);
+ Local<Value> OK(Nan::New<Uint32, uint32_t>(GRPC_CALL_OK));
+ Nan::Set(call_error, Nan::New("OK").ToLocalChecked(), OK);
+ Local<Value> ERROR(Nan::New<Uint32, uint32_t>(GRPC_CALL_ERROR));
+ Nan::Set(call_error, Nan::New("ERROR").ToLocalChecked(), ERROR);
+ Local<Value> NOT_ON_SERVER(
+ Nan::New<Uint32, uint32_t>(GRPC_CALL_ERROR_NOT_ON_SERVER));
+ Nan::Set(call_error, Nan::New("NOT_ON_SERVER").ToLocalChecked(),
+ NOT_ON_SERVER);
+ Local<Value> NOT_ON_CLIENT(
+ Nan::New<Uint32, uint32_t>(GRPC_CALL_ERROR_NOT_ON_CLIENT));
+ Nan::Set(call_error, Nan::New("NOT_ON_CLIENT").ToLocalChecked(),
+ NOT_ON_CLIENT);
+ Local<Value> ALREADY_INVOKED(
+ Nan::New<Uint32, uint32_t>(GRPC_CALL_ERROR_ALREADY_INVOKED));
+ Nan::Set(call_error, Nan::New("ALREADY_INVOKED").ToLocalChecked(),
+ ALREADY_INVOKED);
+ Local<Value> NOT_INVOKED(
+ Nan::New<Uint32, uint32_t>(GRPC_CALL_ERROR_NOT_INVOKED));
+ Nan::Set(call_error, Nan::New("NOT_INVOKED").ToLocalChecked(), NOT_INVOKED);
+ Local<Value> ALREADY_FINISHED(
+ Nan::New<Uint32, uint32_t>(GRPC_CALL_ERROR_ALREADY_FINISHED));
+ Nan::Set(call_error, Nan::New("ALREADY_FINISHED").ToLocalChecked(),
+ ALREADY_FINISHED);
+ Local<Value> TOO_MANY_OPERATIONS(
+ Nan::New<Uint32, uint32_t>(GRPC_CALL_ERROR_TOO_MANY_OPERATIONS));
+ Nan::Set(call_error, Nan::New("TOO_MANY_OPERATIONS").ToLocalChecked(),
+ TOO_MANY_OPERATIONS);
+ Local<Value> INVALID_FLAGS(
+ Nan::New<Uint32, uint32_t>(GRPC_CALL_ERROR_INVALID_FLAGS));
+ Nan::Set(call_error, Nan::New("INVALID_FLAGS").ToLocalChecked(),
+ INVALID_FLAGS);
}
-void InitOpTypeConstants(Handle<Object> exports) {
- NanScope();
- 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));
- op_type->Set(NanNew("SEND_INITIAL_METADATA"), SEND_INITIAL_METADATA);
- Handle<Value> SEND_MESSAGE(
- NanNew<Uint32, uint32_t>(GRPC_OP_SEND_MESSAGE));
- op_type->Set(NanNew("SEND_MESSAGE"), SEND_MESSAGE);
- Handle<Value> SEND_CLOSE_FROM_CLIENT(
- NanNew<Uint32, uint32_t>(GRPC_OP_SEND_CLOSE_FROM_CLIENT));
- op_type->Set(NanNew("SEND_CLOSE_FROM_CLIENT"), SEND_CLOSE_FROM_CLIENT);
- Handle<Value> SEND_STATUS_FROM_SERVER(
- NanNew<Uint32, uint32_t>(GRPC_OP_SEND_STATUS_FROM_SERVER));
- op_type->Set(NanNew("SEND_STATUS_FROM_SERVER"), SEND_STATUS_FROM_SERVER);
- Handle<Value> RECV_INITIAL_METADATA(
- NanNew<Uint32, uint32_t>(GRPC_OP_RECV_INITIAL_METADATA));
- op_type->Set(NanNew("RECV_INITIAL_METADATA"), RECV_INITIAL_METADATA);
- Handle<Value> RECV_MESSAGE(
- NanNew<Uint32, uint32_t>(GRPC_OP_RECV_MESSAGE));
- op_type->Set(NanNew("RECV_MESSAGE"), RECV_MESSAGE);
- Handle<Value> RECV_STATUS_ON_CLIENT(
- NanNew<Uint32, uint32_t>(GRPC_OP_RECV_STATUS_ON_CLIENT));
- op_type->Set(NanNew("RECV_STATUS_ON_CLIENT"), RECV_STATUS_ON_CLIENT);
- Handle<Value> RECV_CLOSE_ON_SERVER(
- NanNew<Uint32, uint32_t>(GRPC_OP_RECV_CLOSE_ON_SERVER));
- op_type->Set(NanNew("RECV_CLOSE_ON_SERVER"), RECV_CLOSE_ON_SERVER);
+void InitOpTypeConstants(Local<Object> exports) {
+ Nan::HandleScope scope;
+ Local<Object> op_type = Nan::New<Object>();
+ Nan::Set(exports, Nan::New("opType").ToLocalChecked(), op_type);
+ Local<Value> SEND_INITIAL_METADATA(
+ Nan::New<Uint32, uint32_t>(GRPC_OP_SEND_INITIAL_METADATA));
+ Nan::Set(op_type, Nan::New("SEND_INITIAL_METADATA").ToLocalChecked(),
+ SEND_INITIAL_METADATA);
+ Local<Value> SEND_MESSAGE(
+ Nan::New<Uint32, uint32_t>(GRPC_OP_SEND_MESSAGE));
+ Nan::Set(op_type, Nan::New("SEND_MESSAGE").ToLocalChecked(), SEND_MESSAGE);
+ Local<Value> SEND_CLOSE_FROM_CLIENT(
+ Nan::New<Uint32, uint32_t>(GRPC_OP_SEND_CLOSE_FROM_CLIENT));
+ Nan::Set(op_type, Nan::New("SEND_CLOSE_FROM_CLIENT").ToLocalChecked(),
+ SEND_CLOSE_FROM_CLIENT);
+ Local<Value> SEND_STATUS_FROM_SERVER(
+ Nan::New<Uint32, uint32_t>(GRPC_OP_SEND_STATUS_FROM_SERVER));
+ Nan::Set(op_type, Nan::New("SEND_STATUS_FROM_SERVER").ToLocalChecked(),
+ SEND_STATUS_FROM_SERVER);
+ Local<Value> RECV_INITIAL_METADATA(
+ Nan::New<Uint32, uint32_t>(GRPC_OP_RECV_INITIAL_METADATA));
+ Nan::Set(op_type, Nan::New("RECV_INITIAL_METADATA").ToLocalChecked(),
+ RECV_INITIAL_METADATA);
+ Local<Value> RECV_MESSAGE(
+ Nan::New<Uint32, uint32_t>(GRPC_OP_RECV_MESSAGE));
+ Nan::Set(op_type, Nan::New("RECV_MESSAGE").ToLocalChecked(), RECV_MESSAGE);
+ Local<Value> RECV_STATUS_ON_CLIENT(
+ Nan::New<Uint32, uint32_t>(GRPC_OP_RECV_STATUS_ON_CLIENT));
+ Nan::Set(op_type, Nan::New("RECV_STATUS_ON_CLIENT").ToLocalChecked(),
+ RECV_STATUS_ON_CLIENT);
+ Local<Value> RECV_CLOSE_ON_SERVER(
+ Nan::New<Uint32, uint32_t>(GRPC_OP_RECV_CLOSE_ON_SERVER));
+ Nan::Set(op_type, Nan::New("RECV_CLOSE_ON_SERVER").ToLocalChecked(),
+ RECV_CLOSE_ON_SERVER);
}
-void InitPropagateConstants(Handle<Object> exports) {
- NanScope();
- Handle<Object> propagate = NanNew<Object>();
- exports->Set(NanNew("propagate"), propagate);
- Handle<Value> DEADLINE(NanNew<Uint32, uint32_t>(GRPC_PROPAGATE_DEADLINE));
- propagate->Set(NanNew("DEADLINE"), DEADLINE);
- Handle<Value> CENSUS_STATS_CONTEXT(
- NanNew<Uint32, uint32_t>(GRPC_PROPAGATE_CENSUS_STATS_CONTEXT));
- propagate->Set(NanNew("CENSUS_STATS_CONTEXT"), CENSUS_STATS_CONTEXT);
- Handle<Value> CENSUS_TRACING_CONTEXT(
- NanNew<Uint32, uint32_t>(GRPC_PROPAGATE_CENSUS_TRACING_CONTEXT));
- propagate->Set(NanNew("CENSUS_TRACING_CONTEXT"), CENSUS_TRACING_CONTEXT);
- Handle<Value> CANCELLATION(
- NanNew<Uint32, uint32_t>(GRPC_PROPAGATE_CANCELLATION));
- propagate->Set(NanNew("CANCELLATION"), CANCELLATION);
- Handle<Value> DEFAULTS(NanNew<Uint32, uint32_t>(GRPC_PROPAGATE_DEFAULTS));
- propagate->Set(NanNew("DEFAULTS"), DEFAULTS);
+void InitPropagateConstants(Local<Object> exports) {
+ Nan::HandleScope scope;
+ Local<Object> propagate = Nan::New<Object>();
+ Nan::Set(exports, Nan::New("propagate").ToLocalChecked(), propagate);
+ Local<Value> DEADLINE(Nan::New<Uint32, uint32_t>(GRPC_PROPAGATE_DEADLINE));
+ Nan::Set(propagate, Nan::New("DEADLINE").ToLocalChecked(), DEADLINE);
+ Local<Value> CENSUS_STATS_CONTEXT(
+ Nan::New<Uint32, uint32_t>(GRPC_PROPAGATE_CENSUS_STATS_CONTEXT));
+ Nan::Set(propagate, Nan::New("CENSUS_STATS_CONTEXT").ToLocalChecked(),
+ CENSUS_STATS_CONTEXT);
+ Local<Value> CENSUS_TRACING_CONTEXT(
+ Nan::New<Uint32, uint32_t>(GRPC_PROPAGATE_CENSUS_TRACING_CONTEXT));
+ Nan::Set(propagate, Nan::New("CENSUS_TRACING_CONTEXT").ToLocalChecked(),
+ CENSUS_TRACING_CONTEXT);
+ Local<Value> CANCELLATION(
+ Nan::New<Uint32, uint32_t>(GRPC_PROPAGATE_CANCELLATION));
+ Nan::Set(propagate, Nan::New("CANCELLATION").ToLocalChecked(), CANCELLATION);
+ Local<Value> DEFAULTS(Nan::New<Uint32, uint32_t>(GRPC_PROPAGATE_DEFAULTS));
+ Nan::Set(propagate, Nan::New("DEFAULTS").ToLocalChecked(), DEFAULTS);
}
-void InitConnectivityStateConstants(Handle<Object> exports) {
- NanScope();
- Handle<Object> channel_state = NanNew<Object>();
- exports->Set(NanNew("connectivityState"), channel_state);
- Handle<Value> IDLE(NanNew<Uint32, uint32_t>(GRPC_CHANNEL_IDLE));
- channel_state->Set(NanNew("IDLE"), IDLE);
- Handle<Value> CONNECTING(NanNew<Uint32, uint32_t>(GRPC_CHANNEL_CONNECTING));
- channel_state->Set(NanNew("CONNECTING"), CONNECTING);
- Handle<Value> READY(NanNew<Uint32, uint32_t>(GRPC_CHANNEL_READY));
- channel_state->Set(NanNew("READY"), READY);
- Handle<Value> TRANSIENT_FAILURE(
- NanNew<Uint32, uint32_t>(GRPC_CHANNEL_TRANSIENT_FAILURE));
- channel_state->Set(NanNew("TRANSIENT_FAILURE"), TRANSIENT_FAILURE);
- Handle<Value> FATAL_FAILURE(
- NanNew<Uint32, uint32_t>(GRPC_CHANNEL_FATAL_FAILURE));
- channel_state->Set(NanNew("FATAL_FAILURE"), FATAL_FAILURE);
+void InitConnectivityStateConstants(Local<Object> exports) {
+ Nan::HandleScope scope;
+ Local<Object> channel_state = Nan::New<Object>();
+ Nan::Set(exports, Nan::New("connectivityState").ToLocalChecked(),
+ channel_state);
+ Local<Value> IDLE(Nan::New<Uint32, uint32_t>(GRPC_CHANNEL_IDLE));
+ Nan::Set(channel_state, Nan::New("IDLE").ToLocalChecked(), IDLE);
+ Local<Value> CONNECTING(Nan::New<Uint32, uint32_t>(GRPC_CHANNEL_CONNECTING));
+ Nan::Set(channel_state, Nan::New("CONNECTING").ToLocalChecked(), CONNECTING);
+ Local<Value> READY(Nan::New<Uint32, uint32_t>(GRPC_CHANNEL_READY));
+ Nan::Set(channel_state, Nan::New("READY").ToLocalChecked(), READY);
+ Local<Value> TRANSIENT_FAILURE(
+ Nan::New<Uint32, uint32_t>(GRPC_CHANNEL_TRANSIENT_FAILURE));
+ Nan::Set(channel_state, Nan::New("TRANSIENT_FAILURE").ToLocalChecked(),
+ TRANSIENT_FAILURE);
+ Local<Value> FATAL_FAILURE(
+ Nan::New<Uint32, uint32_t>(GRPC_CHANNEL_FATAL_FAILURE));
+ Nan::Set(channel_state, Nan::New("FATAL_FAILURE").ToLocalChecked(),
+ FATAL_FAILURE);
}
-void InitWriteFlags(Handle<Object> exports) {
- NanScope();
- Handle<Object> write_flags = NanNew<Object>();
- exports->Set(NanNew("writeFlags"), write_flags);
- Handle<Value> BUFFER_HINT(NanNew<Uint32, uint32_t>(GRPC_WRITE_BUFFER_HINT));
- write_flags->Set(NanNew("BUFFER_HINT"), BUFFER_HINT);
- Handle<Value> NO_COMPRESS(NanNew<Uint32, uint32_t>(GRPC_WRITE_NO_COMPRESS));
- write_flags->Set(NanNew("NO_COMPRESS"), NO_COMPRESS);
+void InitWriteFlags(Local<Object> exports) {
+ Nan::HandleScope scope;
+ Local<Object> write_flags = Nan::New<Object>();
+ Nan::Set(exports, Nan::New("writeFlags").ToLocalChecked(), write_flags);
+ Local<Value> BUFFER_HINT(Nan::New<Uint32, uint32_t>(GRPC_WRITE_BUFFER_HINT));
+ Nan::Set(write_flags, Nan::New("BUFFER_HINT").ToLocalChecked(), BUFFER_HINT);
+ Local<Value> NO_COMPRESS(Nan::New<Uint32, uint32_t>(GRPC_WRITE_NO_COMPRESS));
+ Nan::Set(write_flags, Nan::New("NO_COMPRESS").ToLocalChecked(), NO_COMPRESS);
}
-void init(Handle<Object> exports) {
- NanScope();
+void init(Local<Object> exports) {
+ Nan::HandleScope scope;
grpc_init();
InitStatusConstants(exports);
InitCallErrorConstants(exports);
diff --git a/src/node/ext/server.cc b/src/node/ext/server.cc
index 32a8ff55b1..87363fc446 100644
--- a/src/node/ext/server.cc
+++ b/src/node/ext/server.cc
@@ -50,6 +50,15 @@
namespace grpc {
namespace node {
+using Nan::Callback;
+using Nan::EscapableHandleScope;
+using Nan::HandleScope;
+using Nan::Maybe;
+using Nan::MaybeLocal;
+using Nan::ObjectWrap;
+using Nan::Persistent;
+using Nan::Utf8String;
+
using std::unique_ptr;
using v8::Array;
using v8::Boolean;
@@ -57,16 +66,13 @@ using v8::Date;
using v8::Exception;
using v8::Function;
using v8::FunctionTemplate;
-using v8::Handle;
-using v8::HandleScope;
using v8::Local;
using v8::Number;
using v8::Object;
-using v8::Persistent;
using v8::String;
using v8::Value;
-NanCallback *Server::constructor;
+Nan::Callback *Server::constructor;
Persistent<FunctionTemplate> Server::fun_tpl;
class NewCallOp : public Op {
@@ -82,22 +88,26 @@ class NewCallOp : public Op {
grpc_metadata_array_destroy(&request_metadata);
}
- Handle<Value> GetNodeValue() const {
- NanEscapableScope();
+ Local<Value> GetNodeValue() const {
+ Nan::EscapableHandleScope scope;
if (call == NULL) {
- return NanEscapeScope(NanNull());
+ return scope.Escape(Nan::Null());
}
- Handle<Object> obj = NanNew<Object>();
- obj->Set(NanNew("call"), Call::WrapStruct(call));
- obj->Set(NanNew("method"), NanNew(details.method));
- obj->Set(NanNew("host"), NanNew(details.host));
- obj->Set(NanNew("deadline"),
- NanNew<Date>(TimespecToMilliseconds(details.deadline)));
- obj->Set(NanNew("metadata"), ParseMetadata(&request_metadata));
- return NanEscapeScope(obj);
+ Local<Object> obj = Nan::New<Object>();
+ Nan::Set(obj, Nan::New("call").ToLocalChecked(), Call::WrapStruct(call));
+ Nan::Set(obj, Nan::New("method").ToLocalChecked(),
+ Nan::New(details.method).ToLocalChecked());
+ Nan::Set(obj, Nan::New("host").ToLocalChecked(),
+ Nan::New(details.host).ToLocalChecked());
+ Nan::Set(obj, Nan::New("deadline").ToLocalChecked(),
+ Nan::New<Date>(
+ TimespecToMilliseconds(details.deadline)).ToLocalChecked());
+ Nan::Set(obj, Nan::New("metadata").ToLocalChecked(),
+ ParseMetadata(&request_metadata));
+ return scope.Escape(obj);
}
- bool ParseOp(Handle<Value> value, grpc_op *out,
+ bool ParseOp(Local<Value> value, grpc_op *out,
shared_ptr<Resources> resources) {
return true;
}
@@ -124,35 +134,25 @@ Server::~Server() {
grpc_completion_queue_destroy(this->shutdown_queue);
}
-void Server::Init(Handle<Object> exports) {
- NanScope();
- Local<FunctionTemplate> tpl = NanNew<FunctionTemplate>(New);
- tpl->SetClassName(NanNew("Server"));
+void Server::Init(Local<Object> exports) {
+ HandleScope scope;
+ Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
+ tpl->SetClassName(Nan::New("Server").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
- NanSetPrototypeTemplate(tpl, "requestCall",
- NanNew<FunctionTemplate>(RequestCall)->GetFunction());
-
- NanSetPrototypeTemplate(
- tpl, "addHttp2Port",
- NanNew<FunctionTemplate>(AddHttp2Port)->GetFunction());
-
- NanSetPrototypeTemplate(tpl, "start",
- NanNew<FunctionTemplate>(Start)->GetFunction());
-
- NanSetPrototypeTemplate(tpl, "tryShutdown",
- NanNew<FunctionTemplate>(TryShutdown)->GetFunction());
- NanSetPrototypeTemplate(
- tpl, "forceShutdown",
- NanNew<FunctionTemplate>(ForceShutdown)->GetFunction());
-
- NanAssignPersistent(fun_tpl, tpl);
- Handle<Function> ctr = tpl->GetFunction();
- constructor = new NanCallback(ctr);
- exports->Set(NanNew("Server"), ctr);
+ Nan::SetPrototypeMethod(tpl, "requestCall", RequestCall);
+ Nan::SetPrototypeMethod(tpl, "addHttp2Port", AddHttp2Port);
+ Nan::SetPrototypeMethod(tpl, "start", Start);
+ Nan::SetPrototypeMethod(tpl, "tryShutdown", TryShutdown);
+ Nan::SetPrototypeMethod(tpl, "forceShutdown", ForceShutdown);
+ fun_tpl.Reset(tpl);
+ Local<Function> ctr = Nan::GetFunction(tpl).ToLocalChecked();
+ Nan::Set(exports, Nan::New("Server").ToLocalChecked(), ctr);
+ constructor = new Callback(ctr);
}
-bool Server::HasInstance(Handle<Value> val) {
- return NanHasInstance(fun_tpl, val);
+bool Server::HasInstance(Local<Value> val) {
+ HandleScope scope;
+ return Nan::New(fun_tpl)->HasInstance(val);
}
void Server::ShutdownServer() {
@@ -165,64 +165,77 @@ void Server::ShutdownServer() {
}
NAN_METHOD(Server::New) {
- NanScope();
-
/* If this is not a constructor call, make a constructor call and return
the result */
- if (!args.IsConstructCall()) {
+ if (!info.IsConstructCall()) {
const int argc = 1;
- Local<Value> argv[argc] = {args[0]};
- NanReturnValue(constructor->GetFunction()->NewInstance(argc, argv));
+ Local<Value> argv[argc] = {info[0]};
+ MaybeLocal<Object> maybe_instance = constructor->GetFunction()->NewInstance(
+ argc, argv);
+ if (maybe_instance.IsEmpty()) {
+ // There's probably a pending exception
+ return;
+ } else {
+ info.GetReturnValue().Set(maybe_instance.ToLocalChecked());
+ return;
+ }
}
grpc_server *wrapped_server;
grpc_completion_queue *queue = CompletionQueueAsyncWorker::GetQueue();
- if (args[0]->IsUndefined()) {
+ if (info[0]->IsUndefined()) {
wrapped_server = grpc_server_create(NULL, NULL);
- } else if (args[0]->IsObject()) {
- Handle<Object> args_hash(args[0]->ToObject());
- Handle<Array> keys(args_hash->GetOwnPropertyNames());
+ } else if (info[0]->IsObject()) {
+ Local<Object> args_hash = Nan::To<Object>(info[0]).ToLocalChecked();
+ Local<Array> keys = Nan::GetOwnPropertyNames(args_hash).ToLocalChecked();
grpc_channel_args channel_args;
channel_args.num_args = keys->Length();
channel_args.args = reinterpret_cast<grpc_arg *>(
calloc(channel_args.num_args, sizeof(grpc_arg)));
/* These are used to keep all strings until then end of the block, then
destroy them */
- std::vector<NanUtf8String *> key_strings(keys->Length());
- std::vector<NanUtf8String *> value_strings(keys->Length());
+ std::vector<Utf8String *> key_strings(keys->Length());
+ std::vector<Utf8String *> value_strings(keys->Length());
for (unsigned int i = 0; i < channel_args.num_args; i++) {
- Handle<String> current_key(keys->Get(i)->ToString());
- Handle<Value> current_value(args_hash->Get(current_key));
- key_strings[i] = new NanUtf8String(current_key);
+ MaybeLocal<String> maybe_key = Nan::To<String>(
+ Nan::Get(keys, i).ToLocalChecked());
+ if (maybe_key.IsEmpty()) {
+ free(channel_args.args);
+ return Nan::ThrowTypeError("Arg keys must be strings");
+ }
+ Local<String> current_key = maybe_key.ToLocalChecked();
+ Local<Value> current_value = Nan::Get(args_hash,
+ current_key).ToLocalChecked();
+ key_strings[i] = new Utf8String(current_key);
channel_args.args[i].key = **key_strings[i];
if (current_value->IsInt32()) {
channel_args.args[i].type = GRPC_ARG_INTEGER;
- channel_args.args[i].value.integer = current_value->Int32Value();
+ channel_args.args[i].value.integer = Nan::To<int32_t>(
+ current_value).FromJust();
} else if (current_value->IsString()) {
channel_args.args[i].type = GRPC_ARG_STRING;
- value_strings[i] = new NanUtf8String(current_value);
+ value_strings[i] = new Utf8String(current_value);
channel_args.args[i].value.string = **value_strings[i];
} else {
free(channel_args.args);
- return NanThrowTypeError("Arg values must be strings");
+ return Nan::ThrowTypeError("Arg values must be strings");
}
}
wrapped_server = grpc_server_create(&channel_args, NULL);
free(channel_args.args);
} else {
- return NanThrowTypeError("Server expects an object");
+ return Nan::ThrowTypeError("Server expects an object");
}
grpc_server_register_completion_queue(wrapped_server, queue, NULL);
Server *server = new Server(wrapped_server);
- server->Wrap(args.This());
- NanReturnValue(args.This());
+ server->Wrap(info.This());
+ info.GetReturnValue().Set(info.This());
}
NAN_METHOD(Server::RequestCall) {
- NanScope();
- if (!HasInstance(args.This())) {
- return NanThrowTypeError("requestCall can only be called on a Server");
+ if (!HasInstance(info.This())) {
+ return Nan::ThrowTypeError("requestCall can only be called on a Server");
}
- Server *server = ObjectWrap::Unwrap<Server>(args.This());
+ Server *server = ObjectWrap::Unwrap<Server>(info.This());
NewCallOp *op = new NewCallOp();
unique_ptr<OpVec> ops(new OpVec());
ops->push_back(unique_ptr<Op>(op));
@@ -230,79 +243,74 @@ NAN_METHOD(Server::RequestCall) {
server->wrapped_server, &op->call, &op->details, &op->request_metadata,
CompletionQueueAsyncWorker::GetQueue(),
CompletionQueueAsyncWorker::GetQueue(),
- new struct tag(new NanCallback(args[0].As<Function>()), ops.release(),
+ new struct tag(new Callback(info[0].As<Function>()), ops.release(),
shared_ptr<Resources>(nullptr)));
if (error != GRPC_CALL_OK) {
- return NanThrowError(nanErrorWithCode("requestCall failed", error));
+ return Nan::ThrowError(nanErrorWithCode("requestCall failed", error));
}
CompletionQueueAsyncWorker::Next();
- NanReturnUndefined();
}
NAN_METHOD(Server::AddHttp2Port) {
- NanScope();
- if (!HasInstance(args.This())) {
- return NanThrowTypeError(
+ if (!HasInstance(info.This())) {
+ return Nan::ThrowTypeError(
"addHttp2Port can only be called on a Server");
}
- if (!args[0]->IsString()) {
- return NanThrowTypeError(
+ if (!info[0]->IsString()) {
+ return Nan::ThrowTypeError(
"addHttp2Port's first argument must be a String");
}
- if (!ServerCredentials::HasInstance(args[1])) {
- return NanThrowTypeError(
+ if (!ServerCredentials::HasInstance(info[1])) {
+ return Nan::ThrowTypeError(
"addHttp2Port's second argument must be ServerCredentials");
}
- Server *server = ObjectWrap::Unwrap<Server>(args.This());
+ Server *server = ObjectWrap::Unwrap<Server>(info.This());
ServerCredentials *creds_object = ObjectWrap::Unwrap<ServerCredentials>(
- args[1]->ToObject());
+ Nan::To<Object>(info[1]).ToLocalChecked());
grpc_server_credentials *creds = creds_object->GetWrappedServerCredentials();
int port;
if (creds == NULL) {
port = grpc_server_add_insecure_http2_port(server->wrapped_server,
- *NanUtf8String(args[0]));
+ *Utf8String(info[0]));
} else {
port = grpc_server_add_secure_http2_port(server->wrapped_server,
- *NanUtf8String(args[0]),
+ *Utf8String(info[0]),
creds);
}
- NanReturnValue(NanNew<Number>(port));
+ info.GetReturnValue().Set(Nan::New<Number>(port));
}
NAN_METHOD(Server::Start) {
- NanScope();
- if (!HasInstance(args.This())) {
- return NanThrowTypeError("start can only be called on a Server");
+ Nan::HandleScope scope;
+ if (!HasInstance(info.This())) {
+ return Nan::ThrowTypeError("start can only be called on a Server");
}
- Server *server = ObjectWrap::Unwrap<Server>(args.This());
+ Server *server = ObjectWrap::Unwrap<Server>(info.This());
grpc_server_start(server->wrapped_server);
- NanReturnUndefined();
}
NAN_METHOD(Server::TryShutdown) {
- NanScope();
- if (!HasInstance(args.This())) {
- return NanThrowTypeError("tryShutdown can only be called on a Server");
+ Nan::HandleScope scope;
+ if (!HasInstance(info.This())) {
+ return Nan::ThrowTypeError("tryShutdown can only be called on a Server");
}
- Server *server = ObjectWrap::Unwrap<Server>(args.This());
+ Server *server = ObjectWrap::Unwrap<Server>(info.This());
unique_ptr<OpVec> ops(new OpVec());
grpc_server_shutdown_and_notify(
server->wrapped_server,
CompletionQueueAsyncWorker::GetQueue(),
- new struct tag(new NanCallback(args[0].As<Function>()), ops.release(),
+ new struct tag(new Nan::Callback(info[0].As<Function>()), ops.release(),
shared_ptr<Resources>(nullptr)));
CompletionQueueAsyncWorker::Next();
- NanReturnUndefined();
}
NAN_METHOD(Server::ForceShutdown) {
- NanScope();
- if (!HasInstance(args.This())) {
- return NanThrowTypeError("forceShutdown can only be called on a Server");
+ Nan::HandleScope scope;
+ if (!HasInstance(info.This())) {
+ return Nan::ThrowTypeError("forceShutdown can only be called on a Server");
}
- Server *server = ObjectWrap::Unwrap<Server>(args.This());
+ Server *server = ObjectWrap::Unwrap<Server>(info.This());
server->ShutdownServer();
- NanReturnUndefined();
}
} // namespace node
diff --git a/src/node/ext/server.h b/src/node/ext/server.h
index e7d5c3fb11..ab5fc210e8 100644
--- a/src/node/ext/server.h
+++ b/src/node/ext/server.h
@@ -44,14 +44,14 @@ namespace node {
/* Wraps grpc_server as a JavaScript object. Provides a constructor
and wrapper methods for grpc_server_create, grpc_server_request_call,
grpc_server_add_http2_port, and grpc_server_start. */
-class Server : public ::node::ObjectWrap {
+class Server : public Nan::ObjectWrap {
public:
/* Initializes the Server class and exposes the constructor and
wrapper methods to JavaScript */
- static void Init(v8::Handle<v8::Object> exports);
+ static void Init(v8::Local<v8::Object> exports);
/* Tests whether the given value was constructed by this class's
JavaScript constructor */
- static bool HasInstance(v8::Handle<v8::Value> val);
+ static bool HasInstance(v8::Local<v8::Value> val);
private:
explicit Server(grpc_server *server);
@@ -69,8 +69,8 @@ class Server : public ::node::ObjectWrap {
static NAN_METHOD(Start);
static NAN_METHOD(TryShutdown);
static NAN_METHOD(ForceShutdown);
- static NanCallback *constructor;
- static v8::Persistent<v8::FunctionTemplate> fun_tpl;
+ static Nan::Callback *constructor;
+ static Nan::Persistent<v8::FunctionTemplate> fun_tpl;
grpc_server *wrapped_server;
grpc_completion_queue *shutdown_queue;
diff --git a/src/node/ext/server_credentials.cc b/src/node/ext/server_credentials.cc
index b1201eb664..5e922bd877 100644
--- a/src/node/ext/server_credentials.cc
+++ b/src/node/ext/server_credentials.cc
@@ -41,22 +41,28 @@
namespace grpc {
namespace node {
+using Nan::Callback;
+using Nan::EscapableHandleScope;
+using Nan::HandleScope;
+using Nan::Maybe;
+using Nan::MaybeLocal;
+using Nan::ObjectWrap;
+using Nan::Persistent;
+using Nan::Utf8String;
+
using v8::Array;
using v8::Exception;
using v8::External;
using v8::Function;
using v8::FunctionTemplate;
-using v8::Handle;
-using v8::HandleScope;
using v8::Integer;
using v8::Local;
using v8::Object;
using v8::ObjectTemplate;
-using v8::Persistent;
using v8::String;
using v8::Value;
-NanCallback *ServerCredentials::constructor;
+Nan::Callback *ServerCredentials::constructor;
Persistent<FunctionTemplate> ServerCredentials::fun_tpl;
ServerCredentials::ServerCredentials(grpc_server_credentials *credentials)
@@ -66,33 +72,41 @@ ServerCredentials::~ServerCredentials() {
grpc_server_credentials_release(wrapped_credentials);
}
-void ServerCredentials::Init(Handle<Object> exports) {
- NanScope();
- Local<FunctionTemplate> tpl = NanNew<FunctionTemplate>(New);
- tpl->SetClassName(NanNew("ServerCredentials"));
+void ServerCredentials::Init(Local<Object> exports) {
+ Nan::HandleScope scope;
+ Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
+ tpl->SetClassName(Nan::New("ServerCredentials").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
- NanAssignPersistent(fun_tpl, tpl);
- Handle<Function> ctr = tpl->GetFunction();
- ctr->Set(NanNew("createSsl"),
- NanNew<FunctionTemplate>(CreateSsl)->GetFunction());
- ctr->Set(NanNew("createInsecure"),
- NanNew<FunctionTemplate>(CreateInsecure)->GetFunction());
- constructor = new NanCallback(ctr);
- exports->Set(NanNew("ServerCredentials"), ctr);
+ Local<Function> ctr = tpl->GetFunction();
+ Nan::Set(ctr, Nan::New("createSsl").ToLocalChecked(),
+ Nan::GetFunction(
+ Nan::New<FunctionTemplate>(CreateSsl)).ToLocalChecked());
+ Nan::Set(ctr, Nan::New("createInsecure").ToLocalChecked(),
+ Nan::GetFunction(
+ Nan::New<FunctionTemplate>(CreateInsecure)).ToLocalChecked());
+ fun_tpl.Reset(tpl);
+ constructor = new Nan::Callback(ctr);
+ Nan::Set(exports, Nan::New("ServerCredentials").ToLocalChecked(), ctr);
}
-bool ServerCredentials::HasInstance(Handle<Value> val) {
- NanScope();
- return NanHasInstance(fun_tpl, val);
+bool ServerCredentials::HasInstance(Local<Value> val) {
+ Nan::HandleScope scope;
+ return Nan::New(fun_tpl)->HasInstance(val);
}
-Handle<Value> ServerCredentials::WrapStruct(
+Local<Value> ServerCredentials::WrapStruct(
grpc_server_credentials *credentials) {
- NanEscapableScope();
+ Nan::EscapableHandleScope scope;
const int argc = 1;
- Handle<Value> argv[argc] = {
- NanNew<External>(reinterpret_cast<void *>(credentials))};
- return NanEscapeScope(constructor->GetFunction()->NewInstance(argc, argv));
+ Local<Value> argv[argc] = {
+ Nan::New<External>(reinterpret_cast<void *>(credentials))};
+ MaybeLocal<Object> maybe_instance = Nan::NewInstance(
+ constructor->GetFunction(), argc, argv);
+ if (maybe_instance.IsEmpty()) {
+ return scope.Escape(Nan::Null());
+ } else {
+ return scope.Escape(maybe_instance.ToLocalChecked());
+ }
}
grpc_server_credentials *ServerCredentials::GetWrappedServerCredentials() {
@@ -100,96 +114,103 @@ grpc_server_credentials *ServerCredentials::GetWrappedServerCredentials() {
}
NAN_METHOD(ServerCredentials::New) {
- NanScope();
-
- if (args.IsConstructCall()) {
- if (!args[0]->IsExternal()) {
- return NanThrowTypeError(
+ if (info.IsConstructCall()) {
+ if (!info[0]->IsExternal()) {
+ return Nan::ThrowTypeError(
"ServerCredentials can only be created with the provide functions");
}
- Handle<External> ext = args[0].As<External>();
+ Local<External> ext = info[0].As<External>();
grpc_server_credentials *creds_value =
reinterpret_cast<grpc_server_credentials *>(ext->Value());
ServerCredentials *credentials = new ServerCredentials(creds_value);
- credentials->Wrap(args.This());
- NanReturnValue(args.This());
+ credentials->Wrap(info.This());
+ info.GetReturnValue().Set(info.This());
} else {
const int argc = 1;
- Local<Value> argv[argc] = {args[0]};
- NanReturnValue(constructor->GetFunction()->NewInstance(argc, argv));
+ Local<Value> argv[argc] = {info[0]};
+ MaybeLocal<Object> maybe_instance = constructor->GetFunction()->NewInstance(
+ argc, argv);
+ if (maybe_instance.IsEmpty()) {
+ // There's probably a pending exception
+ return;
+ } else {
+ info.GetReturnValue().Set(maybe_instance.ToLocalChecked());
+ }
}
}
NAN_METHOD(ServerCredentials::CreateSsl) {
- // TODO: have the node API support multiple key/cert pairs.
- NanScope();
+ Nan::HandleScope scope;
char *root_certs = NULL;
- if (::node::Buffer::HasInstance(args[0])) {
- root_certs = ::node::Buffer::Data(args[0]);
- } else if (!(args[0]->IsNull() || args[0]->IsUndefined())) {
- return NanThrowTypeError(
+ if (::node::Buffer::HasInstance(info[0])) {
+ root_certs = ::node::Buffer::Data(info[0]);
+ } else if (!(info[0]->IsNull() || info[0]->IsUndefined())) {
+ return Nan::ThrowTypeError(
"createSSl's first argument must be a Buffer if provided");
}
- if (!args[1]->IsArray()) {
- return NanThrowTypeError(
+ if (!info[1]->IsArray()) {
+ return Nan::ThrowTypeError(
"createSsl's second argument must be a list of objects");
}
int force_client_auth = 0;
- if (args[2]->IsBoolean()) {
- force_client_auth = (int)args[2]->BooleanValue();
- } else if (!(args[2]->IsUndefined() || args[2]->IsNull())) {
- return NanThrowTypeError(
+ if (info[2]->IsBoolean()) {
+ force_client_auth = (int)Nan::To<bool>(info[2]).FromJust();
+ } else if (!(info[2]->IsUndefined() || info[2]->IsNull())) {
+ return Nan::ThrowTypeError(
"createSsl's third argument must be a boolean if provided");
}
- Handle<Array> pair_list = Local<Array>::Cast(args[1]);
+ Local<Array> pair_list = Local<Array>::Cast(info[1]);
uint32_t key_cert_pair_count = pair_list->Length();
grpc_ssl_pem_key_cert_pair *key_cert_pairs = new grpc_ssl_pem_key_cert_pair[
key_cert_pair_count];
- Handle<String> key_key = NanNew("private_key");
- Handle<String> cert_key = NanNew("cert_chain");
+ Local<String> key_key = Nan::New("private_key").ToLocalChecked();
+ Local<String> cert_key = Nan::New("cert_chain").ToLocalChecked();
for(uint32_t i = 0; i < key_cert_pair_count; i++) {
- if (!pair_list->Get(i)->IsObject()) {
+ Local<Value> pair_val = Nan::Get(pair_list, i).ToLocalChecked();
+ if (!pair_val->IsObject()) {
delete key_cert_pairs;
- return NanThrowTypeError("Key/cert pairs must be objects");
+ return Nan::ThrowTypeError("Key/cert pairs must be objects");
}
- Handle<Object> pair_obj = pair_list->Get(i)->ToObject();
- if (!pair_obj->HasOwnProperty(key_key)) {
+ Local<Object> pair_obj = Nan::To<Object>(pair_val).ToLocalChecked();
+ MaybeLocal<Value> maybe_key = Nan::Get(pair_obj, key_key);
+ if (maybe_key.IsEmpty()) {
delete key_cert_pairs;
- return NanThrowTypeError(
+ return Nan::ThrowTypeError(
"Key/cert pairs must have a private_key and a cert_chain");
}
- if (!pair_obj->HasOwnProperty(cert_key)) {
+ MaybeLocal<Value> maybe_cert = Nan::Get(pair_obj, cert_key);
+ if (maybe_cert.IsEmpty()) {
delete key_cert_pairs;
- return NanThrowTypeError(
+ return Nan::ThrowTypeError(
"Key/cert pairs must have a private_key and a cert_chain");
}
- if (!::node::Buffer::HasInstance(pair_obj->Get(key_key))) {
+ if (!::node::Buffer::HasInstance(maybe_key.ToLocalChecked())) {
delete key_cert_pairs;
- return NanThrowTypeError("private_key must be a Buffer");
+ return Nan::ThrowTypeError("private_key must be a Buffer");
}
- if (!::node::Buffer::HasInstance(pair_obj->Get(cert_key))) {
+ if (!::node::Buffer::HasInstance(maybe_cert.ToLocalChecked())) {
delete key_cert_pairs;
- return NanThrowTypeError("cert_chain must be a Buffer");
+ return Nan::ThrowTypeError("cert_chain must be a Buffer");
}
key_cert_pairs[i].private_key = ::node::Buffer::Data(
- pair_obj->Get(key_key));
+ maybe_key.ToLocalChecked());
key_cert_pairs[i].cert_chain = ::node::Buffer::Data(
- pair_obj->Get(cert_key));
+ maybe_cert.ToLocalChecked());
}
grpc_server_credentials *creds = grpc_ssl_server_credentials_create(
root_certs, key_cert_pairs, key_cert_pair_count, force_client_auth, NULL);
delete key_cert_pairs;
if (creds == NULL) {
- NanReturnNull();
+ info.GetReturnValue().SetNull();
+ } else {
+ info.GetReturnValue().Set(WrapStruct(creds));
}
- NanReturnValue(WrapStruct(creds));
}
NAN_METHOD(ServerCredentials::CreateInsecure) {
- NanScope();
- NanReturnValue(WrapStruct(NULL));
+ info.GetReturnValue().Set(WrapStruct(NULL));
}
} // namespace node
diff --git a/src/node/ext/server_credentials.h b/src/node/ext/server_credentials.h
index 63903f663c..bf279e481c 100644
--- a/src/node/ext/server_credentials.h
+++ b/src/node/ext/server_credentials.h
@@ -43,12 +43,12 @@ namespace grpc {
namespace node {
/* Wrapper class for grpc_server_credentials structs */
-class ServerCredentials : public ::node::ObjectWrap {
+class ServerCredentials : public Nan::ObjectWrap {
public:
- static void Init(v8::Handle<v8::Object> exports);
- static bool HasInstance(v8::Handle<v8::Value> val);
+ static void Init(v8::Local<v8::Object> exports);
+ static bool HasInstance(v8::Local<v8::Value> val);
/* Wrap a grpc_server_credentials struct in a javascript object */
- static v8::Handle<v8::Value> WrapStruct(grpc_server_credentials *credentials);
+ static v8::Local<v8::Value> WrapStruct(grpc_server_credentials *credentials);
/* Returns the grpc_server_credentials struct that this object wraps */
grpc_server_credentials *GetWrappedServerCredentials();
@@ -64,9 +64,9 @@ class ServerCredentials : public ::node::ObjectWrap {
static NAN_METHOD(New);
static NAN_METHOD(CreateSsl);
static NAN_METHOD(CreateInsecure);
- static NanCallback *constructor;
+ static Nan::Callback *constructor;
// Used for typechecking instances of this javascript class
- static v8::Persistent<v8::FunctionTemplate> fun_tpl;
+ static Nan::Persistent<v8::FunctionTemplate> fun_tpl;
grpc_server_credentials *wrapped_credentials;
};
diff --git a/src/node/package.json b/src/node/package.json
index bb8987cc0d..edcf17ba1e 100644
--- a/src/node/package.json
+++ b/src/node/package.json
@@ -27,7 +27,7 @@
"dependencies": {
"bindings": "^1.2.0",
"lodash": "^3.9.3",
- "nan": "^1.5.0",
+ "nan": "^2.0.0",
"protobufjs": "^4.0.0"
},
"devDependencies": {