From b6181d93dab330f12a9e4f74b121d01c57a93e2a Mon Sep 17 00:00:00 2001 From: Sahebjot singh Date: Tue, 20 Apr 2021 18:47:39 +0530 Subject: [PATCH] Stricter check for is function instanceof Function fails when run in different contexts, this check allows it to work in normal as well as vm context. --- packages/grpc-native-core/src/client_interceptors.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/grpc-native-core/src/client_interceptors.js b/packages/grpc-native-core/src/client_interceptors.js index 2cf48481d..766b412e2 100644 --- a/packages/grpc-native-core/src/client_interceptors.js +++ b/packages/grpc-native-core/src/client_interceptors.js @@ -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); @@ -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);