diff --git a/addons/c_addons.md b/addons/c_addons.md index 04d34933..3ddf8d35 100644 --- a/addons/c_addons.md +++ b/addons/c_addons.md @@ -7,26 +7,25 @@ Node.js 插件是用 C++ 编写的动态链接共享对象,可以使用 [`requ 实现插件有三种选择:N-API、nan、或直接使用内部的 V8、libuv 和 Node.js 库。 除非你需要直接访问 N-API 未公开的函数,否则请使用 N-API。 -有关 N-API 的更多信息,参阅 [C/C++ 插件 N-API][_n-api] 章节。 +有关 N-API 的更多信息,参阅[具有 N-API 的 C/C++ 插件][_n-api]。 当不使用 N-API 时,实现插件很复杂,涉及多个组件和 API 的知识: - V8:Node.js 目前用于提供 JavaScript 实现的 C++ 库。 V8 提供了用于创建对象、调用函数等的机制。 - V8 的 API 文档主要在 `v8.h` 头文件中(Node.js 源代码中的 `deps/v8/include/v8.h`),也可以在查看 [V8 在线文档][v8-docs]。 + V8 的 API 文档主要在 `v8.h` 头文件中(Node.js 源代码树中的 `deps/v8/include/v8.h`),也可以在查看[在线文档][v8-docs]。 - - [libuv]:实现了 Node.js 的事件循环、工作线程、以及平台所有的的异步操作的 C 库。 + - [libuv]:实现了 Node.js 的事件循环、工作线程、以及平台所有的的异步行为的 C 库。 它也是一个跨平台的抽象库,使所有主流操作系统中可以像 POSIX 一样访问常用的系统任务,比如与文件系统、socket、定时器、以及系统事件的交互。 libuv 还提供了一个类似 POSIX 多线程的线程抽象,可被用于强化更复杂的需要超越标准事件循环的异步插件。 建议插件开发者多思考如何通过在 libuv 的非阻塞系统操作、工作线程、或自定义的 libuv 线程中降低工作负载来避免在 I/O 或其他时间密集型任务中阻塞事件循环。 - - 内置的 Node.js 库。Node.js 自身开放了一些插件可以使用的 C++ API。 - 其中最重要的是 `node::ObjectWrap` 类。 + - 内置的 Node.js 库。Node.js 自身公开了插件可以使用的 C++ API,其中最重要的是 `node::ObjectWrap` 类。 - - Node.js 包含一些其他的静态链接库,如 OpenSSL。 - 这些库位于 Node.js 源代码中的 `deps/` 目录。 - 只有 V8 和 OpenSSL 符号是被 Node.js 开放的,并且通过插件被用于不同的场景。 - 更多信息可查看[链接到 Node.js 自身的依赖][Linking to Node.js' own dependencies]。 + - Node.js 包含了其他的静态链接库,如 OpenSSL。 + 这些库位于 Node.js 源代码树中的 `deps/` 目录。 + 只有 libuv、OpenSSL、V8 和 zlib 符号是被 Node.js 有目的地重新公开,并且可以被插件在不同程度上使用。 + 更多信息可查看[链接到 Node.js 自有的依赖项][Linking to Node.js' own dependencies]。 -以下例子可从 [Node 插件示例][download]下载,作为学习插件开发的起点。 +以下所有示例均可供[下载][download],并可用作学习插件的起点。 diff --git a/addons/linking_to_node_js_own_dependencies.md b/addons/linking_to_node_js_own_dependencies.md index dbedcb2b..c1e6a1ee 100644 --- a/addons/linking_to_node_js_own_dependencies.md +++ b/addons/linking_to_node_js_own_dependencies.md @@ -1,13 +1,14 @@ -Node.js 使用了一些静态链接库,比如 V8 引擎、libuv 和 OpenSSL。 -所有的插件都需要链接到 V8,也可能链接到任何其他依赖。 -通常情况下,只要简单地包含相应的 `#include <...>` 声明(如 `#include `),则 `node-gyp` 会自动定位到相应的头文件。 -但是也有一些注意事项需要注意: +Node.js 使用了静态链接库,比如 V8、libuv 和 OpenSSL。 +所有的插件都需要链接到 V8,也可能链接到任何其他的依赖项。 +通常情况下,只要简单地引入相应的 `#include <...>` 声明(如 `#include `),则 `node-gyp` 将会自动地定位到相应的头文件。 +但是也有一些注意事项需要留意: -* 当 `node-gyp` 运行时,它会检测指定的 Node.js 发行版本,并下载完整的源代码包或只是头文件。 -如果下载了完整的源代码,则插件对全套的 Node.js 依赖有完全的访问权限。 -如果只下载了 Node.js 的文件头,则只有 Node.js 导出的符号可用。 +* 当 `node-gyp` 运行时,它将会检测指定的 Node.js 发行版本,并下载完整的源代码包或只是头文件。 +如果下载了完整的源代码,则插件将会具有对完整的 Node.js 依赖项的完全访问权限。 +如果只下载了 Node.js 的头文件,则只有 Node.js 公开的符号可用。 + +* 可以使用 `--nodedir` 标志指向本地的 Node.js 源代码镜像来运行 `node-gyp`。 +如果使用此选项,则插件将有权访问全部依赖项。 -* `node-gyp` 可使用指向一个本地 Node.js 源代码镜像的 `--nodedir` 标志来运行。 -如果使用该选项,则插件有全套依赖的访问权限。 diff --git a/addons/n_api.md b/addons/n_api.md index 8f38e90d..c2d6b5f6 100644 --- a/addons/n_api.md +++ b/addons/n_api.md @@ -46,5 +46,5 @@ NAPI_MODULE(NODE_GYP_MODULE_NAME, init) } // namespace demo ``` -可用的函数和使用文档请参阅 [C/C++ 插件 - N-API][_n-api]。 +可用的函数和使用文档请参阅[具有 N-API 的 C/C++ 插件][_n-api]。 diff --git a/buffer/buf_index.md b/buffer/buf_index.md index 9cc1436d..9475340d 100644 --- a/buffer/buf_index.md +++ b/buffer/buf_index.md @@ -5,10 +5,11 @@ name: [index] * `index` {integer} -索引操作符 `[index]` 可用于获取或设置 `buf` 中指定的 `index` 位置的字节。 -该值指向单个字节,所以有效的值的范围是 `0x00` 至 `0xFF`(十六进制),或 `0` 至 `255`(十进制)。 +索引操作符 `[index]` 可用于获取或设置 `buf` 中指定的 `index` 位置的八位字节。 +该值指向单个字节,所以有效的值的范围是 `0x00` 至 `0xFF`(十六进制)、或 `0` 至 `255`(十进制)。 -该操作符继承自 `Uint8Array`,所以对越界访问的处理与 `UInt8Array` 相同(也就是,取值时返回 `undefined`,赋值时不作为)。 +该操作符继承自 `Uint8Array`,所以对越界访问的行为与 `UInt8Array` 相同。 +也就是说,取值时返回 `undefined`,赋值时不作为。 ```js // 拷贝 ASCII 字符串到 `Buffer`,每次拷贝一个字节。 diff --git a/buffer/buffers_and_character_encodings.md b/buffer/buffers_and_character_encodings.md index 9be56159..dbfc93b6 100644 --- a/buffer/buffers_and_character_encodings.md +++ b/buffer/buffers_and_character_encodings.md @@ -26,21 +26,21 @@ console.log(Buffer.from('fhqwhgads', 'utf16le')); Node.js 当前支持的字符编码有: -* `'ascii'` - 仅适用于 7 位 ASCII 数据。此编码速度很快,如果设置则会剥离高位。 +* `'ascii'`: 仅适用于 7 位 ASCII 数据。此编码速度很快,如果设置则会剥离高位。 -* `'utf8'` - 多字节编码的 Unicode 字符。许多网页和其他文档格式都使用 UTF-8。 +* `'utf8'`: 多字节编码的 Unicode 字符。许多网页和其他文档格式都使用 UTF-8。 -* `'utf16le'` - 2 或 4 个字节,小端序编码的 Unicode 字符。支持代理对(U+10000 至 U+10FFFF)。 +* `'utf16le'`: 2 或 4 个字节,小端序编码的 Unicode 字符。支持代理对(U+10000 至 U+10FFFF)。 -* `'ucs2'` - `'utf16le'` 的别名。 +* `'ucs2'`: `'utf16le'` 的别名。 -* `'base64'` - Base64 编码。当从字符串创建 `Buffer` 时,此编码也会正确地接受 [RFC 4648 第 5 节][RFC 4648, Section 5]中指定的 “URL 和文件名安全字母”。 +* `'base64'`: Base64 编码。当从字符串创建 `Buffer` 时,此编码也会正确地接受 [RFC 4648 第 5 节][RFC 4648, Section 5]中指定的 “URL 和文件名安全字母”。 -* `'latin1'` - 一种将 `Buffer` 编码成单字节编码字符串的方法(由 [RFC 1345] 中的 IANA 定义,第 63 页,作为 Latin-1 的补充块和 C0/C1 控制码)。 +* `'latin1'`: 一种将 `Buffer` 编码成单字节编码字符串的方法(由 [RFC 1345] 中的 IANA 定义,第 63 页,作为 Latin-1 的补充块和 C0/C1 控制码)。 -* `'binary'` - `'latin1'` 的别名。 +* `'binary'`: `'latin1'` 的别名。 -* `'hex'` - 将每个字节编码成两个十六进制的字符。 +* `'hex'`: 将每个字节编码成两个十六进制的字符。 现代的 Web 浏览器遵循 [WHATWG 编码标准][WHATWG Encoding Standard],将 `'latin1'` 和 `'ISO-8859-1'` 别名为 `'win-1252'`。 这意味着当执行 `http.get()` 之类的操作时,如果返回的字符集是 WHATWG 规范中列出的字符集之一,则服务器可能实际返回 `'win-1252'` 编码的数据,而使用 `'latin1'` 编码可能错误地解码字符。 diff --git a/child_process/child_process_fork_modulepath_args_options.md b/child_process/child_process_fork_modulepath_args_options.md index 5c2cbc1a..522f45cf 100644 --- a/child_process/child_process_fork_modulepath_args_options.md +++ b/child_process/child_process_fork_modulepath_args_options.md @@ -29,7 +29,7 @@ changes: 返回的 [`ChildProcess`] 将会内置一个额外的通信通道,允许消息在父进程和子进程之间来回传递。 详见 [`subprocess.send()`]。 -重要的是要记住,衍生的 Node.js 子进程独立于父进程,但两者之间建立的 IPC 通信通道除外。 +记住,衍生的 Node.js 子进程独立于父进程,但两者之间建立的 IPC 通信通道除外。 每个进程都有自己的内存,带有自己的 V8 实例。 由于需要额外的资源分配,因此不建议衍生大量的 Node.js 子进程。 diff --git a/cli/.md b/cli/.md index be04ad9e..a2f89206 100644 --- a/cli/.md +++ b/cli/.md @@ -2,5 +2,6 @@ added: v8.0.0 --> -stdin 的别名,类似于在其他命令行工具中使用 `-`,表示将会从 stdin 读取脚本,且其余的选项会传给该脚本。 +stdin 的别名。 +类似于在其他命令行工具中使用 `-`,这意味着将会从 stdin 读取脚本,且其余的选项会传给该脚本。 diff --git a/cli/enable_source_maps.md b/cli/enable_source_maps.md index 3cba5eac..31b37e66 100644 --- a/cli/enable_source_maps.md +++ b/cli/enable_source_maps.md @@ -6,3 +6,6 @@ added: v12.12.0 Enable experimental Source Map V3 support for stack traces. +Currently, overriding `Error.prepareStackTrace` is ignored when the +`--enable-source-maps` flag is set. + diff --git a/cli/heap_prof_name.md b/cli/heap_prof_name.md index 793b1844..53bc9559 100644 --- a/cli/heap_prof_name.md +++ b/cli/heap_prof_name.md @@ -6,6 +6,3 @@ added: v12.4.0 Specify the file name of the heap profile generated by `--heap-prof`. -Generates a heap snapshot each time the process receives the specified signal. -`signal` must be a valid signal name. Disabled by default. - diff --git a/cli/heapsnapshot_signal_signal.md b/cli/heapsnapshot_signal_signal.md index af03a4cb..ef12b0bb 100644 --- a/cli/heapsnapshot_signal_signal.md +++ b/cli/heapsnapshot_signal_signal.md @@ -3,7 +3,8 @@ added: v12.0.0 --> Enables a signal handler that causes the Node.js process to write a heap dump -when the specified signal is received. +when the specified signal is received. `signal` must be a valid signal name. +Disabled by default. ```console $ node --heapsnapshot-signal=SIGUSR2 index.js & diff --git a/cli/source_map_cache.md b/cli/source_map_cache.md index 7488036e..b76a8a68 100644 --- a/cli/source_map_cache.md +++ b/cli/source_map_cache.md @@ -5,8 +5,9 @@ If found, Source Map data is appended to the top-level key `source-map-cache` on the JSON coverage object. `source-map-cache` is an object with keys representing the files source maps -were extracted from, and the values include the raw source-map URL -(in the key `url`) and the parsed Source Map V3 information (in the key `data`). +were extracted from, and values which include the raw source-map URL +(in the key `url`), the parsed Source Map V3 information (in the key `data`), +and the line lengths of the source file (in the key `lineLengths`). ```json { @@ -32,7 +33,13 @@ were extracted from, and the values include the raw source-map URL ], "mappings": "MAAMA,IACJC,YAAaC", "sourceRoot": "./" - } + }, + "lineLengths": [ + 13, + 62, + 38, + 27 + ] } } } diff --git a/cluster/cluster_schedulingpolicy.md b/cluster/cluster_schedulingpolicy.md index 8dbd3a70..569ddebf 100644 --- a/cluster/cluster_schedulingpolicy.md +++ b/cluster/cluster_schedulingpolicy.md @@ -4,7 +4,7 @@ added: v0.11.2 调度策略,包括循环计数的 `cluster.SCHED_RR`,以及由操作系统决定的 `cluster.SCHED_NONE`。 -这是一个全局设置,当第一个工作进程被衍生或者调用 `cluster.setupMaster()` 时,都将第一时间生效。 +这是一个全局设置,当第一个工作进程被衍生或者调用 [`.setupMaster()`] 时,都将第一时间生效。 除 Windows 外的所有操作系统中,`SCHED_RR` 都是默认设置。 只要 libuv 可以有效地分发 IOCP 句柄,而不会导致严重的性能冲击的话,Windows 系统也会更改为 `SCHED_RR`。 diff --git a/cluster/cluster_settings.md b/cluster/cluster_settings.md index 37beff16..fe2eb20c 100644 --- a/cluster/cluster_settings.md +++ b/cluster/cluster_settings.md @@ -27,7 +27,7 @@ changes: * `inspectPort` {number|Function} 设置工作进程的检查端口。这可以是一个数字、或不带参数并返回数字的函数。默认情况下,每个工作进程都有自己的端口,从主进程的 `process.debugPort` 开始递增。 * `windowsHide` {boolean} 隐藏衍生的进程的控制台窗口(通常在 Windows 系统上会创建)。**默认值:** `false`。 -调用 `.setupMaster()`(或 `.fork()`)之后,这个配置对象将会包含这些配置项,包括默认值。 +调用 [`.setupMaster()`](或 [`.fork()`])之后,这个配置对象将会包含这些配置项,包括默认值。 这个对象不打算被修改或手动设置。 diff --git a/cluster/cluster_setupmaster_settings.md b/cluster/cluster_setupmaster_settings.md index a0142ebd..cb67a88a 100644 --- a/cluster/cluster_setupmaster_settings.md +++ b/cluster/cluster_setupmaster_settings.md @@ -11,9 +11,9 @@ changes: `setupMaster` 用于修改默认的 'fork' 行为。 一旦调用,将会按照 `cluster.settings` 进行设置。 -所有的设置只对后来的 `.fork()` 调用有效,对之前的工作进程无影响。 +所有的设置只对后来的 [`.fork()`] 调用有效,对之前的工作进程无影响。 -唯一无法通过 `.setupMaster()` 设置的属性是传给 `.fork()` 的 `env` 属性。 +唯一无法通过 `.setupMaster()` 设置的属性是传给 [`.fork()`] 的 `env` 属性。 上述的默认值只在第一次调用时有效,当后续调用时,将采用 `cluster.setupMaster()` 调用时的当前值。 diff --git a/cluster/event_exit_1.md b/cluster/event_exit_1.md index 2cf42eb6..9a37083d 100644 --- a/cluster/event_exit_1.md +++ b/cluster/event_exit_1.md @@ -8,7 +8,7 @@ added: v0.7.9 当任何一个工作进程关闭的时候,cluster 模块都将会触发 `'exit'` 事件。 -这可以用于重启工作进程(通过再次调用 `.fork()`)。 +这可以用于重启工作进程(通过再次调用 [`.fork()`])。 ```js cluster.on('exit', (worker, code, signal) => { diff --git a/cluster/event_message_1.md b/cluster/event_message_1.md index 46110323..d02de34b 100644 --- a/cluster/event_message_1.md +++ b/cluster/event_message_1.md @@ -10,22 +10,7 @@ changes: * `message` {Object} * `handle` {undefined|Object} -当 cluster 主进程接收任意工作进程发送的消息时触发。 +当集群主进程从任何工作进程接收到消息时触发。 -参阅 [`child_process` event: `'message'`]。 - -在 Node.js v6.0 版本之前,此事件只接受 `message` 和 `handle` 两个参数,而没有 `worker` 对象。 - -如果要兼容旧版本并且不需要工作进程对象的情况下,可以通过判断参数数量来实现兼容。 - -```js -cluster.on('message', (worker, message, handle) => { - if (arguments.length === 2) { - handle = message; - message = worker; - worker = undefined; - } - // ... -}); -``` +参阅 [`child_process` 事件 `'message'`][`child_process` event: `'message'`]。 diff --git a/cluster/event_setup.md b/cluster/event_setup.md index 0ffe6c5a..80e7c5db 100644 --- a/cluster/event_setup.md +++ b/cluster/event_setup.md @@ -4,9 +4,9 @@ added: v0.7.1 * `settings` {Object} -每当 `.setupMaster()` 被调用时触发。 +每当 [`.setupMaster()`] 被调用时触发。 -`settings` 对象是 `setupMaster()` 被调用时的 `cluster.settings` 对象,并且只能查询,因为在一个时间点内 `.setupMaster()` 可以被调用多次。 +`settings` 对象是 [`.setupMaster()`] 被调用时的 `cluster.settings` 对象,并且只能查询,因为在一个时间点内 [`.setupMaster()`] 可以被调用多次。 如果精确度十分重要,则使用 `cluster.settings`。 diff --git a/cluster/worker_send_message_sendhandle_callback.md b/cluster/worker_send_message_sendhandle_options_callback.md similarity index 58% rename from cluster/worker_send_message_sendhandle_callback.md rename to cluster/worker_send_message_sendhandle_options_callback.md index 1d55a0d3..d21a6f9c 100644 --- a/cluster/worker_send_message_sendhandle_callback.md +++ b/cluster/worker_send_message_sendhandle_options_callback.md @@ -8,10 +8,12 @@ changes: * `message` {Object} * `sendHandle` {Handle} +* `options` {Object} `options` 参数(如果存在)是一个对象,用于参数化某些类型的句柄的发送。`options` 支持以下属性: + * `keepOpen` {boolean} 当传递 `net.Socket` 实例时可以使用的值。 当为 `true` 时,套接字在发送的过程中保持打开状态。**默认值:** `false`。 * `callback` {Function} * 返回: {boolean} -发送一个消息给工作进程或主进程,也可以附带发送一个句柄。 +发送消息给工作进程或主进程,可以选择带上句柄。 在主进程中,这会发送消息给特定的工作进程。 相当于 [`ChildProcess.send()`]。 @@ -19,7 +21,7 @@ changes: 在工作进程中,这会发送消息给主进程。 相当于 `process.send()`。 -这个例子里面,工作进程将主进程发送的消息响应回去: +此示例将会回响主进程的所有消息: ```js if (cluster.isMaster) { diff --git a/crypto/crypto_createcipheriv_algorithm_key_iv_options.md b/crypto/crypto_createcipheriv_algorithm_key_iv_options.md index e188a344..034931b5 100644 --- a/crypto/crypto_createcipheriv_algorithm_key_iv_options.md +++ b/crypto/crypto_createcipheriv_algorithm_key_iv_options.md @@ -43,5 +43,5 @@ changes: 初始化向量应该是不可预测的且唯一的,理想情况下,它们在密码上是随机的。 它们不必是私密的:IV 通常只是添加到未加密的密文消息中。 它们必须是不可预测的且唯一的,但不一定是私密的,这听起来似乎是矛盾的。 -重要的是要记住,攻击者必须无法提前预测给定的 IV 将会是什么。 +记住,攻击者必须无法提前预测给定的 IV 将会是什么。 diff --git a/crypto/crypto_createdecipheriv_algorithm_key_iv_options.md b/crypto/crypto_createdecipheriv_algorithm_key_iv_options.md index 929fe01a..696445ce 100644 --- a/crypto/crypto_createdecipheriv_algorithm_key_iv_options.md +++ b/crypto/crypto_createdecipheriv_algorithm_key_iv_options.md @@ -43,5 +43,5 @@ changes: 初始化向量应该是不可预测的且唯一的,理想情况下,它们在密码上是随机的。 它们不必是私密的:IV 通常只是添加到未加密的密文消息中。 它们必须是不可预测的且唯一的,但不一定是私密的,这听起来似乎是矛盾的。 -重要的是要记住,攻击者必须无法提前预测给定的 IV 将会是什么。 +记住,攻击者必须无法提前预测给定的 IV 将会是什么。 diff --git a/crypto/crypto_sign_algorithm_data_key.md b/crypto/crypto_sign_algorithm_data_key.md index 7c845413..9a109658 100644 --- a/crypto/crypto_sign_algorithm_data_key.md +++ b/crypto/crypto_sign_algorithm_data_key.md @@ -15,13 +15,13 @@ If `key` is not a [`KeyObject`][], this function behaves as if `key` had been passed to [`crypto.createPrivateKey()`][]. If it is an object, the following additional properties can be passed: -* `padding`: {integer} - Optional padding value for RSA, one of the following: +* `padding` {integer} Optional padding value for RSA, one of the following: * `crypto.constants.RSA_PKCS1_PADDING` (default) * `crypto.constants.RSA_PKCS1_PSS_PADDING` `RSA_PKCS1_PSS_PADDING` will use MGF1 with the same hash function used to sign the message as specified in section 3.1 of [RFC 4055][]. -* `saltLength`: {integer} - salt length for when padding is +* `saltLength` {integer} Salt length for when padding is `RSA_PKCS1_PSS_PADDING`. The special value `crypto.constants.RSA_PSS_SALTLEN_DIGEST` sets the salt length to the digest size, `crypto.constants.RSA_PSS_SALTLEN_MAX_SIGN` (default) sets it to the diff --git a/crypto/crypto_verify_algorithm_data_key_signature.md b/crypto/crypto_verify_algorithm_data_key_signature.md index 90215fce..b2c05eca 100644 --- a/crypto/crypto_verify_algorithm_data_key_signature.md +++ b/crypto/crypto_verify_algorithm_data_key_signature.md @@ -16,13 +16,13 @@ If `key` is not a [`KeyObject`][], this function behaves as if `key` had been passed to [`crypto.createPublicKey()`][]. If it is an object, the following additional properties can be passed: -* `padding`: {integer} - Optional padding value for RSA, one of the following: +* `padding` {integer} Optional padding value for RSA, one of the following: * `crypto.constants.RSA_PKCS1_PADDING` (default) * `crypto.constants.RSA_PKCS1_PSS_PADDING` `RSA_PKCS1_PSS_PADDING` will use MGF1 with the same hash function used to sign the message as specified in section 3.1 of [RFC 4055][]. -* `saltLength`: {integer} - salt length for when padding is +* `saltLength` {integer} Salt length for when padding is `RSA_PKCS1_PSS_PADDING`. The special value `crypto.constants.RSA_PSS_SALTLEN_DIGEST` sets the salt length to the digest size, `crypto.constants.RSA_PSS_SALTLEN_MAX_SIGN` (default) sets it to the diff --git a/crypto/openssl_engine_constants.md b/crypto/openssl_engine_constants.md index a15c5e7b..86e26fc8 100644 --- a/crypto/openssl_engine_constants.md +++ b/crypto/openssl_engine_constants.md @@ -1,4 +1,3 @@ - diff --git a/crypto/openssl_options.md b/crypto/openssl_options.md index 4b600dc7..6a31222a 100644 --- a/crypto/openssl_options.md +++ b/crypto/openssl_options.md @@ -1,4 +1,4 @@ - +
diff --git a/crypto/sign_sign_privatekey_outputencoding.md b/crypto/sign_sign_privatekey_outputencoding.md index c8d0873c..2bb44e24 100644 --- a/crypto/sign_sign_privatekey_outputencoding.md +++ b/crypto/sign_sign_privatekey_outputencoding.md @@ -25,7 +25,7 @@ If `privateKey` is not a [`KeyObject`][], this function behaves as if `privateKey` had been passed to [`crypto.createPrivateKey()`][]. If it is an object, the following additional properties can be passed: -* `padding`: {integer} - Optional padding value for RSA, one of the following: +* `padding` {integer} Optional padding value for RSA, one of the following: * `crypto.constants.RSA_PKCS1_PADDING` (default) * `crypto.constants.RSA_PKCS1_PSS_PADDING` @@ -33,7 +33,7 @@ object, the following additional properties can be passed: used to sign the message as specified in section 3.1 of [RFC 4055][], unless an MGF1 hash function has been specified as part of the key in compliance with section 3.3 of [RFC 4055][]. -* `saltLength`: {integer} - salt length for when padding is +* `saltLength` {integer} Salt length for when padding is `RSA_PKCS1_PSS_PADDING`. The special value `crypto.constants.RSA_PSS_SALTLEN_DIGEST` sets the salt length to the digest size, `crypto.constants.RSA_PSS_SALTLEN_MAX_SIGN` (default) sets it to the diff --git a/crypto/verify_verify_object_signature_signatureencoding.md b/crypto/verify_verify_object_signature_signatureencoding.md index c2868c75..1ca1f659 100644 --- a/crypto/verify_verify_object_signature_signatureencoding.md +++ b/crypto/verify_verify_object_signature_signatureencoding.md @@ -26,7 +26,7 @@ If `object` is not a [`KeyObject`][], this function behaves as if `object` had been passed to [`crypto.createPublicKey()`][]. If it is an object, the following additional properties can be passed: -* `padding`: {integer} - Optional padding value for RSA, one of the following: +* `padding` {integer} Optional padding value for RSA, one of the following: * `crypto.constants.RSA_PKCS1_PADDING` (default) * `crypto.constants.RSA_PKCS1_PSS_PADDING` @@ -34,7 +34,7 @@ object, the following additional properties can be passed: used to verify the message as specified in section 3.1 of [RFC 4055][], unless an MGF1 hash function has been specified as part of the key in compliance with section 3.3 of [RFC 4055][]. -* `saltLength`: {integer} - salt length for when padding is +* `saltLength` {integer} Salt length for when padding is `RSA_PKCS1_PSS_PADDING`. The special value `crypto.constants.RSA_PSS_SALTLEN_DIGEST` sets the salt length to the digest size, `crypto.constants.RSA_PSS_SALTLEN_AUTO` (default) causes it to be diff --git a/deprecations/dep0005_buffer_constructor.md b/deprecations/dep0005_buffer_constructor.md index 5a72a104..745928e8 100644 --- a/deprecations/dep0005_buffer_constructor.md +++ b/deprecations/dep0005_buffer_constructor.md @@ -19,17 +19,17 @@ API usability issues that can lead to accidental security issues. As an alternative, use one of the following methods of constructing `Buffer` objects: -* [`Buffer.alloc(size[, fill[, encoding]])`][alloc] - Create a `Buffer` with +* [`Buffer.alloc(size[, fill[, encoding]])`][alloc]: Create a `Buffer` with *initialized* memory. -* [`Buffer.allocUnsafe(size)`][alloc_unsafe_size] - Create a `Buffer` with +* [`Buffer.allocUnsafe(size)`][alloc_unsafe_size]: Create a `Buffer` with *uninitialized* memory. -* [`Buffer.allocUnsafeSlow(size)`][] - Create a `Buffer` with *uninitialized* +* [`Buffer.allocUnsafeSlow(size)`][]: Create a `Buffer` with *uninitialized* memory. -* [`Buffer.from(array)`][] - Create a `Buffer` with a copy of `array` +* [`Buffer.from(array)`][]: Create a `Buffer` with a copy of `array` * [`Buffer.from(arrayBuffer[, byteOffset[, length]])`][from_arraybuffer] - Create a `Buffer` that wraps the given `arrayBuffer`. -* [`Buffer.from(buffer)`][] - Create a `Buffer` that copies `buffer`. -* [`Buffer.from(string[, encoding])`][from_string_encoding] - Create a `Buffer` +* [`Buffer.from(buffer)`][]: Create a `Buffer` that copies `buffer`. +* [`Buffer.from(string[, encoding])`][from_string_encoding]: Create a `Buffer` that copies `string`. Without `--pending-deprecation`, runtime warnings occur only for code not in diff --git a/dgram/dgram_createsocket_options_callback.md b/dgram/dgram_createsocket_options_callback.md index d0f04d14..dae27ee2 100644 --- a/dgram/dgram_createsocket_options_callback.md +++ b/dgram/dgram_createsocket_options_callback.md @@ -17,8 +17,8 @@ changes: * `type` {string} 套接字族. 必须是 `'udp4'` 或 `'udp6'`。必需填。 * `reuseAddr` {boolean} 若设置为 `true`,则 [`socket.bind()`] 会重用地址,即使另一个进程已经在其上面绑定了一个套接字。**默认值:** `false`。 * `ipv6Only` {boolean} 将 `ipv6Only` 设置为 `true` 将会禁用双栈支持,即绑定到地址 `::` 不会使 `0.0.0.0` 绑定。**默认值:** `false`。 - * `recvBufferSize` {number} - 设置 `SO_RCVBUF` 套接字值。 - * `sendBufferSize` {number} - 设置 `SO_SNDBUF` 套接字值。 + * `recvBufferSize` {number} 设置 `SO_RCVBUF` 套接字值。 + * `sendBufferSize` {number} 设置 `SO_SNDBUF` 套接字值。 * `lookup` {Function} 自定义的查询函数。**默认值:** [`dns.lookup()`]。 * `callback` {Function} 为 `'message'` 事件绑定一个监听器。可选。 * 返回: {dgram.Socket} diff --git a/dgram/dgram_createsocket_type_callback.md b/dgram/dgram_createsocket_type_callback.md index 0b2b002b..2f2bb674 100644 --- a/dgram/dgram_createsocket_type_callback.md +++ b/dgram/dgram_createsocket_type_callback.md @@ -2,8 +2,8 @@ added: v0.1.99 --> -* `type` {string} - `'udp4'` 或 `'udp6'`。 -* `callback` {Function} - 为 `'message'` 事件添加一个监听器。 +* `type` {string} `'udp4'` 或 `'udp6'`。 +* `callback` {Function} 为 `'message'` 事件添加一个监听器。 * 返回: {dgram.Socket} 创建一个特定 `type` 的 `dgram.Socket` 对象。 diff --git a/dgram/socket_send_msg_offset_length_port_address_callback.md b/dgram/socket_send_msg_offset_length_port_address_callback.md index 1af20e08..c96c6562 100644 --- a/dgram/socket_send_msg_offset_length_port_address_callback.md +++ b/dgram/socket_send_msg_offset_length_port_address_callback.md @@ -78,7 +78,7 @@ client.send([buf1, buf2], 41234, (err) => { ``` 发送多个 buffer 的速度取决于应用和操作系统。 -逐案运行基准来确定最佳策略是很重要的。 +逐案运行基准来确定最佳策略。 但是一般来说,发送多个 buffer 速度更快。 示例,使用已连接的 socket 发送 UDP 包到 `localhost` 上的某个端口: diff --git a/dgram/socket_setmulticastttl_ttl.md b/dgram/socket_setmulticastttl_ttl.md index 8048308f..ccc23f57 100644 --- a/dgram/socket_setmulticastttl_ttl.md +++ b/dgram/socket_setmulticastttl_ttl.md @@ -9,6 +9,6 @@ added: v0.3.8 这里特指一个 IP 数据包传输时允许的最大跳步数,尤其是对多播传输。 当 IP 数据包每向前经过一个路由或网关时,TTL 值减 1,若经过某个路由时,TTL 值被减至 0,便不再继续向前传输。 -传给 `socket.setMulticastTTL()` 的参数是一个范围为 0 至 255 的跳步数。 -大多数系统的默认值是 `1`,但是可以变化。 +`ttl` 参数可以是 `0` 到 `255` 之间。 +在大多数系统上,默认值是 `1`。 diff --git a/dgram/socket_setttl_ttl.md b/dgram/socket_setttl_ttl.md index 134613e7..380a9577 100644 --- a/dgram/socket_setttl_ttl.md +++ b/dgram/socket_setttl_ttl.md @@ -9,5 +9,7 @@ added: v0.1.101 当 IP 数据包每向前经过一个路由或网关时,TTL 值减 1,若经过某个路由时,TTL 值被减至 0,便不再继续向前传输。 比较有代表性的是,为了进行网络情况嗅探或者多播而修改 TTL 值。 -传给 `socket.setTTL()` 的参数是一个范围为 1 至 255 的跳步数。 -大多数系统的默认值是 64,但是可以变化。 + +`ttl` 参数可以是 `0` 到 `255` 之间。 +在大多数系统上,默认值是 `64`。 + diff --git a/esm/package_exports.md b/esm/package_exports.md index c53804a0..4f221595 100644 --- a/esm/package_exports.md +++ b/esm/package_exports.md @@ -23,7 +23,7 @@ throw when an attempt is made to import them: ```js import submodule from 'es-module-package/private-module.js'; -// Throws - Module not found +// Throws ERR_MODULE_NOT_FOUND ``` > Note: this is not a strong encapsulation as any private modules can still be diff --git a/events/asynchronous_vs_synchronous.md b/events/asynchronous_vs_synchronous.md index a4f99764..e5f4350b 100644 --- a/events/asynchronous_vs_synchronous.md +++ b/events/asynchronous_vs_synchronous.md @@ -1,13 +1,13 @@ -`EventEmitter` 会按照监听器注册的顺序同步地调用所有监听器。 -所以必须确保事件的排序正确,且避免竞态条件。 -可以使用 `setImmediate()` 或 `process.nextTick()` 切换到异步模式: +`EventEmitter` 以注册的顺序同步地调用所有监听器。 +这样可以确保事件的正确排序,并有助于避免竞态条件和逻辑错误。 +当适当时,监听器函数可以使用 `setImmediate()` 和 `process.nextTick()` 方法切换到异步的操作模式: ```js const myEmitter = new MyEmitter(); myEmitter.on('event', (a, b) => { setImmediate(() => { - console.log('异步进行'); + console.log('异步地发生'); }); }); myEmitter.emit('event', 'a', 'b'); diff --git a/fs/dir_read.md b/fs/dir_read.md index b8d69c57..134f06bf 100644 --- a/fs/dir_read.md +++ b/fs/dir_read.md @@ -9,4 +9,5 @@ added: v12.12.0 读取完成之后,将会返回一个 `Promise`,它被解决时将会返回 [`fs.Dirent`] 或 `null`(如果没有更多的目录项要读取)。 此函数返回的目录项不遵循操作系统的底层目录机制所提供的特定顺序。 +遍历目录时添加或删除的目录项可能会或可能不会包含在遍历的结果中。 diff --git a/fs/dir_read_callback.md b/fs/dir_read_callback.md index f7ebcb17..0485f7fd 100644 --- a/fs/dir_read_callback.md +++ b/fs/dir_read_callback.md @@ -11,4 +11,5 @@ added: v12.12.0 读取完成之后,将会调用 `callback` 并传入 [`fs.Dirent`] 或 `null`(如果没有更多的目录项要读取)。 此函数返回的目录项不遵循操作系统的底层目录机制所提供的特定顺序。 +遍历目录时添加或删除的目录项可能会或可能不会包含在遍历的结果中。 diff --git a/fs/dir_readsync.md b/fs/dir_readsync.md index c3bf5ddf..b973a273 100644 --- a/fs/dir_readsync.md +++ b/fs/dir_readsync.md @@ -9,4 +9,5 @@ added: v12.12.0 如果没有更多的目录项要读取,则将会返回 `null`。 此函数返回的目录项不遵循操作系统的底层目录机制所提供的特定顺序。 +遍历目录时添加或删除的目录项可能会或可能不会包含在遍历的结果中。 diff --git a/fs/dir_symbol_asynciterator.md b/fs/dir_symbol_asynciterator.md index 643e0386..f89eef9a 100644 --- a/fs/dir_symbol_asynciterator.md +++ b/fs/dir_symbol_asynciterator.md @@ -12,4 +12,5 @@ added: v12.12.0 有关示例,请参阅 [`fs.Dir`]。 该迭代器返回的目录项不遵循操作系统的底层目录机制所提供的特定顺序。 +遍历目录时添加或删除的目录项可能会或可能不会包含在遍历的结果中。 diff --git a/fs/fs_watchfile_filename_options_listener.md b/fs/fs_watchfile_filename_options_listener.md index e28a5a09..4043e4fa 100644 --- a/fs/fs_watchfile_filename_options_listener.md +++ b/fs/fs_watchfile_filename_options_listener.md @@ -47,5 +47,5 @@ fs.watchFile('message.text', (curr, prev) => { 这种情况发生在: - 文件被删除,然后又恢复。 -- 文件被重命名两次,且第二次重命名回其原来的名称。 +- 文件被重命名,然后再第二次重命名回其原来的名称。 diff --git a/http2/event_aborted.md b/http2/event_aborted.md index 0dace590..3f8d9263 100644 --- a/http2/event_aborted.md +++ b/http2/event_aborted.md @@ -4,6 +4,7 @@ added: v8.4.0 The `'aborted'` event is emitted whenever a `Http2Stream` instance is abnormally aborted in mid-communication. +Its listener does not expect any arguments. The `'aborted'` event will only be emitted if the `Http2Stream` writable side has not been ended. diff --git a/http2/event_timeout.md b/http2/event_timeout.md index 8519ccee..0b813742 100644 --- a/http2/event_timeout.md +++ b/http2/event_timeout.md @@ -5,6 +5,7 @@ added: v8.4.0 After the `http2session.setTimeout()` method is used to set the timeout period for this `Http2Session`, the `'timeout'` event is emitted if there is no activity on the `Http2Session` after the configured number of milliseconds. +Its listener does not expect any arguments. ```js session.setTimeout(2000); diff --git a/http2/http2_connect_authority_options_listener.md b/http2/http2_connect_authority_options_listener.md index 056f5f78..62af8647 100644 --- a/http2/http2_connect_authority_options_listener.md +++ b/http2/http2_connect_authority_options_listener.md @@ -38,18 +38,18 @@ changes: serialized, compressed block of headers. Attempts to send headers that exceed this limit will result in a `'frameError'` event being emitted and the stream being closed and destroyed. - * `paddingStrategy` {number} Identifies the strategy used for determining the - amount of padding to use for `HEADERS` and `DATA` frames. **Default:** + * `paddingStrategy` {number} Strategy used for determining the amount of + padding to use for `HEADERS` and `DATA` frames. **Default:** `http2.constants.PADDING_STRATEGY_NONE`. Value may be one of: - * `http2.constants.PADDING_STRATEGY_NONE` - Specifies that no padding is + * `http2.constants.PADDING_STRATEGY_NONE`: Specifies that no padding is to be applied. - * `http2.constants.PADDING_STRATEGY_MAX` - Specifies that the maximum + * `http2.constants.PADDING_STRATEGY_MAX`: Specifies that the maximum amount of padding, as determined by the internal implementation, is to be applied. - * `http2.constants.PADDING_STRATEGY_CALLBACK` - Specifies that the user + * `http2.constants.PADDING_STRATEGY_CALLBACK`: Specifies that the user provided `options.selectPadding()` callback is to be used to determine the amount of padding. - * `http2.constants.PADDING_STRATEGY_ALIGNED` - Will *attempt* to apply + * `http2.constants.PADDING_STRATEGY_ALIGNED`: Will *attempt* to apply enough padding to ensure that the total frame length, including the 9-byte header, is a multiple of 8. For each frame, however, there is a maximum allowed number of padding bytes that is determined by current diff --git a/http2/http2_createsecureserver_options_onrequesthandler.md b/http2/http2_createsecureserver_options_onrequesthandler.md index 9cd01916..f6cafb45 100644 --- a/http2/http2_createsecureserver_options_onrequesthandler.md +++ b/http2/http2_createsecureserver_options_onrequesthandler.md @@ -39,18 +39,18 @@ changes: serialized, compressed block of headers. Attempts to send headers that exceed this limit will result in a `'frameError'` event being emitted and the stream being closed and destroyed. - * `paddingStrategy` {number} Identifies the strategy used for determining the - amount of padding to use for `HEADERS` and `DATA` frames. **Default:** + * `paddingStrategy` {number} Strategy used for determining the amount of + padding to use for `HEADERS` and `DATA` frames. **Default:** `http2.constants.PADDING_STRATEGY_NONE`. Value may be one of: - * `http2.constants.PADDING_STRATEGY_NONE` - Specifies that no padding is + * `http2.constants.PADDING_STRATEGY_NONE`: Specifies that no padding is to be applied. - * `http2.constants.PADDING_STRATEGY_MAX` - Specifies that the maximum + * `http2.constants.PADDING_STRATEGY_MAX`: Specifies that the maximum amount of padding, as determined by the internal implementation, is to be applied. - * `http2.constants.PADDING_STRATEGY_CALLBACK` - Specifies that the user + * `http2.constants.PADDING_STRATEGY_CALLBACK`: Specifies that the user provided `options.selectPadding()` callback is to be used to determine the amount of padding. - * `http2.constants.PADDING_STRATEGY_ALIGNED` - Will *attempt* to apply + * `http2.constants.PADDING_STRATEGY_ALIGNED`: Will *attempt* to apply enough padding to ensure that the total frame length, including the 9-byte header, is a multiple of 8. For each frame, however, there is a maximum allowed number of padding bytes that is determined by current diff --git a/http2/http2_createserver_options_onrequesthandler.md b/http2/http2_createserver_options_onrequesthandler.md index d04af0d8..921dd37f 100644 --- a/http2/http2_createserver_options_onrequesthandler.md +++ b/http2/http2_createserver_options_onrequesthandler.md @@ -39,18 +39,18 @@ changes: serialized, compressed block of headers. Attempts to send headers that exceed this limit will result in a `'frameError'` event being emitted and the stream being closed and destroyed. - * `paddingStrategy` {number} Identifies the strategy used for determining the - amount of padding to use for `HEADERS` and `DATA` frames. **Default:** + * `paddingStrategy` {number} The strategy used for determining the amount of + padding to use for `HEADERS` and `DATA` frames. **Default:** `http2.constants.PADDING_STRATEGY_NONE`. Value may be one of: - * `http2.constants.PADDING_STRATEGY_NONE` - Specifies that no padding is + * `http2.constants.PADDING_STRATEGY_NONE`: Specifies that no padding is to be applied. - * `http2.constants.PADDING_STRATEGY_MAX` - Specifies that the maximum + * `http2.constants.PADDING_STRATEGY_MAX`: Specifies that the maximum amount of padding, as determined by the internal implementation, is to be applied. - * `http2.constants.PADDING_STRATEGY_CALLBACK` - Specifies that the user + * `http2.constants.PADDING_STRATEGY_CALLBACK`: Specifies that the user provided `options.selectPadding()` callback is to be used to determine the amount of padding. - * `http2.constants.PADDING_STRATEGY_ALIGNED` - Will *attempt* to apply + * `http2.constants.PADDING_STRATEGY_ALIGNED`: Will *attempt* to apply enough padding to ensure that the total frame length, including the 9-byte header, is a multiple of 8. For each frame, however, there is a maximum allowed number of padding bytes that is determined by current diff --git a/inspector/session_post_method_params_callback.md b/inspector/session_post_method_params_callback.md index b0fa102d..7f1f7dd1 100644 --- a/inspector/session_post_method_params_callback.md +++ b/inspector/session_post_method_params_callback.md @@ -8,7 +8,7 @@ added: v8.0.0 Posts a message to the inspector back-end. `callback` will be notified when a response is received. `callback` is a function that accepts two optional -arguments - error and message-specific result. +arguments: error and message-specific result. ```js session.post('Runtime.evaluate', { expression: '2 + 2' }, diff --git a/modules/all_together.md b/modules/all_together.md index eea75945..dda9c430 100644 --- a/modules/all_together.md +++ b/modules/all_together.md @@ -15,6 +15,7 @@ require(X) from module at path Y 3. If X begins with './' or '/' or '../' a. LOAD_AS_FILE(Y + X) b. LOAD_AS_DIRECTORY(Y + X) + c. THROW "not found" 4. LOAD_NODE_MODULES(X, dirname(Y)) 5. THROW "not found" diff --git a/n-api/asynchronous_thread_safe_function_calls.md b/n-api/asynchronous_thread_safe_function_calls.md index ee980a01..5b44bff4 100644 --- a/n-api/asynchronous_thread_safe_function_calls.md +++ b/n-api/asynchronous_thread_safe_function_calls.md @@ -22,9 +22,9 @@ Upon creation of a `napi_threadsafe_function` a `napi_finalize` callback can be provided. This callback will be invoked on the main thread when the thread-safe function is about to be destroyed. It receives the context and the finalize data given during construction, and provides an opportunity for cleaning up after the -threads e.g. by calling `uv_thread_join()`. **It is important that, aside from -the main loop thread, there be no threads left using the thread-safe function -after the finalize callback completes.** +threads e.g. by calling `uv_thread_join()`. **Aside from the main loop thread, +no threads should be using the thread-safe function after the finalize callback +completes.** The `context` given during the call to `napi_create_threadsafe_function()` can be retrieved from any thread with a call to @@ -69,13 +69,13 @@ existing thread will stop making use of the thread-safe function. the object has called `napi_release_threadsafe_function()` or has received a return status of `napi_closing` in response to a call to `napi_call_threadsafe_function`. The queue is emptied before the -`napi_threadsafe_function` is destroyed. It is important that -`napi_release_threadsafe_function()` be the last API call made in conjunction -with a given `napi_threadsafe_function`, because after the call completes, there -is no guarantee that the `napi_threadsafe_function` is still allocated. For the -same reason it is also important that no more use be made of a thread-safe -function after receiving a return value of `napi_closing` in response to a call -to `napi_call_threadsafe_function`. Data associated with the +`napi_threadsafe_function` is destroyed. `napi_release_threadsafe_function()` +should be the last API call made in conjunction with a given +`napi_threadsafe_function`, because after the call completes, there is no +guarantee that the `napi_threadsafe_function` is still allocated. For the same +reason, do not make use of a thread-safe function +after receiving a return value of `napi_closing` in response to a call to +`napi_call_threadsafe_function`. Data associated with the `napi_threadsafe_function` can be freed in its `napi_finalize` callback which was passed to `napi_create_threadsafe_function()`. diff --git a/n-api/build_tools.md b/n-api/build_tools.md new file mode 100644 index 00000000..c33b1ef8 --- /dev/null +++ b/n-api/build_tools.md @@ -0,0 +1,5 @@ + +Both the tools listed here require that *users* of the native +addon have a C/C++ toolchain installed in order to successfully install +the native addon. + diff --git a/n-api/building.md b/n-api/building.md new file mode 100644 index 00000000..04852468 --- /dev/null +++ b/n-api/building.md @@ -0,0 +1,32 @@ + +Unlike modules written in JavaScript, developing and deploying Node.js +native addons using N-API requires an additional set of tools. Besides the +basic tools required to develop for Node.js, the native addon developer +requires a toolchain that can compile C and C++ code into a binary. In +addition, depending upon how the native addon is deployed, the *user* of +the native addon will also need to have a C/C++ toolchain installed. + +For Linux developers, the necessary C/C++ toolchain packages are readily +available. [GCC][] is widely used in the Node.js community to build and +test across a variety of plarforms. For many developers, the [LLVM][] +compiler infrastructure is also a good choice. + +For Mac developers, [Xcode][] offers all the required compiler tools. +However, it is not necessary to install the entire Xcode IDE. The following +command installs the necessary toolchain: + +```bash +xcode-select --install +``` + +For Windows developers, [Visual Studio][] offers all the required compiler +tools. However, it is not necessary to install the entire Visual Studio +IDE. The following command installs the necessary toolchain: + +```bash +npm install --global --production windows-build-tools +``` + +The sections below describe the additional tools available for developing +and deploying Node.js native addons. + diff --git a/n-api/cmake_js.md b/n-api/cmake_js.md new file mode 100644 index 00000000..e32666d5 --- /dev/null +++ b/n-api/cmake_js.md @@ -0,0 +1,6 @@ + +[CMake.js][] is an alternative build system based on [CMake][]. + +CMake.js is a good choice for projects that already use CMake or for +developers affected by limitations in node-gyp. + diff --git a/n-api/exceptions.md b/n-api/exceptions.md index da3986ee..47342cb7 100644 --- a/n-api/exceptions.md +++ b/n-api/exceptions.md @@ -23,11 +23,11 @@ When an exception is pending one of two approaches can be employed. The first approach is to do any appropriate cleanup and then return so that execution will return to JavaScript. As part of the transition back to -JavaScript the exception will be thrown at the point in the JavaScript +JavaScript, the exception will be thrown at the point in the JavaScript code where the native method was invoked. The behavior of most N-API calls is unspecified while an exception is pending, and many will simply return -`napi_pending_exception`, so it is important to do as little as possible -and then return to JavaScript where the exception can be handled. +`napi_pending_exception`, so do as little as possible and then return to +JavaScript where the exception can be handled. The second approach is to try to handle the exception. There will be cases where the native code can catch the exception, take the appropriate action, diff --git a/n-api/n_api.md b/n-api/n_api.md index c61c9a01..da584e1e 100644 --- a/n-api/n_api.md +++ b/n-api/n_api.md @@ -13,11 +13,10 @@ changes in the underlying JavaScript engine and allow modules compiled for one major version to run on later major versions of Node.js without recompilation. The [ABI Stability][] guide provides a more in-depth explanation. -Addons are built/packaged with the same approach/tools -outlined in the section titled [C++ Addons](addons.html). -The only difference is the set of APIs that are used by the native code. -Instead of using the V8 or [Native Abstractions for Node.js][] APIs, -the functions available in the N-API are used. +Addons are built/packaged with the same approach/tools outlined in the section +titled [C++ Addons][]. The only difference is the set of APIs that are used by +the native code. Instead of using the V8 or [Native Abstractions for Node.js][] +APIs, the functions available in the N-API are used. APIs exposed by N-API are generally used to create and manipulate JavaScript values. Concepts and operations generally map to ideas specified @@ -75,7 +74,6 @@ if (status != napi_ok) { 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. -When using `node-addon-api` instead of the C APIs, start with the API -[docs](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`. diff --git a/n-api/napi_adjust_external_memory.md b/n-api/napi_adjust_external_memory.md index 5b8cd4e0..7d59a846 100644 --- a/n-api/napi_adjust_external_memory.md +++ b/n-api/napi_adjust_external_memory.md @@ -22,5 +22,3 @@ that points to its own memory allocated by a native module). Registering externally allocated memory will trigger global garbage collections more often than it would otherwise. - - diff --git a/n-api/napi_create_array_with_length.md b/n-api/napi_create_array_with_length.md index 0c1e84b0..6d8bbe8f 100644 --- a/n-api/napi_create_array_with_length.md +++ b/n-api/napi_create_array_with_length.md @@ -18,9 +18,8 @@ Returns `napi_ok` if the API succeeded. This API returns an N-API value corresponding to a JavaScript `Array` type. The `Array`'s length property is set to the passed-in length parameter. However, the underlying buffer is not guaranteed to be pre-allocated by the VM -when the array is created - that behavior is left to the underlying VM -implementation. -If the buffer must be a contiguous block of memory that can be +when the array is created. That behavior is left to the underlying VM +implementation. If the buffer must be a contiguous block of memory that can be directly read and/or written via C, consider using [`napi_create_external_arraybuffer`][]. diff --git a/n-api/napi_get_typedarray_info.md b/n-api/napi_get_typedarray_info.md index 8d7de24e..05fdae05 100644 --- a/n-api/napi_get_typedarray_info.md +++ b/n-api/napi_get_typedarray_info.md @@ -15,18 +15,18 @@ napi_status napi_get_typedarray_info(napi_env env, * `[in] env`: The environment that the API is invoked under. * `[in] typedarray`: `napi_value` representing the `TypedArray` whose -properties to query. + properties to query. * `[out] type`: Scalar datatype of the elements within the `TypedArray`. * `[out] length`: The number of elements in the `TypedArray`. * `[out] data`: The data buffer underlying the `TypedArray` adjusted by -the `byte_offset` value so that it points to the first element in the -`TypedArray`. + the `byte_offset` value so that it points to the first element in the + `TypedArray`. * `[out] arraybuffer`: The `ArrayBuffer` underlying the `TypedArray`. * `[out] byte_offset`: The byte offset within the underlying native array -at which the first element of the arrays is located. The value for the data -parameter has already been adjusted so that data points to the first element -in the array. Therefore, the first byte of the native array would be at -data - `byte_offset`. + at which the first element of the arrays is located. The value for the data + parameter has already been adjusted so that data points to the first element + in the array. Therefore, the first byte of the native array would be at + `data - byte_offset`. Returns `napi_ok` if the API succeeded. diff --git a/n-api/napi_get_uv_event_loop.md b/n-api/napi_get_uv_event_loop.md index 89179cf6..7729d27e 100644 --- a/n-api/napi_get_uv_event_loop.md +++ b/n-api/napi_get_uv_event_loop.md @@ -13,5 +13,3 @@ NAPI_EXTERN napi_status napi_get_uv_event_loop(napi_env env, * `[in] env`: The environment that the API is invoked under. * `[out] loop`: The current libuv loop instance. - - diff --git a/n-api/napi_is_promise.md b/n-api/napi_is_promise.md index 477587da..0b3a23e6 100644 --- a/n-api/napi_is_promise.md +++ b/n-api/napi_is_promise.md @@ -12,5 +12,5 @@ napi_status napi_is_promise(napi_env env, * `[in] env`: The environment that the API is invoked under. * `[in] promise`: The promise to examine * `[out] is_promise`: Flag indicating whether `promise` is a native promise -object - that is, a promise object created by the underlying engine. + object (that is, a promise object created by the underlying engine). diff --git a/n-api/napi_property_attributes.md b/n-api/napi_property_attributes.md index b1c26420..6a56581f 100644 --- a/n-api/napi_property_attributes.md +++ b/n-api/napi_property_attributes.md @@ -18,15 +18,13 @@ attributes listed in [Section 6.1.7.1][] of the [ECMAScript Language Specification][]. They can be one or more of the following bitflags: -* `napi_default` - Used to indicate that no explicit attributes are set on the -given property. By default, a property is read only, not enumerable and not -configurable. -* `napi_writable` - Used to indicate that a given property is writable. -* `napi_enumerable` - Used to indicate that a given property is enumerable. -* `napi_configurable` - Used to indicate that a given property is configurable, -as defined in [Section 6.1.7.1][] of the [ECMAScript Language Specification][]. -* `napi_static` - Used to indicate that the property will be defined as -a static property on a class as opposed to an instance property, which is the -default. This is used only by [`napi_define_class`][]. It is ignored by -`napi_define_properties`. +* `napi_default`: No explicit attributes are set on the property. By default, a + property is read only, not enumerable and not configurable. +* `napi_writable`: The property is writable. +* `napi_enumerable`: The property is enumerable. +* `napi_configurable`: The property is configurable as defined in + [Section 6.1.7.1][] of the [ECMAScript Language Specification][]. +* `napi_static`: The property will be defined as a static property on a class as + opposed to an instance property, which is the default. This is used only by + [`napi_define_class`][]. It is ignored by `napi_define_properties`. diff --git a/n-api/napi_unref_threadsafe_function.md b/n-api/napi_unref_threadsafe_function.md index fff5ab06..e6ae789d 100644 --- a/n-api/napi_unref_threadsafe_function.md +++ b/n-api/napi_unref_threadsafe_function.md @@ -96,6 +96,17 @@ This API may only be called from the main thread. + + + + + + + + + + + diff --git a/n-api/node_gyp.md b/n-api/node_gyp.md new file mode 100644 index 00000000..e33bc92d --- /dev/null +++ b/n-api/node_gyp.md @@ -0,0 +1,9 @@ + +[node-gyp][] is a build system based on Google's [GYP][] tool and comes +bundled with npm. GYP, and therefore node-gyp, requires that Python be +installed. + +Historically, node-gyp has been the tool of choice for building native +addons. It has widespread adoption and documentation. However, some +developers have run into limitations in node-gyp. + diff --git a/n-api/node_pre_gyp.md b/n-api/node_pre_gyp.md new file mode 100644 index 00000000..cde26c39 --- /dev/null +++ b/n-api/node_pre_gyp.md @@ -0,0 +1,5 @@ + +[node-pre-gyp][] is a tool based on node-gyp that adds the ability to +upload binaries to a server of the developer's choice. node-pre-gyp has +particularly good support for uploading binaries to Amazon S3. + diff --git a/n-api/prebuild.md b/n-api/prebuild.md new file mode 100644 index 00000000..fcc9cd03 --- /dev/null +++ b/n-api/prebuild.md @@ -0,0 +1,6 @@ + +[prebuild][] is a tool that supports builds using either node-gyp or +CMake.js. Unlike node-pre-gyp which supports a variety of servers, prebuild +uploads binaries only to [GitHub releases][]. prebuild is a good choice for +GitHub projects using CMake.js. + diff --git a/n-api/prebuildify.md b/n-api/prebuildify.md new file mode 100644 index 00000000..02413aaa --- /dev/null +++ b/n-api/prebuildify.md @@ -0,0 +1,6 @@ + +[prebuildify][] is tool based on node-gyp. The advantage of prebuildify is +that the built binaries are bundled with the native module when it's +uploaded to npm. The binaries are downloaded from npm and are immediately +available to the module user when the native module is installed. + diff --git a/n-api/simple_asynchronous_operations.md b/n-api/simple_asynchronous_operations.md index ea67de10..d84ffdb1 100644 --- a/n-api/simple_asynchronous_operations.md +++ b/n-api/simple_asynchronous_operations.md @@ -2,8 +2,7 @@ Addon modules often need to leverage async helpers from libuv as part of their implementation. This allows them to schedule work to be executed asynchronously so that their methods can return in advance of the work being completed. This -is important in order to allow them to avoid blocking overall execution -of the Node.js application. +allows them to avoid blocking overall execution of the Node.js application. N-API provides an ABI-stable interface for these supporting functions which covers the most common asynchronous use cases. diff --git a/n-api/uploading_precompiled_binaries.md b/n-api/uploading_precompiled_binaries.md new file mode 100644 index 00000000..53b1ad34 --- /dev/null +++ b/n-api/uploading_precompiled_binaries.md @@ -0,0 +1,8 @@ + +The three tools listed here permit native addon developers and maintainers +to create and upload binaries to public or private servers. These tools are +typically integrated with CI/CD build systems like [Travis CI][] and +[AppVeyor][] to build and upload binaries for a variety of platforms and +architectures. These binaries are then available for download by users who +do not need to have a C/C++ toolchain installed. + diff --git a/n-api/usage.md b/n-api/usage.md index 4e1637e3..a6cf18c2 100644 --- a/n-api/usage.md +++ b/n-api/usage.md @@ -1,7 +1,6 @@ -In order to use the N-API functions, include the file -[`node_api.h`](https://github.com/nodejs/node/blob/master/src/node_api.h) -which is located in the src directory in the node development tree: +In order to use the N-API functions, include the file [`node_api.h`][] which is +located in the src directory in the node development tree: ```C #include diff --git a/n-api/working_with_javascript_values_and_abstract_operations.md b/n-api/working_with_javascript_values_and_abstract_operations.md new file mode 100644 index 00000000..fca2416a --- /dev/null +++ b/n-api/working_with_javascript_values_and_abstract_operations.md @@ -0,0 +1,12 @@ + +N-API exposes a set of APIs to perform some abstract operations on JavaScript +values. Some of these operations are documented under [Section 7][] +of the [ECMAScript Language Specification][]. + +These APIs support doing one of the following: + +1. Coerce JavaScript values to specific JavaScript types (such as `Number` or + `String`). +2. Check the type of a JavaScript value. +3. Check for equality between two JavaScript values. + diff --git a/net/identifying_paths_for_ipc_connections.md b/net/identifying_paths_for_ipc_connections.md index b22e8022..fd898ceb 100644 --- a/net/identifying_paths_for_ipc_connections.md +++ b/net/identifying_paths_for_ipc_connections.md @@ -4,7 +4,7 @@ 在 Unix 上,本地域也称为 Unix 域。 参数 `path` 是文件系统路径名。 -它被从 `sizeof(sockaddr_un.sun_path) - 1` 处被截断,其长度因操作系统不同而在 91 至 107 字节之间变化。 +它被截断为 `sizeof(sockaddr_un.sun_path) - 1` 的长度,该长度因操作系统而异,在 91 至 107 字节之间。 典型值在 Linux 上为 107,在 macOS 上为 103。 该路径受到与创建文件相同的命名约定和权限检查。 如果创建 Unix 域套接字(作为文件系统路径可见)并与 Node.js 的 API 抽象之一(例如 [`net.createServer()`])一起使用,则它将作为 [`server.close()`] 的一部分取消链接。 diff --git a/net/socket_buffersize.md b/net/socket_buffersize.md index ee2ec006..d2c35774 100644 --- a/net/socket_buffersize.md +++ b/net/socket_buffersize.md @@ -4,7 +4,7 @@ added: v0.3.8 * {integer} -`net.Socket` 具有该属性,`socket.write()` 工作时需要。它可以帮助用户快速启动和运行。计算机(处理速度)不能总是跟上 socket 的写入速度 - 网络连接可能太慢了。 Node.js 内部将维护一个写入 socket 的数据队列,并在可能的时候将数据发送出去。(内部实现是对 socket 的文件描述符进行轮询其是否是可写状态。) +`net.Socket` 具有该属性,`socket.write()` 工作时需要。它可以帮助用户快速启动和运行。计算机(处理速度)不能总是跟上 socket 的写入速度。网络连接也可能太慢。 Node.js 内部将维护一个写入 socket 的数据队列,并在可能的时候将数据发送出去。(内部实现是对 socket 的文件描述符进行轮询其是否是可写状态。) 使用内部缓冲的结果是可能造成内存的增长。此属性显示当前即将被写入的缓冲的字符数。(字符串的数目大致等于即将被写入的字节,但缓冲可能包含字符串,而字符串是惰性编码的,所以实际的字节数是不知道的。) diff --git a/net/socket_connect_options_connectlistener.md b/net/socket_connect_options_connectlistener.md index 237dcacd..794beea8 100644 --- a/net/socket_connect_options_connectlistener.md +++ b/net/socket_connect_options_connectlistener.md @@ -38,9 +38,9 @@ changes: 对于这两种类型,可用 `options` 包括: -* `onread` {Object} - 如果指定,则传入的数据会存储在单个 `buffer` 中,并在数据到达套接字时传给提供的 `callback`。 +* `onread` {Object} 如果指定,则传入的数据会存储在单个 `buffer` 中,并在数据到达套接字时传给提供的 `callback`。 这将会导致流式的功能不会提供任何数据,但 `'error'`、`'end'` 和 `'close'` 等事件仍将会被正常触发,且 `pause()` 和 `resume()` 等方法也将会按预期运行。 - * `buffer` {Buffer|Uint8Array|Function} - 用于存储传入数据的可复用的内存块、或返回此类数据的函数。 + * `buffer` {Buffer|Uint8Array|Function} 用于存储传入数据的可复用的内存块、或返回此类数据的函数。 * `callback` {Function} 为每个传入的数据块调用此函数。有两个参数传给它:写入 `buffer` 的字节数和对 `buffer` 的引用。从此函数返回 `false` 可以隐式地 `pause()` 套接字。该函数将会在全局的上下文中执行。 以下是使用 `onread` 选项的客户端的示例: diff --git a/net/socket_write_data_encoding_callback.md b/net/socket_write_data_encoding_callback.md index a41faf71..7f13caca 100644 --- a/net/socket_write_data_encoding_callback.md +++ b/net/socket_write_data_encoding_callback.md @@ -11,7 +11,7 @@ added: v0.1.90 如果全部数据都成功刷新到内核的缓冲则返回 `true`。如果全部或部分数据在用户内中排队,则返回 `false`。当缓冲再次空闲的时候将触发 [`'drain'`][] 事件。 -当数据最终都被写出之后,可选的 `callback` 参数将会被执行 - 可能不会立即执行。 +当数据最终都被写出之后,可选的 `callback` 参数将会被执行(可能不会立即执行)。 详见 `Writable` 流的 [`write()`][stream_writable_write] 方法。 diff --git a/os/error_constants.md b/os/error_constants.md index 0a57af0e..2fdf8718 100644 --- a/os/error_constants.md +++ b/os/error_constants.md @@ -1,3 +1,3 @@ -下面的错误常量由 `os.constants.errno` 给出: +下面的错误常量由 `os.constants.errno` 给出。 diff --git a/os/os_arch.md b/os/os_arch.md index 8bc35c78..b37e3a84 100644 --- a/os/os_arch.md +++ b/os/os_arch.md @@ -4,9 +4,8 @@ added: v0.5.0 * 返回: {string} -`os.arch()` 方法返回一个字符串,表明 Node.js 二进制编译所用的操作系统 CPU 架构。 +返回为其编译 Node.js 二进制文件的操作系统的 CPU 架构。 +可能的值有:`'arm'`、`'arm64'`、`'ia32'`、`'mips'`、`'mipsel'`、`'ppc'`、`'ppc64'`、`'s390'`、`'s390x'`、`'x32'` 和 `'x64'`。 -现在可能的值有:`'arm'`、`'arm64'`、`'ia32'`、`'mips'`、`'mipsel'`、`'ppc'`、`'ppc64'`、`'s390'`、`'s390x'`、`'x32'`、`'x64'`。 - -等价于 [`process.arch`]。 +返回的值等价于 [`process.arch`]。 diff --git a/os/os_constants.md b/os/os_constants.md index a4378bbd..3952f69a 100644 --- a/os/os_constants.md +++ b/os/os_constants.md @@ -4,6 +4,6 @@ added: v6.3.0 * {Object} -返回一个包含错误码,处理信号等通用的操作系统特定常量的对象。 -现在,这些特定的常量的定义被描述在 [OS 常量][_os_constants]。 +包含错误码、进程信号等常用的操作系统特定的常量。 +定义的特定常量在 [OS 常量][_os_constants]中描述。 diff --git a/os/os_cpus.md b/os/os_cpus.md index 6d044ab9..29f2c00f 100644 --- a/os/os_cpus.md +++ b/os/os_cpus.md @@ -4,18 +4,18 @@ added: v0.3.3 * 返回: {Object[]} -`os.cpus()` 方法返回一个对象数组,包含每个逻辑 CPU 内核的信息。 +返回一个对象数组,其中包含有关每个逻辑 CPU 内核的信息。 -下面的属性包含在每个对象中: +每个对象上包含的属性有: * `model` {string} * `speed` {number} 以兆赫兹为单位。 * `times` {Object} - * `user` {number} CPU 花费在用户模式下的毫秒时间数。 - * `nice` {number} CPU 花费在良好模式下的毫秒时间数。 - * `sys` {number} CPU 花费在系统模式下的毫秒时间数。 - * `idle` {number} CPU 花费在空闲模式下的毫秒时间数。 - * `irq` {number} CPU 花费在中断请求模式下的毫秒时间数。 + * `user` {number} CPU 在用户模式下花费的毫秒数。 + * `nice` {number} CPU 在良好模式下花费的毫秒数。 + * `sys` {number} CPU 在系统模式下花费的毫秒数。 + * `idle` {number} CPU 在空闲模式下花费的毫秒数。 + * `irq` {number} CPU 在中断请求模式下花费的毫秒数。 ```js @@ -63,53 +63,10 @@ added: v0.3.3 idle: 1070905480, irq: 20 } - }, - { - model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz', - speed: 2926, - times: { - user: 511580, - nice: 20, - sys: 40900, - idle: 1070842510, - irq: 0 - } - }, - { - model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz', - speed: 2926, - times: { - user: 291660, - nice: 0, - sys: 34360, - idle: 1070888000, - irq: 10 - } - }, - { - model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz', - speed: 2926, - times: { - user: 308260, - nice: 0, - sys: 55410, - idle: 1071129970, - irq: 880 - } - }, - { - model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz', - speed: 2926, - times: { - user: 266450, - nice: 1480, - sys: 34920, - idle: 1072572010, - irq: 30 - } } ] ``` -因为 `nice` 的值是 UNIX 相关的,在 Windows 系统上所有处理器的 `nice` 值总是 0。 +`nice` 的值仅适用于 POSIX。 +在 Windows 上,所有处理器的 `nice` 值始终为 0。 diff --git a/os/os_endianness.md b/os/os_endianness.md index 2e6de244..b64a6e59 100644 --- a/os/os_endianness.md +++ b/os/os_endianness.md @@ -4,10 +4,7 @@ added: v0.9.4 * 返回: {string} -`os.endianness()` 方法返回一个字符串,表明 Node.js 二进制编译环境的字节顺序。 +返回一个字符串,该字符串标识为其编译 Node.js 二进制文件的 CPU 的字节序。 -可能的值: - -* `'BE'` 大端模式。 -* `'LE'` 小端模式。 +可能的值有,`'BE'` 用于大端字节序,`'LE'` 用于小端字节序。 diff --git a/os/os_eol.md b/os/os_eol.md index 07353f38..628b73d4 100644 --- a/os/os_eol.md +++ b/os/os_eol.md @@ -4,8 +4,8 @@ added: v0.7.8 * {string} -一个字符串常量,定义操作系统相关的行末标志: +操作系统特定的行末标志。 -* `\n` 在 POSIX 系统上。 -* `\r\n` 在 Windows 系统上。 +* 在 POSIX 上是 `\n`。 +* 在 Windows 上是 `\r\n`。 diff --git a/os/os_freemem.md b/os/os_freemem.md index b2726550..6c99f27a 100644 --- a/os/os_freemem.md +++ b/os/os_freemem.md @@ -4,5 +4,5 @@ added: v0.3.3 * 返回: {integer} -`os.freemem()` 方法以整数的形式回空闲系统内存的字节数。 +以整数的形式返回空闲的系统内存量(以字节为单位)。 diff --git a/os/os_getpriority_pid.md b/os/os_getpriority_pid.md index bfe5983c..945c7af9 100644 --- a/os/os_getpriority_pid.md +++ b/os/os_getpriority_pid.md @@ -2,9 +2,9 @@ added: v10.10.0 --> -* `pid` {integer} 用于检索调度优先级的进程 ID。**默认值** `0`。 +* `pid` {integer} 要为其获取调度优先级的进程 ID。**默认值** `0`。 * 返回: {integer} -`os.getPriority()` 方法返回由 `pid` 指定的进程的调度优先级。 +返回由 `pid` 指定的进程的调度优先级。 如果未提供 `pid` 或者为 `0`,则返回当前进程的优先级。 diff --git a/os/os_homedir.md b/os/os_homedir.md index 6523f669..e9901f52 100644 --- a/os/os_homedir.md +++ b/os/os_homedir.md @@ -4,14 +4,12 @@ added: v2.3.0 * 返回: {string} -`os.homedir()` 方法以字符串的形式返回当前用户的主目录。 +返回当前用户的主目录的字符串路径。 -在 POSIX 上: -如果定义,则将会使用 `$HOME` 环境变量。 -否则,将会使用[有效的 UID][EUID] 来查找用户的主目录。 +在 POSIX 上,使用 `$HOME` 环境变量(如果有定义)。 +否则,使用[有效的 UID][EUID] 来查找用户的主目录。 -在 Windows 上: -如果定义,则将会使用 `USERPROFILE` 环境变量。 -否则,将会是当前用户的配置文件目录的路径。 +在 Windows 上,使用 `USERPROFILE` 环境变量(如果有定义)。 +否则,使用当前用户的配置文件目录的路径。 diff --git a/os/os_hostname.md b/os/os_hostname.md index 41b194f9..55abf761 100644 --- a/os/os_hostname.md +++ b/os/os_hostname.md @@ -4,5 +4,5 @@ added: v0.3.3 * 返回: {string} -`os.hostname()` 方法以字符串的形式返回操作系统的主机名。 +以字符串的形式返回操作系统的主机名。 diff --git a/os/os_loadavg.md b/os/os_loadavg.md index 76992bd1..83f80b6e 100644 --- a/os/os_loadavg.md +++ b/os/os_loadavg.md @@ -4,11 +4,10 @@ added: v0.3.3 * 返回: {number[]} -`os.loadavg()` 方法返回一个数组,包含 1、5 和 15 分钟平均负载。 +返回一个数组,包含 1、5 和 15 分钟的平均负载。 -平均负载是系统活动的测量,由操作系统计算得出,表达为一个分数。 -一般来说,平均负载应该理想地比系统的逻辑 CPU 的数目要少。 +平均负载是系统活动性的测量,由操作系统计算得出,并表现为一个分数。 -平均负载是 UNIX 相关的概念,在 Windows 平台上没有对应的概念。 -在 Windows 上,其返回值总是 `[0, 0, 0]`。 +平均负载是 UNIX 特定的概念。 +在 Windows 上,其返回值始终为 `[0, 0, 0]`。 diff --git a/os/os_networkinterfaces.md b/os/os_networkinterfaces.md index d39e7e22..9c9c84f2 100644 --- a/os/os_networkinterfaces.md +++ b/os/os_networkinterfaces.md @@ -4,20 +4,20 @@ added: v0.6.0 * 返回: {Object} -`os.networkInterfaces()` 方法返回一个对象,包含只有被赋予网络地址的网络接口。 +返回一个对象,该对象包含已分配了网络地址的网络接口。 -在返回对象的每个关键词都指明了一个网络接口。 -返回的值是一个对象数组,每个都描述了赋予的网络地址。 +返回的对象上的每个键都标识了一个网络接口。 +关联的值是一个对象数组,每个对象描述了一个分配的网络地址。 -被赋予网络地址的对象包含的属性: +分配的网络地址的对象上可用的属性包括: -* `address` {string} 被赋予的 IPv4 或 IPv6 地址。 -* `netmask` {string} IPv4 或 IPv6 子网掩码。 +* `address` {string} 分配的 IPv4 或 IPv6 地址。 +* `netmask` {string} IPv4 或 IPv6 的子网掩码。 * `family` {string} `IPv4` 或 `IPv6`。 * `mac` {string} 网络接口的 MAC 地址。 -* `internal` {boolean} 如果网络接口是 loopback 或相似的远程不能用的接口时,值为 `true`,否则为 `false`。 -* `scopeid` {number} IPv6 数字领域识别码(只有当 `family` 是 `IPv6` 时可用)。 -* `cidr` {string} 以 CIDR 表示法分配的带有路由前缀的 IPv4 或 IPv6 地址。如果 `netmask` 参数不可用,则该属性是 `null`。 +* `internal` {boolean} 如果网络接口是不可远程访问的环回接口或类似接口,则为 `true`,否则为 `false`。 +* `scopeid` {number} 数值型的 IPv6 作用域 ID(仅当 `family` 为 `IPv6` 时指定)。 +* `cidr` {string} 以 CIDR 表示法分配的带有路由前缀的 IPv4 或 IPv6 地址。如果 `netmask` 无效,则此属性会被设为 `null`。 ```js diff --git a/os/os_platform.md b/os/os_platform.md index 12e49885..b9b53da9 100644 --- a/os/os_platform.md +++ b/os/os_platform.md @@ -4,21 +4,13 @@ added: v0.5.0 * 返回: {string} -`os.platform()` 方法返回一个字符串,指定 Node.js 编译时的操作系统平台。 +返回标识操作系统平台的字符串。 +该值在编译时设置。 +可能的值有 `'aix'`、`'darwin'`、`'freebsd'`、`'linux'`、`'openbsd'`、`'sunos'` 和 `'win32'`。 -当前可能的值有: +返回的值等价于 [`process.platform`]。 -* `'aix'` -* `'darwin'` -* `'freebsd'` -* `'linux'` -* `'openbsd'` -* `'sunos'` -* `'win32'` - -等价于 [`process.platform`]。 - -如果 Node.js 在 Android 操作系统上构建,则可能返回 `'android'` 值。 -但是,Node.js 中的 Android 支持目前被视为是[试验的][Android building]。 +如果 Node.js 在 Android 操作系统上构建,则也可能返回 `'android'` 值。 +[Android 的支持是试验性的][Android building]。 diff --git a/policy/error_behavior.md b/policy/error_behavior.md index 0b3baa74..975db29b 100644 --- a/policy/error_behavior.md +++ b/policy/error_behavior.md @@ -4,10 +4,11 @@ It is possible to change the error behavior to one of a few possibilities by defining an "onerror" field in a policy manifest. The following values are available to change the behavior: -* `"exit"` - will exit the process immediately. +* `"exit"`: will exit the process immediately. No cleanup code will be allowed to run. -* `"log"` - will log the error at the site of the failure. -* `"throw"` (default) - will throw a JS error at the site of the failure. +* `"log"`: will log the error at the site of the failure. +* `"throw"`: will throw a JS error at the site of the failure. This is the + default. ```json { diff --git a/report/usage.md b/report/usage.md index 83cf3db8..3e9f5cab 100644 --- a/report/usage.md +++ b/report/usage.md @@ -54,11 +54,11 @@ the name of a file into which the report is written. process.report.writeReport('./foo.json'); ``` -This function takes an optional additional argument `err` - an `Error` object -that will be used as the context for the JavaScript stack printed in the report. -When using report to handle errors in a callback or an exception handler, this -allows the report to include the location of the original error as well -as where it was handled. +This function takes an optional additional argument `err` which is an `Error` +object that will be used as the context for the JavaScript stack printed in the +report. When using report to handle errors in a callback or an exception +handler, this allows the report to include the location of the original error as +well as where it was handled. ```js try { @@ -92,8 +92,9 @@ console.log(typeof report === 'object'); // true console.log(JSON.stringify(report, null, 2)); ``` -This function takes an optional additional argument `err` - an `Error` object -that will be used as the context for the JavaScript stack printed in the report. +This function takes an optional additional argument `err`, which is an `Error` +object that will be used as the context for the JavaScript stack printed in the +report. ```js const report = process.report.getReport(new Error('custom error')); diff --git a/tls/alpn_and_sni.md b/tls/alpn_and_sni.md index ae5e10e6..902ed431 100644 --- a/tls/alpn_and_sni.md +++ b/tls/alpn_and_sni.md @@ -4,7 +4,7 @@ ALPN (Application-Layer Protocol Negotiation Extension) and SNI (Server Name Indication) are TLS handshake extensions: -* ALPN - Allows the use of one TLS server for multiple protocols (HTTP, HTTP/2) -* SNI - Allows the use of one TLS server for multiple hostnames with different +* ALPN: Allows the use of one TLS server for multiple protocols (HTTP, HTTP/2) +* SNI: Allows the use of one TLS server for multiple hostnames with different SSL certificates. diff --git a/tls/tls_default_max_version.md b/tls/tls_default_max_version.md index b6329b57..7a4bec52 100644 --- a/tls/tls_default_max_version.md +++ b/tls/tls_default_max_version.md @@ -6,7 +6,7 @@ added: v11.4.0 [`tls.createSecureContext()`][]. It can be assigned any of the supported TLS protocol versions, `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. **Default:** `'TLSv1.3'`, unless changed using CLI options. Using - `--tls-max-v1.2` sets the default to `'TLSv1.2`'. Using `--tls-max-v1.3` sets + `--tls-max-v1.2` sets the default to `'TLSv1.2'`. Using `--tls-max-v1.3` sets the default to `'TLSv1.3'`. If multiple of the options are provided, the highest maximum is used. diff --git a/tls/tls_default_min_version.md b/tls/tls_default_min_version.md index 63a10d7e..333584fa 100644 --- a/tls/tls_default_min_version.md +++ b/tls/tls_default_min_version.md @@ -4,7 +4,7 @@ added: v11.4.0 * {string} The default value of the `minVersion` option of [`tls.createSecureContext()`][]. It can be assigned any of the supported TLS - protocol versions, `'TLSv1.3'`, `TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. + protocol versions, `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. **Default:** `'TLSv1.2'`, unless changed using CLI options. Using `--tls-min-v1.0` sets the default to `'TLSv1'`. Using `--tls-min-v1.1` sets the default to `'TLSv1.1'`. Using `--tls-min-v1.3` sets the default to diff --git a/tracing/trace_events.md b/tracing/trace_events.md index bb696529..39c283b0 100644 --- a/tracing/trace_events.md +++ b/tracing/trace_events.md @@ -12,26 +12,26 @@ accepts a list of comma-separated category names. The available categories are: -* `node` - An empty placeholder. -* `node.async_hooks` - Enables capture of detailed [`async_hooks`][] trace data. +* `node`: An empty placeholder. +* `node.async_hooks`: Enables capture of detailed [`async_hooks`][] trace data. The [`async_hooks`][] events have a unique `asyncId` and a special `triggerId` `triggerAsyncId` property. -* `node.bootstrap` - Enables capture of Node.js bootstrap milestones. -* `node.console` - Enables capture of `console.time()` and `console.count()` +* `node.bootstrap`: Enables capture of Node.js bootstrap milestones. +* `node.console`: Enables capture of `console.time()` and `console.count()` output. -* `node.dns.native` - Enables capture of trace data for DNS queries. -* `node.environment` - Enables capture of Node.js Environment milestones. -* `node.fs.sync` - Enables capture of trace data for file system sync methods. -* `node.perf` - Enables capture of [Performance API][] measurements. - * `node.perf.usertiming` - Enables capture of only Performance API User Timing +* `node.dns.native`: Enables capture of trace data for DNS queries. +* `node.environment`: Enables capture of Node.js Environment milestones. +* `node.fs.sync`: Enables capture of trace data for file system sync methods. +* `node.perf`: Enables capture of [Performance API][] measurements. + * `node.perf.usertiming`: Enables capture of only Performance API User Timing measures and marks. - * `node.perf.timerify` - Enables capture of only Performance API timerify + * `node.perf.timerify`: Enables capture of only Performance API timerify measurements. -* `node.promises.rejections` - Enables capture of trace data tracking the number +* `node.promises.rejections`: Enables capture of trace data tracking the number of unhandled Promise rejections and handled-after-rejections. -* `node.vm.script` - Enables capture of trace data for the `vm` module's +* `node.vm.script`: Enables capture of trace data for the `vm` module's `runInNewContext()`, `runInContext()`, and `runInThisContext()` methods. -* `v8` - The [V8][] events are GC, compiling, and execution related. +* `v8`: The [V8][] events are GC, compiling, and execution related. By default the `node`, `node.async_hooks`, and `v8` categories are enabled. diff --git a/util/util_types.md b/util/util_types.md index 26e78c3b..da74a6c1 100644 --- a/util/util_types.md +++ b/util/util_types.md @@ -2,11 +2,10 @@ added: v10.0.0 --> -`util.types` provides a number of type checks for different kinds of built-in -objects. Unlike `instanceof` or `Object.prototype.toString.call(value)`, -these checks do not inspect properties of the object that are accessible from -JavaScript (like their prototype), and usually have the overhead of -calling into C++. +`util.types` provides type checks for different kinds of built-in objects. +Unlike `instanceof` or `Object.prototype.toString.call(value)`, these checks do +not inspect properties of the object that are accessible from JavaScript (like +their prototype), and usually have the overhead of calling into C++. The result generally does not make any guarantees about what kinds of properties or behavior a value exposes in JavaScript. They are primarily
Constant