Skip to content

Commit

Permalink
v12.13.1
Browse files Browse the repository at this point in the history
  • Loading branch information
h7lin committed Nov 20, 2019
1 parent 8236144 commit 849f509
Show file tree
Hide file tree
Showing 91 changed files with 349 additions and 312 deletions.
19 changes: 9 additions & 10 deletions addons/c_addons.md
Original file line number Diff line number Diff line change
Expand Up @@ -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],并可用作学习插件的起点

19 changes: 10 additions & 9 deletions addons/linking_to_node_js_own_dependencies.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@

Node.js 使用了一些静态链接库,比如 V8 引擎、libuv OpenSSL。
所有的插件都需要链接到 V8,也可能链接到任何其他依赖
通常情况下,只要简单地包含相应的 `#include <...>` 声明(如 `#include <v8.h>`),则 `node-gyp` 会自动定位到相应的头文件
但是也有一些注意事项需要注意
Node.js 使用了静态链接库,比如 V8、libuv OpenSSL。
所有的插件都需要链接到 V8,也可能链接到任何其他的依赖项
通常情况下,只要简单地引入相应的 `#include <...>` 声明(如 `#include <v8.h>`),则 `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` 标志来运行。
如果使用该选项,则插件有全套依赖的访问权限。

2 changes: 1 addition & 1 deletion addons/n_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

7 changes: 4 additions & 3 deletions buffer/buf_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`,每次拷贝一个字节。
Expand Down
16 changes: 8 additions & 8 deletions buffer/buffers_and_character_encodings.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'` 编码可能错误地解码字符。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ changes:
返回的 [`ChildProcess`] 将会内置一个额外的通信通道,允许消息在父进程和子进程之间来回传递。
详见 [`subprocess.send()`]

重要的是要记住,衍生的 Node.js 子进程独立于父进程,但两者之间建立的 IPC 通信通道除外。
记住,衍生的 Node.js 子进程独立于父进程,但两者之间建立的 IPC 通信通道除外。
每个进程都有自己的内存,带有自己的 V8 实例。
由于需要额外的资源分配,因此不建议衍生大量的 Node.js 子进程。

Expand Down
3 changes: 2 additions & 1 deletion cli/.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
added: v8.0.0
-->

stdin 的别名,类似于在其他命令行工具中使用 `-`,表示将会从 stdin 读取脚本,且其余的选项会传给该脚本。
stdin 的别名。
类似于在其他命令行工具中使用 `-`,这意味着将会从 stdin 读取脚本,且其余的选项会传给该脚本。

3 changes: 3 additions & 0 deletions cli/enable_source_maps.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

3 changes: 0 additions & 3 deletions cli/heap_prof_name.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

3 changes: 2 additions & 1 deletion cli/heapsnapshot_signal_signal.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 &
Expand Down
13 changes: 10 additions & 3 deletions cli/source_map_cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
]
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion cluster/cluster_schedulingpolicy.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion cluster/cluster_settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ changes:
* `inspectPort` {number|Function} 设置工作进程的检查端口。这可以是一个数字、或不带参数并返回数字的函数。默认情况下,每个工作进程都有自己的端口,从主进程的 `process.debugPort` 开始递增。
* `windowsHide` {boolean} 隐藏衍生的进程的控制台窗口(通常在 Windows 系统上会创建)。**默认值:** `false`

调用 `.setupMaster()`(或 `.fork()`)之后,这个配置对象将会包含这些配置项,包括默认值。
调用 [`.setupMaster()`](或 [`.fork()`])之后,这个配置对象将会包含这些配置项,包括默认值。

这个对象不打算被修改或手动设置。

4 changes: 2 additions & 2 deletions cluster/cluster_setupmaster_settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ changes:
`setupMaster` 用于修改默认的 'fork' 行为。
一旦调用,将会按照 `cluster.settings` 进行设置。

所有的设置只对后来的 `.fork()` 调用有效,对之前的工作进程无影响。
所有的设置只对后来的 [`.fork()`] 调用有效,对之前的工作进程无影响。

唯一无法通过 `.setupMaster()` 设置的属性是传给 `.fork()` `env` 属性。
唯一无法通过 `.setupMaster()` 设置的属性是传给 [`.fork()`] `env` 属性。

上述的默认值只在第一次调用时有效,当后续调用时,将采用 `cluster.setupMaster()` 调用时的当前值。

Expand Down
2 changes: 1 addition & 1 deletion cluster/event_exit_1.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ added: v0.7.9

当任何一个工作进程关闭的时候,cluster 模块都将会触发 `'exit'` 事件。

这可以用于重启工作进程(通过再次调用 `.fork()`)。
这可以用于重启工作进程(通过再次调用 [`.fork()`])。

```js
cluster.on('exit', (worker, code, signal) => {
Expand Down
19 changes: 2 additions & 17 deletions cluster/event_message_1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'`]

4 changes: 2 additions & 2 deletions cluster/event_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ added: v0.7.1

* `settings` {Object}

每当 `.setupMaster()` 被调用时触发。
每当 [`.setupMaster()`] 被调用时触发。

`settings` 对象是 `setupMaster()` 被调用时的 `cluster.settings` 对象,并且只能查询,因为在一个时间点内 `.setupMaster()` 可以被调用多次。
`settings` 对象是 [`.setupMaster()`] 被调用时的 `cluster.settings` 对象,并且只能查询,因为在一个时间点内 [`.setupMaster()`] 可以被调用多次。

如果精确度十分重要,则使用 `cluster.settings`

Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ changes:

* `message` {Object}
* `sendHandle` {Handle}
* `options` {Object} `options` 参数(如果存在)是一个对象,用于参数化某些类型的句柄的发送。`options` 支持以下属性:
* `keepOpen` {boolean} 当传递 `net.Socket` 实例时可以使用的值。 当为 `true` 时,套接字在发送的过程中保持打开状态。**默认值:** `false`
* `callback` {Function}
* 返回: {boolean}

发送一个消息给工作进程或主进程,也可以附带发送一个句柄
发送消息给工作进程或主进程,可以选择带上句柄

在主进程中,这会发送消息给特定的工作进程。
相当于 [`ChildProcess.send()`]

在工作进程中,这会发送消息给主进程。
相当于 `process.send()`

这个例子里面,工作进程将主进程发送的消息响应回去
此示例将会回响主进程的所有消息

```js
if (cluster.isMaster) {
Expand Down
2 changes: 1 addition & 1 deletion crypto/crypto_createcipheriv_algorithm_key_iv_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ changes:
初始化向量应该是不可预测的且唯一的,理想情况下,它们在密码上是随机的。
它们不必是私密的:IV 通常只是添加到未加密的密文消息中。
它们必须是不可预测的且唯一的,但不一定是私密的,这听起来似乎是矛盾的。
重要的是要记住,攻击者必须无法提前预测给定的 IV 将会是什么。
记住,攻击者必须无法提前预测给定的 IV 将会是什么。

2 changes: 1 addition & 1 deletion crypto/crypto_createdecipheriv_algorithm_key_iv_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ changes:
初始化向量应该是不可预测的且唯一的,理想情况下,它们在密码上是随机的。
它们不必是私密的:IV 通常只是添加到未加密的密文消息中。
它们必须是不可预测的且唯一的,但不一定是私密的,这听起来似乎是矛盾的。
重要的是要记住,攻击者必须无法提前预测给定的 IV 将会是什么。
记住,攻击者必须无法提前预测给定的 IV 将会是什么。

4 changes: 2 additions & 2 deletions crypto/crypto_sign_algorithm_data_key.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions crypto/crypto_verify_algorithm_data_key_signature.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion crypto/openssl_engine_constants.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<!--lint enable maximum-line-length remark-lint-->

<table>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion crypto/openssl_options.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!--lint disable maximum-line-length-->

<table>
<tr>
<th>Constant</th>
Expand Down
4 changes: 2 additions & 2 deletions crypto/sign_sign_privatekey_outputencoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ 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`

`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][], 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
Expand Down
Loading

0 comments on commit 849f509

Please sign in to comment.