Skip to content

Conversation

@justus-hildebrand
Copy link
Collaborator

@justus-hildebrand justus-hildebrand commented Jan 22, 2018

module's name in JS is given into RegisterModule() as a parameter. If no name is given, process.binding() will have to be called manually.

cmfcmf
cmfcmf previously approved these changes Jan 22, 2018
Copy link
Collaborator

@cmfcmf cmfcmf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

src/node.cc Outdated
node_module_register(module);

if(auto_bind) {
Evaluate(name + " = process.binding('" + name + "')");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Should we check name for invalid characters?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from what I can see, nodejs' Binding function (defined in node.cc, invoked by process.binding()) throws a JS exception when no module named name is found, so this check is made there already.

ATM, I don't really know how node's exceptions work, so if you don't have a solution to handling these at this moment, I'd say we attach it to issue #17 for now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or open a new issue for exception handling (vs. MaybeLocal stuff)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about the case when invalid js code is executed:

std::name name = "123-foo"; // or "while(true) {}; foo"
Evaluate(name + " = process.binding('" + name + "')");
// Evaluate("123-foo = process.binding('123-foo')");
// Error: 123-foo isn't allowed as variable name.

Also, maybe add const in front of the variable name in JS.

Copy link
Collaborator Author

@justus-hildebrand justus-hildebrand Jan 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried it out, throws a SyntaxError from node.js. Which makes sense, since all errors produced by javascript code (even by faulty JS code) result in JS exceptions/errors.

So again, (IMO) this should still be handled with these exceptions just like with every other call to Evaluate().

const is a good call.

@justus-hildebrand
Copy link
Collaborator Author

closes #26

If string is given, module is bound to the JS variable named by the
target string. If no string is given, the user has to call
process.biding() themselves.
@justus-hildebrand justus-hildebrand dismissed cmfcmf’s stale review January 22, 2018 16:10

changes after approval


void RegisterModule(const std::string & name, const addon_context_register_func & callback, void *priv) {
node::node_module* module = new node::node_module();
void RegisterModule(const std::string & name, const addon_context_register_func & callback, void *priv, const std::string & target) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO it would be better to swap the priv and target parameters to match the other RegisterModule function

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i mean, i see what you mean, but even then the parameters won't match, right? one takes a callback, the other takes the <string, callback> map...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, true. Maybe it's indeed not needed to swap the parameters.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will leave it as is then, I think. Is everything else in this PR ok? If so, I think we're ready to merge.

Copy link
Collaborator

@cmfcmf cmfcmf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 👍 Good to merge!

@justus-hildebrand justus-hildebrand merged commit 6126411 into node_lib Jan 24, 2018
@justus-hildebrand justus-hildebrand deleted the process-binding branch January 24, 2018 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants