From 232ff022ab24939bbef2ca48d097688ebe259be1 Mon Sep 17 00:00:00 2001 From: Mohamad mehdi Kharatizadeh Date: Tue, 6 Mar 2018 01:32:55 +0330 Subject: [PATCH] stronger checking for functions in client.js checking for functions simply by instanceof would render library usesless in vm or REPL contexts. because if client is created in another V8 context, typeof would still return "function" but instanceof Function would fail and return false for functions and arrow functions. thus it would be impossible to create client before starting a REPL context. --- packages/grpc-native-core/src/client.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/grpc-native-core/src/client.js b/packages/grpc-native-core/src/client.js index 79868df46..e5ce8a3e1 100644 --- a/packages/grpc-native-core/src/client.js +++ b/packages/grpc-native-core/src/client.js @@ -429,7 +429,7 @@ exports.Client = Client; Client.prototype.makeUnaryRequest = function(path, serialize, deserialize, argument, metadata, options, callback) { - if (options instanceof Function) { + if (_.isFunction(options)) { callback = options; if (metadata instanceof Metadata) { options = {}; @@ -437,7 +437,7 @@ Client.prototype.makeUnaryRequest = function(path, serialize, deserialize, options = metadata; metadata = new Metadata(); } - } else if (metadata instanceof Function) { + } else if (_.isFunction(metadata)) { callback = metadata; metadata = new Metadata(); options = {}; @@ -450,7 +450,7 @@ Client.prototype.makeUnaryRequest = function(path, serialize, deserialize, } if (!((metadata instanceof Metadata) && (options instanceof Object) && - (callback instanceof Function))) { + (_.isFunction(callback)))) { throw new Error('Argument mismatch in makeUnaryRequest'); } @@ -508,7 +508,7 @@ Client.prototype.makeUnaryRequest = function(path, serialize, deserialize, Client.prototype.makeClientStreamRequest = function(path, serialize, deserialize, metadata, options, callback) { - if (options instanceof Function) { + if (_.isFunction(options)) { callback = options; if (metadata instanceof Metadata) { options = {}; @@ -516,7 +516,7 @@ Client.prototype.makeClientStreamRequest = function(path, serialize, options = metadata; metadata = new Metadata(); } - } else if (metadata instanceof Function) { + } else if (_.isFunction(metadata)) { callback = metadata; metadata = new Metadata(); options = {}; @@ -529,7 +529,7 @@ Client.prototype.makeClientStreamRequest = function(path, serialize, } if (!((metadata instanceof Metadata) && (options instanceof Object) && - (callback instanceof Function))) { + (_.isFunction(callback)))) { throw new Error('Argument mismatch in makeClientStreamRequest'); }