-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
doc: better linkaged to node-addon-api #24371
Closed
Closed
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,13 +34,53 @@ properties: | |
handling section [Error Handling][]. | ||
|
||
The N-API is a C API that ensures ABI stability across Node.js versions | ||
and different compiler levels. However, we also understand that a C++ | ||
API can be easier to use in many cases. To support these cases we expect | ||
there to be one or more C++ wrapper modules that provide an inlineable C++ | ||
API. Binaries built with these wrapper modules will depend on the symbols | ||
for the N-API C based functions exported by Node.js. These wrappers are not | ||
part of N-API, nor will they be maintained as part of Node.js. One such | ||
example is: [node-addon-api](https://github.com/nodejs/node-addon-api). | ||
and different compiler levels. A C++ API can be easier to use | ||
. To support using C++, the project maintains a | ||
C++ wrapper module called | ||
[node-addon-api](https://github.com/nodejs/node-addon-api). | ||
This wrapper provides an inlineable C++ API. Binaries built | ||
with `node-addon-api` will depend on the symbols for the N-API C-based | ||
functions exported by Node.js. `node-addon-api` is a more | ||
efficient way to write code that calls N-API. Take, for example, the | ||
following `node-addon-api` code. The first section shows the | ||
`node-add-api` code and the section section shows what actually gets | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, there are two "section"s. |
||
used in the addon. | ||
|
||
```C++ | ||
Object obj = Object::New(env); | ||
obj["foo"] = String::New(env, "bar"); | ||
``` | ||
|
||
```C++ | ||
napi_status status; | ||
napi_value object, string; | ||
status = napi_create_object(env, &object); | ||
if (status != napi_ok) { | ||
napi_throw_error(env, ...); | ||
return; | ||
} | ||
|
||
status = napi_crate_string_utf8(env, "bar", NAPI_AUTO_LENGTH, &string); | ||
if (status != napi_ok) { | ||
napi_throw_error(env, ...); | ||
return; | ||
} | ||
|
||
status = napi_set_named_property(env, object, "foo", string); | ||
if (status != napi_ok) { | ||
napi_throw_error(env, ...); | ||
return; | ||
} | ||
``` | ||
|
||
The end result is that the addon only uses the exported C APIs. As a result, | ||
it still gets the benefits of the ABI stability provided by the C API. | ||
Detailed API documentation for `node-addon-api` is available | ||
vsemozhetbyt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[here](https://github.com/nodejs/node-addon-api#api-documentation). | ||
|
||
|
||
When using `node-addon-api` instead of the C APIs, start with the API docs | ||
for `node-addon-api`. | ||
thefourtheye marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Implications of ABI Stability | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: Seeing a line starting with a dot, seems not correct.