@@ -8,20 +8,22 @@ _Addons_ are dynamically-linked shared objects written in C++. The
8
8
[ ` require() ` ] [ require ] function can load addons as ordinary Node.js modules.
9
9
Addons provide an interface between JavaScript and C/C++ libraries.
10
10
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
+ * Node-API
13
+ * ` nan ` ([ Native Abstractions for Node.js] [ ] )
14
+ * direct use of internal V8, libuv, and Node.js libraries
15
+
16
+ Unless there is a need fordirect access to functionality which is not exposed by Node-API, use Node-API.
14
17
Refer to [ C/C++ addons with Node-API] ( n-api.md ) for more information on
15
18
Node-API.
16
19
17
- When not using Node-API, implementing addons is complicated,
18
- involving knowledge of several components and APIs:
20
+ When not using Node-API, implementing addons becomes more complex, requiring knowledge of multiple components and APIs:
19
21
20
22
* [ 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
23
+ JavaScript implementation. It provides the mechanisms for creating objects,
24
+ calling functions, etc. The V8's API is documented mostly in the
23
25
` v8.h ` header file (` deps/v8/include/v8.h ` in the Node.js source
24
- tree), which is also available [ online] [ v8-docs ] .
26
+ tree), and is also available [ online] [ v8-docs ] .
25
27
26
28
* [ libuv] [ ] : The C library that implements the Node.js event loop, its worker
27
29
threads and all of the asynchronous behaviors of the platform. It also
@@ -35,10 +37,10 @@ involving knowledge of several components and APIs:
35
37
offloading work via libuv to non-blocking system operations, worker threads,
36
38
or a custom use of libuv threads.
37
39
38
- * Internal Node.js libraries. Node.js itself exports C++ APIs that addons can
40
+ * Internal Node.js libraries: Node.js itself exports C++ APIs that addons can
39
41
use, the most important of which is the ` node::ObjectWrap ` class.
40
42
41
- * Node.js includes other statically linked libraries including OpenSSL. These
43
+ * Other statically linked libraries ( including OpenSSL): These
42
44
other libraries are located in the ` deps/ ` directory in the Node.js source
43
45
tree. Only the libuv, OpenSSL, V8, and zlib symbols are purposefully
44
46
re-exported by Node.js and may be used to various extents by addons. See
@@ -148,8 +150,8 @@ invocation of `NODE_MODULE_INIT()`:
148
150
* `Local<Value> module`, and
149
151
* `Local<Context> context`
150
152
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
153
+ Building a context-aware addon requires careful management of global static data
154
+ to ensure stability and correctness . Since the addon may be loaded multiple
153
155
times, potentially even from different threads, any global static data stored
154
156
in the addon must be properly protected, and must not contain any persistent
155
157
references to JavaScript objects. The reason for this is that JavaScript
@@ -255,7 +257,7 @@ such as a main thread and a Worker thread, an add-on needs to either:
255
257
* Be declared as context-aware using `NODE_MODULE_INIT()` as described above
256
258
257
259
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
260
+ they may have allocated when such a thread exits . This can be achieved through
259
261
the usage of the `AddEnvironmentCleanupHook()` function:
260
262
261
263
```cpp
@@ -1273,7 +1275,7 @@ class MyObject : public node::ObjectWrap {
1273
1275
#endif
1274
1276
```
1275
1277
1276
- The implementation of ` myobject.cc ` is similar to before :
1278
+ The implementation of ` myobject.cc ` remains similar to the previous version :
1277
1279
1278
1280
``` cpp
1279
1281
// myobject.cc
0 commit comments