-
Notifications
You must be signed in to change notification settings - Fork 470
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
Set up doc-comments and doxygen #34
Conversation
While someone has created a doxygen npm package, it apparently isn't widely used. I tried it out and it doesn't work very well: there's no way to download the doxygen binaries only when needed (so it's very slow when running repeatedly), and it doesn't show progress while downloading or running. |
Related: #6 Write documentation for C++ APIs |
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.
Looks good to me, comments are mostly just nitpicky grammar and such.
Only glanced over the Doxyfile. This is a huge file.
👍
napi.h
Outdated
/// Converts to another type of `Napi::Value`, when the actual type is known or assumed. | ||
/// | ||
/// This conversion does NOT coerce the type. Calling any methods inappropriate for the actual | ||
/// value type will cause `Napi::Error`s to be thrown. |
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.
Just nitpicky, should we write this as such?
Calling any methods inappropriate for the actual value type will throw Napi::Error
.
napi.h
Outdated
/// Creates a new String value from a UTF-8 encoded C string. | ||
static String New( | ||
napi_env env, ///< N-API environment | ||
const char* value ///< UTF-8 encoded C string |
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.
C string seems to imply "null-terminated" but should we explicitly mention that here since there is an overload which takes a length parameter?
napi.h
Outdated
static String New( | ||
napi_env env, ///< N-API environment | ||
const char* value, ///< UTF-8 encoded C string | ||
size_t length ///< length of the string in bytes |
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.
length is not capitalized, seems like it should be to be consistent with other comments.
napi.h
Outdated
/// may be changed to/from a strong reference by adjusting the refcount. | ||
/// | ||
/// The referenced value is not immediately destroyed when the reference count is zero; it is | ||
/// merely then eligible for if there are no other references to the value. |
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.
Eligible for destruction?
napi.h
Outdated
/// Napi::Value GetSomething(const Napi::CallbackInfo& info); | ||
/// void SetSomething(const Napi::CallbackInfo& info, const Napi::Value& value); | ||
/// Napi::Value DoSomething(const Napi::CallbackInfo& info); | ||
/// } |
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.
Nitpicky: This brace is not aligned with the class statement - looks like it's 2 spaces further right.
Thanks @boingoing. I pushed an update that fixed all the issues you commented on. |
I was thinking an easy way to publish the generated API docs would be to use GitHub Pages. Based on the GitHub help, I created a @mhdawson Can you go to the settings for this repo and enable GitHub Pages, using the |
Docs are visible now at https://nodejs.github.io/node-api/ |
- Add doc-comments to a few of the classes in napi.h - Add a doxygen config file
@digitalinfinity @gabrielschulhof @mhdawson @addaleax Any feedback on the documentation format? |
README.md
Outdated
### API Documentation | ||
|
||
- [ABI-Stable C APIs in Node.js](https://nodejs.org/dist/latest-v7.x/docs/api/n-api.html) | ||
- [C++ APIs in this package](https://nodejs.github.io/node-api/namespace_napi.html) |
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.
Aaaah this is so cool! Thank you for setting it up!
README.md
Outdated
@@ -5,6 +5,13 @@ Node.js API (N-API), along with library code that enables | |||
backward-compatibility with use with older versions of Node.js that do | |||
not have N-API built-in. | |||
|
|||
### API Documentation | |||
|
|||
- [ABI-Stable C APIs in Node.js](https://nodejs.org/dist/latest-v7.x/docs/api/n-api.html) |
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.
latest-v7.x
only works by accident (and it might/should get deleted) – I would just stick with linking to https://nodejs.org/api/n-api.html and accept that it only works once the 8.0.0 release is out
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.
Yes. I wanted to link to https://github.com/nodejs/node/blob/master/doc/api/n-api.md for now, but links to external markdown files confuse the Doxygen generator.
napi.h
Outdated
/// wrapper automatically converts and throws it as a JavaScript exception. | ||
/// | ||
/// Catching a C++ exception of type `Napi::Error` also clears the JavaScript exception. Of | ||
/// course it may be then re-thrown, which restores the JavaScript exception. |
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.
This paragraph sounds a bit confusing (it sounds like C++ exception management affects the JS VM’s state), I would be okay with just deleting it.
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.
Reworded and combined with the previous paragraph.
napi.h
Outdated
/// a C++ exception of type `Napi::Error`. | ||
/// | ||
/// If a C++ exception of type `Napi::Error` escapes from a N-API C++ callback, then the N-API | ||
/// wrapper automatically converts and throws it as a JavaScript exception. |
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.
By the way, should we catch all exceptions coming from C++ callbacks and convert them to JS errors? I don’t think there’s a way to do anything more meaningful (or at least I would assume JS engines don’t like it if the call stack unwinds outside of their control)
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'm not sure. I suppose we could catch any kind of std::exception
and then copy the message into a JS error. But would that be safe, or could some exceptions leave the module in an inconsistent state?
The alternative is to just let any other kinds of uncaught C++ exceptions result in a crash, which is what happens now.
napi.h
Outdated
/// exception of type `Napi::Error`, until it is either caught while still in C++, or else | ||
/// automatically re-thrown as a JavaScript exception when the callback returns to JavaScript. | ||
/// | ||
/// #### Example 2 - Ignoring a NAPI exception: |
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.
s/Ignoring/not catching/?
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.
Fixed.
napi.h
Outdated
/// exception of type `Napi::Error`, until it is either caught while still in C++, or else | ||
/// automatically re-thrown as a JavaScript exception when the callback returns to JavaScript. | ||
/// | ||
/// #### Example 3 - Handling a NAPI exception: |
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.
N-API?
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.
Fixed.
Sorry for the late response, I've been out all this week. Looks like you
found somebody else to configure it.
Regards,
Michael (M.H.) Dawson
Runtime Technologies Node.js Technical Lead
Software Developer and Master Inventor
Phone: 1-613-356-5484 | Phone: 1-343-882-2473
E-mail: [email protected]
Find me on:
3755 Riverside Drive
Ottawa, ON K1V 1B8
Canada
From: Jason Ginchereau <[email protected]>
To: nodejs/node-api <[email protected]>
Cc: Michael Dawson/Ottawa/IBM@IBMCA, Mention
<[email protected]>
Date: 05/03/2017 05:52 PM
Subject: Re: [nodejs/node-api] Set up doc-comments and doxygen
(#34)
I was thinking an easy way to publish the generated API docs would be to
use GitHub Pages. Based on the GitHub help, I created a gh-pages branch in
this repo and pushed a commit with all the generated docs.
@mhdawson Can you go to the settings for this repo and enable GitHub
Pages, using the gh-pages branch? Then I think the docs should be visible
at https://nodejs.github.io/node-api/
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
napi.h
:Value
,String
,Error
To generate documents:
Doxyfile
configuration file added in this change.Doxygen supports multiple different doc-comment styles and text formatting methods. Here, I have chosen:
@command
or\command
formatting instructions that are also supported. We can still mix in any of Doxygen's supported commands.Doxygen also supports Javadoc style comments (
/** ... */
) but those would not be as nice here IMO.