Skip to content

Commit

Permalink
stronger checking for functions in client.js
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Mohamad mehdi Kharatizadeh committed Mar 6, 2018
1 parent ed2a048 commit 232ff02
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/grpc-native-core/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,15 +429,15 @@ 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 = {};
} else {
options = metadata;
metadata = new Metadata();
}
} else if (metadata instanceof Function) {
} else if (_.isFunction(metadata)) {
callback = metadata;
metadata = new Metadata();
options = {};
Expand All @@ -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');
}

Expand Down Expand Up @@ -508,15 +508,15 @@ 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 = {};
} else {
options = metadata;
metadata = new Metadata();
}
} else if (metadata instanceof Function) {
} else if (_.isFunction(metadata)) {
callback = metadata;
metadata = new Metadata();
options = {};
Expand All @@ -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');
}

Expand Down

0 comments on commit 232ff02

Please sign in to comment.