-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
src: add context-aware helpers and init macro #21318
Conversation
e292f6d
to
f25f30b
Compare
src/node.h
Outdated
|
||
recv->PrototypeTemplate()->Set(fn_name, t); | ||
} | ||
|
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 wouldn’t be a fan of including this in our public API, unless there’s a reason why we would export it from core
We originally had more core of this sort around (e.g. node_object_wrap.h
), but it’s a good idea that this generally moved into Nan territory? I’d suggest PR’ing it there
doc/api/addons.md
Outdated
@@ -98,6 +98,107 @@ the `.node` suffix). | |||
In the `hello.cc` example, then, the initialization function is `Initialize` | |||
and the addon module name is `addon`. | |||
|
|||
When building your addon with node-gyp, using the macro `NODE_GYP_MODULE_NAME` |
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.
node-gyp
-> `node-gyp`
for consistency with other mentions?
doc/api/addons.md
Outdated
invocation of `NODE_MODULE_INIT()`: | ||
* `Local<Object> exports`, | ||
* `Local<Value> module`, and | ||
* `Local<Context> context |
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.
Missing final backtick and period?
doc/api/addons.md
Outdated
* Constructing an instance of this class in the addon initializer such that | ||
`exports` is passed to the constructor, | ||
* Storing the instance in a `v8::External`, and | ||
* exposing methods to JavaScript via `node::SetMethodWithData()` and via |
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.
Should the first letter case be unified in this list?
e83beeb
to
0f7d65d
Compare
@addaleax @bnoordhuis I have reduced the scope of the PR to the |
@vsemozhetbyt I have fixed the issues you mention. |
Doc format LGTM. |
237c4f3
to
ac20ee3
Compare
doc/api/addons.md
Outdated
@@ -98,6 +98,120 @@ the `.node` suffix). | |||
In the `hello.cc` example, then, the initialization function is `Initialize` | |||
and the addon module name is `addon`. | |||
|
|||
When building your addon with `node-gyp`, using the macro `NODE_GYP_MODULE_NAME` |
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.
nit: "When building addons with..."
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.
Yep, I let that one slip :) Thanks!
ac20ee3
to
49360b2
Compare
49360b2
to
6b68df1
Compare
Another CI before I land: https://ci.nodejs.org/job/node-test-pull-request/15639/ |
this needs another approval to land |
@devsnek aaah, thank you! Wasn't sure. |
It seems our docs state only one approving is needed to land a not fast-track PR. |
@vsemozhetbyt actually, it says it must be two if a Collaborator is the originator of the PR. I checked after @devsnek's reminder: https://github.com/nodejs/node/blob/master/COLLABORATOR_GUIDE.md#code-reviews |
Do you refer this sentence?
I read it as "One Collaborator is the PR author, another Collaborator is a reviewer". |
I don't read it that way, because I know that the PR's author may not
approve. Therefore, since all PRs need at least one approver, and a
Collaborator's PR needs and additional approver, I conclude that a
Collaborator's PR needs to approvers. Still, it should maybe state
explicitly that a Collaborator's PR needs the approver of two Collaborators.
…On Wed, Jun 27, 2018 at 10:29 AM, Vse Mozhet Byt ***@***.***> wrote:
Do you refer this sentence?
In the case of pull requests proposed by an existing Collaborator, an
additional Collaborator is required for sign-off.
I read it as "One Collaborator is the PR author, another Collaborator is a
reviewer".
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#21318 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AA7k0YUDmU2AqXPuk33Qw_GV-exV3InLks5uA5awgaJpZM4UmriR>
.
|
Let's see how others understand this. It seems we have a bit confusing wording here. |
This does not need a second reviewer, although I would try pinging a relevant team or two before landing, just to get a second one. |
@nodejs/collaborators in the spirit of #21565 (comment), could somebody else please have a look? 🙂 |
Aww, the dreaded mention. P.S. I'll take a look :) |
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.
LGTM
doc/api/addons.md
Outdated
### Context-aware addons | ||
|
||
There are environments in which Node.js addons may need to be loaded multiple | ||
times in multiple contexts. The macro `NODE_MODULE_INIT()` will construct an |
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.
Can you please articulate what could be those cases?
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.
@mcollina how about the new paragraph I added?
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.
That’s perfect!
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.
LGTM, but if I were you, I'd wait for @addaleax's review.
@addaleax could you please take another look? |
Introduces macro `NODE_MODULE_INIT()` which creates the boilerplate for a context-aware module which can be loaded multiple times via the special symbol mechanism. Additionally, provides an example of using the new macro to construct an addon which stores per-addon-instance data in a heap-allocated structure that gets passed to each binding, rather than in a collection of global static variables. Re: nodejs#21291 (comment)
f81217c
to
9402ca1
Compare
Rebased and added doc for |
Landed in 602da64. |
Introduces macros `NODE_MODULE_INITIALIZER` which expands to the name of the special symbol that process.dlopen() will look for to initialize an addon, and `NODE_MODULE_INIT()` which creates the boilerplate for a context-aware module which can be loaded multiple times via the special symbol mechanism. Additionally, provides an example of using the new macro to construct an addon which stores per-addon-instance data in a heap-allocated structure that gets passed to each binding, rather than in a collection of global static variables. Re: nodejs#21291 (comment) PR-URL: nodejs#21318 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com>
CI was not green. I think we need stronger wording in our docs about not landing stuff when CI is not green. I'll open a PR for that right now. If you have a mostly-green node-test-pull-request, you're fairly certain the not-green stuff isn't relevant to your changes, and you want to re-run just the things that aren't green, use "Resume Build" on the left menu. It will create a new node-test-pull-request, copy over all the green stuff, and only re-run the red/yellow/grey stuff.
EDIT: Can't re-run CI because the branch has been deleted. So in lieu of that, here's a node-daily-master run manually kicked off to re-test this: https://ci.nodejs.org/job/node-daily-master/1203/ |
@Trott sorry about that! One job failed on what looked like an infra issue (unable to create a directory). Using "Resume Build" is an awesome option! I didn't know about it. |
Sorry, didn't mean to pick on you! No need to apologize. You're far from alone. I'm just trying to spread the word about Resume Build. :-D (I didn't know about it until someone else on Build showed it to me...I think it was @refack.) |
Introduces macros `NODE_MODULE_INITIALIZER` which expands to the name of the special symbol that process.dlopen() will look for to initialize an addon, and `NODE_MODULE_INIT()` which creates the boilerplate for a context-aware module which can be loaded multiple times via the special symbol mechanism. Additionally, provides an example of using the new macro to construct an addon which stores per-addon-instance data in a heap-allocated structure that gets passed to each binding, rather than in a collection of global static variables. Re: #21291 (comment) PR-URL: #21318 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com>
Introduces macro
NODE_MODULE_INIT()
which creates the boilerplate fora context-aware module which can be loaded multiple times via the
special symbol mechanism.
Also introduces class
node::WeakData
with which one can weaklyassociate a native class instance with a JavaScript object, and
convenience methods
node::SetMethodWithData()
andnode::SetPrototypeMethodWithData()
which pass a native pointerthrough to bindings.
Together, these APIs allow one to avoid using global static data in
an addon.
Re: #21291 (comment)
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes