@@ -8,20 +8,25 @@ _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
+
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.
14
19
Refer to [ C/C++ addons with Node-API] ( n-api.md ) for more information on
15
20
Node-API.
16
21
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:
19
24
20
25
* [ 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
23
28
` 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 ] .
25
30
26
31
* [ libuv] [ ] : The C library that implements the Node.js event loop, its worker
27
32
threads and all of the asynchronous behaviors of the platform. It also
@@ -35,10 +40,10 @@ involving knowledge of several components and APIs:
35
40
offloading work via libuv to non-blocking system operations, worker threads,
36
41
or a custom use of libuv threads.
37
42
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
39
44
use, the most important of which is the ` node::ObjectWrap ` class.
40
45
41
- * Node.js includes other statically linked libraries including OpenSSL. These
46
+ * Other statically linked libraries ( including OpenSSL): These
42
47
other libraries are located in the ` deps/ ` directory in the Node.js source
43
48
tree. Only the libuv, OpenSSL, V8, and zlib symbols are purposefully
44
49
re-exported by Node.js and may be used to various extents by addons. See
@@ -148,8 +153,8 @@ invocation of `NODE_MODULE_INIT()`:
148
153
* `Local<Value> module`, and
149
154
* `Local<Context> context`
150
155
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
153
158
times, potentially even from different threads, any global static data stored
154
159
in the addon must be properly protected, and must not contain any persistent
155
160
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:
255
260
* Be declared as context-aware using `NODE_MODULE_INIT()` as described above
256
261
257
262
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
259
264
the usage of the `AddEnvironmentCleanupHook()` function:
260
265
261
266
```cpp
@@ -1273,7 +1278,7 @@ class MyObject : public node::ObjectWrap {
1273
1278
#endif
1274
1279
```
1275
1280
1276
- The implementation of ` myobject.cc ` is similar to before :
1281
+ The implementation of ` myobject.cc ` remains similar to the previous version :
1277
1282
1278
1283
``` cpp
1279
1284
// myobject.cc
0 commit comments