Skip to content

Commit 232ff02

Browse files
author
Mohamad mehdi Kharatizadeh
committed
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.
1 parent ed2a048 commit 232ff02

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

packages/grpc-native-core/src/client.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -429,15 +429,15 @@ exports.Client = Client;
429429
Client.prototype.makeUnaryRequest = function(path, serialize, deserialize,
430430
argument, metadata, options,
431431
callback) {
432-
if (options instanceof Function) {
432+
if (_.isFunction(options)) {
433433
callback = options;
434434
if (metadata instanceof Metadata) {
435435
options = {};
436436
} else {
437437
options = metadata;
438438
metadata = new Metadata();
439439
}
440-
} else if (metadata instanceof Function) {
440+
} else if (_.isFunction(metadata)) {
441441
callback = metadata;
442442
metadata = new Metadata();
443443
options = {};
@@ -450,7 +450,7 @@ Client.prototype.makeUnaryRequest = function(path, serialize, deserialize,
450450
}
451451
if (!((metadata instanceof Metadata) &&
452452
(options instanceof Object) &&
453-
(callback instanceof Function))) {
453+
(_.isFunction(callback)))) {
454454
throw new Error('Argument mismatch in makeUnaryRequest');
455455
}
456456

@@ -508,15 +508,15 @@ Client.prototype.makeUnaryRequest = function(path, serialize, deserialize,
508508
Client.prototype.makeClientStreamRequest = function(path, serialize,
509509
deserialize, metadata,
510510
options, callback) {
511-
if (options instanceof Function) {
511+
if (_.isFunction(options)) {
512512
callback = options;
513513
if (metadata instanceof Metadata) {
514514
options = {};
515515
} else {
516516
options = metadata;
517517
metadata = new Metadata();
518518
}
519-
} else if (metadata instanceof Function) {
519+
} else if (_.isFunction(metadata)) {
520520
callback = metadata;
521521
metadata = new Metadata();
522522
options = {};
@@ -529,7 +529,7 @@ Client.prototype.makeClientStreamRequest = function(path, serialize,
529529
}
530530
if (!((metadata instanceof Metadata) &&
531531
(options instanceof Object) &&
532-
(callback instanceof Function))) {
532+
(_.isFunction(callback)))) {
533533
throw new Error('Argument mismatch in makeClientStreamRequest');
534534
}
535535

0 commit comments

Comments
 (0)