Skip to content

Commit

Permalink
Stricter check for is function
Browse files Browse the repository at this point in the history
instanceof Function fails when run in different contexts, this check allows it to work in normal as well as vm context.
  • Loading branch information
zereraz committed Apr 20, 2021
1 parent 545a935 commit b6181d9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/grpc-native-core/src/client_interceptors.js
Expand Up @@ -1335,15 +1335,15 @@ var listenerGenerators = {
* @return {grpc~Listener}
*/
function getLastListener(method_definition, emitter, callback) {
if (emitter instanceof Function) {
if (toString.call(emitter) === '[object Function]') {
callback = emitter;
callback = function() {};
}
if (!(callback instanceof Function)) {
if (!(toString.call(callback) === '[object Function]')) {
callback = function() {};
}
if (!((emitter instanceof EventEmitter) &&
(callback instanceof Function))) {
(toString.call(callback) === '[object Function]'))) {
throw new Error('Argument mismatch in getLastListener');
}
var method_type = common.getMethodType(method_definition);
Expand Down Expand Up @@ -1376,7 +1376,7 @@ function getInterceptingCall(method_definition, options,
* @return {Interceptor}
*/
function _getLastInterceptor(method_definition, channel, responder) {
var callback = (responder instanceof Function) ? responder : function() {};
var callback = (toString.call(responder) === '[object Function]') ? responder : function() {};
var emitter = (responder instanceof EventEmitter) ? responder :
new EventEmitter();
var method_type = common.getMethodType(method_definition);
Expand Down

0 comments on commit b6181d9

Please sign in to comment.