diff options
author | Michael Lumish <mlumish@google.com> | 2017-03-24 13:51:47 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-24 13:51:47 -0700 |
commit | cbe5036bb74d4e141f79b052e1325dd550867969 (patch) | |
tree | 0f19c7e63478b7d37e44c670113801ae9cd4e2b5 /src/node | |
parent | ac7f90da26522965c420623a7c008c2eede464f3 (diff) | |
parent | ac4a7283ee77bfe5118a061a62930019ff090e37 (diff) |
Merge branch 'master' into node_protobuf_js_6_upgrade
Diffstat (limited to 'src/node')
-rw-r--r-- | src/node/ext/server_uv.cc | 2 | ||||
-rw-r--r-- | src/node/src/server.js | 13 | ||||
-rw-r--r-- | src/node/test/surface_test.js | 26 |
3 files changed, 37 insertions, 4 deletions
diff --git a/src/node/ext/server_uv.cc b/src/node/ext/server_uv.cc index bf8b609a63..c5e5ca9f42 100644 --- a/src/node/ext/server_uv.cc +++ b/src/node/ext/server_uv.cc @@ -47,12 +47,12 @@ namespace grpc { namespace node { using Nan::Callback; +using Nan::MaybeLocal; using v8::External; using v8::Function; using v8::FunctionTemplate; using v8::Local; -using v8::MaybeLocal; using v8::Object; using v8::Value; diff --git a/src/node/src/server.js b/src/node/src/server.js index 77d50b8250..3450abed08 100644 --- a/src/node/src/server.js +++ b/src/node/src/server.js @@ -755,9 +755,16 @@ Server.prototype.addService = function(service, implementation) { } var impl; if (implementation[name] === undefined) { - common.log(grpc.logVerbosity.ERROR, 'Method handler for ' + - attrs.path + ' expected but not provided'); - impl = defaultHandler[method_type]; + /* Handle the case where the method is passed with the name exactly as + written in the proto file, instead of using JavaScript function + naming style */ + if (implementation[attrs.originalName] === undefined) { + common.log(grpc.logVerbosity.ERROR, 'Method handler ' + name + ' for ' + + attrs.path + ' expected but not provided'); + impl = defaultHandler[method_type]; + } else { + impl = _.bind(implementation[attrs.originalName], implementation); + } } else { impl = _.bind(implementation[name], implementation); } diff --git a/src/node/test/surface_test.js b/src/node/test/surface_test.js index 026d2c7dc2..783028fa99 100644 --- a/src/node/test/surface_test.js +++ b/src/node/test/surface_test.js @@ -166,6 +166,32 @@ describe('Server.prototype.addService', function() { server.addService(mathServiceAttrs, dummyImpls); }); }); + it('Should allow method names as originally written', function() { + var altDummyImpls = { + 'Div': function() {}, + 'DivMany': function() {}, + 'Fib': function() {}, + 'Sum': function() {} + }; + assert.doesNotThrow(function() { + server.addProtoService(mathService, altDummyImpls); + }); + }); + it('Should have a conflict between name variations', function() { + /* This is really testing that both name variations are actually used, + by checking that the method actually gets registered, for the + corresponding function, in both cases */ + var altDummyImpls = { + 'Div': function() {}, + 'DivMany': function() {}, + 'Fib': function() {}, + 'Sum': function() {} + }; + server.addProtoService(mathService, altDummyImpls); + assert.throws(function() { + server.addProtoService(mathService, dummyImpls); + }); + }); it('Should fail if the server has been started', function() { server.start(); assert.throws(function() { |