-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Modules: adding load linked modules feature #8386
Conversation
if (cache->Has(module)) { | ||
exports = cache->Get(module)->ToObject(); | ||
args.GetReturnValue().Set(exports); | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead do the following:
exports = cache->Get(module).As<Object>();
if (cache->IsObject())
return args.GetReturnValue().Set(exports);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got these snippets from somewhere else in node.cc
actually. Is the above new for what's currently in master?
I was gonna remove this duplication once I got the go ahead on the general approach.
So most of this comes from Binding()
. Should we change the code there as well and/or consolidate into a reusable function to avoid duplication?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just a different way of accomplishing the same thing. Don't bother changing the code anywhere that isn't directly involved with your code changes.
Left a couple style comments. To make sure I understand correctly, this is a feature that allows injecting code directly into the Node build? |
Yes, all you'd need to change is Wanted to point out again that this is based on |
Well, since master is behind v0.12, and we're just going to merge v0.12 into master once it's released just keep it as-is. Whether this is merged into v0.12 I'll leave open. /cc @tjfontaine @indutny |
@trevnorris I updated this PR to match the style you indicated and tested (manually) that the feature still works the same way. Do we need to add an example or some way to at least manually test this feature somewhere? |
ping @indutny @tjfontaine What are your thoughts on this patch? |
@@ -2030,6 +2032,10 @@ extern "C" void node_module_register(void* m) { | |||
if (mp->nm_flags & NM_F_BUILTIN) { | |||
mp->nm_link = modlist_builtin; | |||
modlist_builtin = mp; | |||
} else if (!node_is_initialized){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space between )
and {
One nit, otherwise LGTM. Let's land it in v0.12 |
@indutny fixed the nit, waiting for @tjfontaine to reply to #8386 (comment). |
Just as a note, I hid the |
- introduced NM_F_LINKED flag to identify linked modules - setting node_is_initialized after calling V8::Initialize in order to make the right decision during initial module registration - introduced modlist_linked in order to track modules that were pre-registered in order to complete it once node is initialized - completing registration of linked module similarly to the way it's done inside DLOpen
- introduced NM_F_LINKED flag to identify linked modules - setting node_is_initialized after calling V8::Initialize in order to make the right decision during initial module registration - introduced modlist_linked in order to track modules that were pre-registered in order to complete it once node is initialized - completing registration of linked module similarly to the way it's done inside DLOpen PR-URL: #8386 Reviewed-by: Trevor Norris <trev.norris@gmail.com>
Since the API is "hidden" going ahead and merging it. We can work out the details with usage and make it public in the future. Landed in c131c1f. |
This PR is mainly to get some guidance if I'm on the right track (i.e. what @tjfontaine had in mind).
It enables to include C++ modules simply by adding them to the
node.gyp
file and loading them from JS viaprocess.linkedBinding
.It is based on
v0.12
, but I can rebase onmaster
if that is better.Please lmk what else needs to be done to get this completed, i.e do we need tests (a little hard to do since it needs to rebuild node to run) and/or an example of how this is used?
make the right decision during initial module registration
pre-registered in order to complete it once node is initialized
done inside DLOpen
Example
Assuming
src/simple.cc
registers itself via:node.gyp
additionThis addition can be done manually or via nad which injects parameters derived from the existing
binding.gyp
intonode.gyp
via a simple command.Loading inside
simple.js