Added an inline C++ function to replace a deprecated nan function

pull/2955/head
murgatroid99 9 years ago
parent 2194cd8fd4
commit 28c37b8856
  1. 4
      src/node/ext/call.cc
  2. 13
      src/node/ext/call.h
  3. 2
      src/node/ext/server.cc

@ -619,7 +619,7 @@ NAN_METHOD(Call::StartBatch) {
call->wrapped_call, &ops[0], nops, new struct tag( call->wrapped_call, &ops[0], nops, new struct tag(
callback, op_vector.release(), resources), NULL); callback, op_vector.release(), resources), NULL);
if (error != GRPC_CALL_OK) { if (error != GRPC_CALL_OK) {
return NanThrowError("startBatch failed", error); return NanThrowError(nanErrorWithCode("startBatch failed", error));
} }
CompletionQueueAsyncWorker::Next(); CompletionQueueAsyncWorker::Next();
NanReturnUndefined(); NanReturnUndefined();
@ -633,7 +633,7 @@ NAN_METHOD(Call::Cancel) {
Call *call = ObjectWrap::Unwrap<Call>(args.This()); Call *call = ObjectWrap::Unwrap<Call>(args.This());
grpc_call_error error = grpc_call_cancel(call->wrapped_call, NULL); grpc_call_error error = grpc_call_cancel(call->wrapped_call, NULL);
if (error != GRPC_CALL_OK) { if (error != GRPC_CALL_OK) {
return NanThrowError("cancel failed", error); return NanThrowError(nanErrorWithCode("cancel failed", error));
} }
NanReturnUndefined(); NanReturnUndefined();
} }

@ -51,6 +51,19 @@ namespace node {
using std::unique_ptr; using std::unique_ptr;
using std::shared_ptr; using std::shared_ptr;
/**
* Helper function for throwing errors with a grpc_call_error value.
* Modified from the answer by Gus Goose to
* http://stackoverflow.com/questions/31794200.
*/
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);
}
v8::Handle<v8::Value> ParseMetadata(const grpc_metadata_array *metadata_array); v8::Handle<v8::Value> ParseMetadata(const grpc_metadata_array *metadata_array);
class PersistentHolder { class PersistentHolder {

@ -235,7 +235,7 @@ NAN_METHOD(Server::RequestCall) {
new struct tag(new NanCallback(args[0].As<Function>()), ops.release(), new struct tag(new NanCallback(args[0].As<Function>()), ops.release(),
shared_ptr<Resources>(nullptr))); shared_ptr<Resources>(nullptr)));
if (error != GRPC_CALL_OK) { if (error != GRPC_CALL_OK) {
return NanThrowError("requestCall failed", error); return NanThrowError(nanErrorWithCode("requestCall failed", error));
} }
CompletionQueueAsyncWorker::Next(); CompletionQueueAsyncWorker::Next();
NanReturnUndefined(); NanReturnUndefined();

Loading…
Cancel
Save