Skip to content

Commit 16eef64

Browse files
preveen-stackmarco-ippolito
authored andcommitted
doc: clarity to available addon options
bullet pointed addon optons; wording clarity; fixes typo PR-URL: #55715 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent d2421f3 commit 16eef64

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

doc/api/addons.md

+19-14
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,25 @@ _Addons_ are dynamically-linked shared objects written in C++. The
88
[`require()`][require] function can load addons as ordinary Node.js modules.
99
Addons provide an interface between JavaScript and C/C++ libraries.
1010

11-
There are three options for implementing addons: Node-API, nan, or direct
12-
use of internal V8, libuv, and Node.js libraries. Unless there is a need for
13-
direct access to functionality which is not exposed by Node-API, use Node-API.
11+
There are three options for implementing addons:
12+
13+
* Node-API
14+
* `nan` ([Native Abstractions for Node.js][])
15+
* direct use of internal V8, libuv, and Node.js libraries
16+
17+
Unless there is a need for direct access to functionality which is not\
18+
exposed by Node-API, use Node-API.
1419
Refer to [C/C++ addons with Node-API](n-api.md) for more information on
1520
Node-API.
1621

17-
When not using Node-API, implementing addons is complicated,
18-
involving knowledge of several components and APIs:
22+
When not using Node-API, implementing addons becomes more complex, requiring\
23+
knowledge of multiple components and APIs:
1924

2025
* [V8][]: the C++ library Node.js uses to provide the
21-
JavaScript implementation. V8 provides the mechanisms for creating objects,
22-
calling functions, etc. V8's API is documented mostly in the
26+
JavaScript implementation. It provides the mechanisms for creating objects,
27+
calling functions, etc. The V8's API is documented mostly in the
2328
`v8.h` header file (`deps/v8/include/v8.h` in the Node.js source
24-
tree), which is also available [online][v8-docs].
29+
tree), and is also available [online][v8-docs].
2530

2631
* [libuv][]: The C library that implements the Node.js event loop, its worker
2732
threads and all of the asynchronous behaviors of the platform. It also
@@ -35,10 +40,10 @@ involving knowledge of several components and APIs:
3540
offloading work via libuv to non-blocking system operations, worker threads,
3641
or a custom use of libuv threads.
3742

38-
* Internal Node.js libraries. Node.js itself exports C++ APIs that addons can
43+
* Internal Node.js libraries: Node.js itself exports C++ APIs that addons can
3944
use, the most important of which is the `node::ObjectWrap` class.
4045

41-
* Node.js includes other statically linked libraries including OpenSSL. These
46+
* Other statically linked libraries (including OpenSSL): These
4247
other libraries are located in the `deps/` directory in the Node.js source
4348
tree. Only the libuv, OpenSSL, V8, and zlib symbols are purposefully
4449
re-exported by Node.js and may be used to various extents by addons. See
@@ -148,8 +153,8 @@ invocation of `NODE_MODULE_INIT()`:
148153
* `Local<Value> module`, and
149154
* `Local<Context> context`
150155
151-
The choice to build a context-aware addon carries with it the responsibility of
152-
carefully managing global static data. Since the addon may be loaded multiple
156+
Building a context-aware addon requires careful management of global static data
157+
to ensure stability and correctness. Since the addon may be loaded multiple
153158
times, potentially even from different threads, any global static data stored
154159
in the addon must be properly protected, and must not contain any persistent
155160
references to JavaScript objects. The reason for this is that JavaScript
@@ -255,7 +260,7 @@ such as a main thread and a Worker thread, an add-on needs to either:
255260
* Be declared as context-aware using `NODE_MODULE_INIT()` as described above
256261
257262
In order to support [`Worker`][] threads, addons need to clean up any resources
258-
they may have allocated when such a thread exists. This can be achieved through
263+
they may have allocated when such a thread exits. This can be achieved through
259264
the usage of the `AddEnvironmentCleanupHook()` function:
260265
261266
```cpp
@@ -1273,7 +1278,7 @@ class MyObject : public node::ObjectWrap {
12731278
#endif
12741279
```
12751280

1276-
The implementation of `myobject.cc` is similar to before:
1281+
The implementation of `myobject.cc` remains similar to the previous version:
12771282

12781283
```cpp
12791284
// myobject.cc

0 commit comments

Comments
 (0)