-
Notifications
You must be signed in to change notification settings - Fork 647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stronger checking for functions in client.js #204
Conversation
Thank you for your pull request. Before we can look at your contribution, we need to ensure all contributors are covered by a Contributor License Agreement. After the following items are addressed, please respond with a new comment here, and the automated system will re-verify.
Regards, |
I've signed CLA |
Can you share reproduction steps for this problem? |
Also, since we are already depending on lodash anyway, I would prefer to just use |
Dear good sir.. The following example fails with error message Argument Mismatch const grpc = require('grpc');
const f = '../proto/proto/math.proto';
const vm = require('vm');
parsed = grpc.load(f);
const service = new parsed.math.MathService('localhost:8000', grpc.credentials.createInsecure());
const sandbox = { service: service };
vm.createContext(sandbox);
script = `
ch = service.add((err, data) => console.log(err, data));
ch.write(1);
ch.write(5);
ch.end();
`;
vm.runInContext(script, sandbox); |
A more general example of V8 contexts and behavior of const vm = require('vm');
const sandbox = {
isFunction: f => f instanceof Function,
result: null
};
vm.createContext(sandbox);
// prints:
// outof sandbox: true
console.log('outof sandbox:', sandbox.isFunction(() => console.log()));
script = `
result = isFunction(() => console.log());
`;
vm.runInContext(script, sandbox);
// prints:
// inside sandbox: false
console.log('inside sandbox:', sandbox.result); |
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.
I apologize for not noticing that.. I've replaced usage of isFunction with _.isFunction |
Thank you for your contribution. This change will definitely go into the 1.11.x release, and we may decide to backport it to 1.10.x. |
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.
Mainly I ran into problem using grpcc with following error:
After inspecting the problem and reading node docs about V8 contexts and so forth I concluded that "instanceof" is not evaluated properly because when a callback is created in REPL context, it is treated as when functions are created in another window and instanceof would fail.