Skip to content

Commit

Permalink
feat: 14.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
h7lin committed Jul 23, 2020
1 parent 962466f commit 68287e2
Show file tree
Hide file tree
Showing 272 changed files with 1,740 additions and 857 deletions.
4 changes: 1 addition & 3 deletions addons/callbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ using v8::Function;
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::NewStringType;
using v8::Null;
using v8::Object;
using v8::String;
Expand All @@ -26,8 +25,7 @@ void RunCallback(const FunctionCallbackInfo<Value>& args) {
const unsigned argc = 1;
Local<Value> argv[argc] = {
String::NewFromUtf8(isolate,
"hello world",
NewStringType::kNormal).ToLocalChecked() };
"hello world").ToLocalChecked() };
cb->Call(context, Null(isolate), argc, argv).ToLocalChecked();
}
Expand Down
3 changes: 1 addition & 2 deletions addons/context_aware_addons.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ NODE_MODULE_INIT(/* exports, module, context */) {
// 把 `Method` 方法暴露给 JavaScript,
// 并确保其接收我们通过把 `external` 作为 `FunctionTemplate` 构造函数第三个参数时创建的每个插件实例的数据。
exports->Set(context,
String::NewFromUtf8(isolate, "method", NewStringType::kNormal)
.ToLocalChecked(),
String::NewFromUtf8(isolate, "method").ToLocalChecked(),
FunctionTemplate::New(isolate, Method, external)
->GetFunction(context).ToLocalChecked()).FromJust();
}
Expand Down
4 changes: 1 addition & 3 deletions addons/factory_of_wrapped_objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ using v8::FunctionTemplate;
using v8::Global;
using v8::Isolate;
using v8::Local;
using v8::NewStringType;
using v8::Number;
using v8::Object;
using v8::String;
Expand All @@ -106,8 +105,7 @@ MyObject::~MyObject() {
void MyObject::Init(Isolate* isolate) {
// 准备构造函数模版
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
tpl->SetClassName(String::NewFromUtf8(
isolate, "MyObject", NewStringType::kNormal).ToLocalChecked());
tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
// 原型
Expand Down
11 changes: 4 additions & 7 deletions addons/function_arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ using v8::Exception;
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::NewStringType;
using v8::Number;
using v8::Object;
using v8::String;
Expand All @@ -29,18 +28,16 @@ void Add(const FunctionCallbackInfo<Value>& args) {
if (args.Length() < 2) {
// 抛出一个错误并传回到 JavaScript。
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate,
"参数的数量错误",
NewStringType::kNormal).ToLocalChecked()));
String::NewFromUtf8(isolate,
"参数的数量错误").ToLocalChecked()));
return;
}
// 检查参数的类型。
if (!args[0]->IsNumber() || !args[1]->IsNumber()) {
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate,
"参数错误",
NewStringType::kNormal).ToLocalChecked()));
String::NewFromUtf8(isolate,
"参数错误").ToLocalChecked()));
return;
}
Expand Down
5 changes: 2 additions & 3 deletions addons/function_factory.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
using v8::Isolate;
using v8::Local;
using v8::NewStringType;
using v8::Object;
using v8::String;
using v8::Value;
void MyFunction(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
args.GetReturnValue().Set(String::NewFromUtf8(
isolate, "hello world", NewStringType::kNormal).ToLocalChecked());
isolate, "hello world").ToLocalChecked());
}
void CreateFunction(const FunctionCallbackInfo<Value>& args) {
Expand All @@ -33,7 +32,7 @@ void CreateFunction(const FunctionCallbackInfo<Value>& args) {
// 可以省略这步使它匿名
fn->SetName(String::NewFromUtf8(
isolate, "theFunction", NewStringType::kNormal).ToLocalChecked());
isolate, "theFunction").ToLocalChecked());
args.GetReturnValue().Set(fn);
}
Expand Down
3 changes: 1 addition & 2 deletions addons/hello_world.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ namespace demo {
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::NewStringType;
using v8::Object;
using v8::String;
using v8::Value;
void Method(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
args.GetReturnValue().Set(String::NewFromUtf8(
isolate, "world", NewStringType::kNormal).ToLocalChecked());
isolate, "world").ToLocalChecked());
}
void Initialize(Local<Object> exports) {
Expand Down
4 changes: 1 addition & 3 deletions addons/object_factory.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ using v8::Context;
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::NewStringType;
using v8::Object;
using v8::String;
using v8::Value;
Expand All @@ -24,8 +23,7 @@ void CreateObject(const FunctionCallbackInfo<Value>& args) {
Local<Object> obj = Object::New(isolate);
obj->Set(context,
String::NewFromUtf8(isolate,
"msg",
NewStringType::kNormal).ToLocalChecked(),
"msg").ToLocalChecked(),
args[0]->ToString(context).ToLocalChecked())
.FromJust();
Expand Down
4 changes: 1 addition & 3 deletions addons/passing_wrapped_objects_around.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ using v8::FunctionTemplate;
using v8::Global;
using v8::Isolate;
using v8::Local;
using v8::NewStringType;
using v8::Object;
using v8::String;
using v8::Value;
Expand All @@ -114,8 +113,7 @@ MyObject::~MyObject() {
void MyObject::Init(Isolate* isolate) {
// Prepare constructor template
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
tpl->SetClassName(String::NewFromUtf8(
isolate, "MyObject", NewStringType::kNormal).ToLocalChecked());
tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
Local<Context> context = isolate->GetCurrentContext();
Expand Down
8 changes: 3 additions & 5 deletions addons/wrapping_c_objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
using v8::Isolate;
using v8::Local;
using v8::NewStringType;
using v8::Number;
using v8::Object;
using v8::ObjectTemplate;
Expand All @@ -91,8 +90,7 @@ void MyObject::Init(Local<Object> exports) {
// 准备构造函数模版
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New, addon_data);
tpl->SetClassName(String::NewFromUtf8(
isolate, "MyObject", NewStringType::kNormal).ToLocalChecked());
tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
// 原型
Expand All @@ -101,8 +99,8 @@ void MyObject::Init(Local<Object> exports) {
Local<Function> constructor = tpl->GetFunction(context).ToLocalChecked();
addon_data->SetInternalField(0, constructor);
exports->Set(context, String::NewFromUtf8(
isolate, "MyObject", NewStringType::kNormal).ToLocalChecked(),
constructor).FromJust();
isolate, "MyObject").ToLocalChecked(),
constructor).FromJust();
}
void MyObject::New(const FunctionCallbackInfo<Value>& args) {
Expand Down
2 changes: 2 additions & 0 deletions assert/assert.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@

> 稳定性: 2 - 稳定

<!-- source_link=lib/assert.js -->

`assert` 模块提供了一组断言函数,用于验证不变量。

2 changes: 2 additions & 0 deletions async_hooks/async_hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

> Stability: 1 - Experimental

<!-- source_link=lib/async_hooks.js -->

The `async_hooks` module provides an API to track asynchronous resources. It
can be accessed using:

Expand Down
37 changes: 28 additions & 9 deletions async_hooks/asynchronous_context_example.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,17 @@ async_hooks.createHook({
},
before(asyncId) {
const indentStr = ' '.repeat(indent);
fs.writeFileSync('log.out',
`${indentStr}before: ${asyncId}\n`, { flag: 'a' });
fs.writeSync(process.stdout.fd, `${indentStr}before: ${asyncId}\n`);
indent += 2;
},
after(asyncId) {
indent -= 2;
const indentStr = ' '.repeat(indent);
fs.writeFileSync('log.out',
`${indentStr}after: ${asyncId}\n`, { flag: 'a' });
fs.writeSync(process.stdout.fd, `${indentStr}after: ${asyncId}\n`);
},
destroy(asyncId) {
const indentStr = ' '.repeat(indent);
fs.writeFileSync('log.out',
`${indentStr}destroy: ${asyncId}\n`, { flag: 'a' });
fs.writeSync(process.stdout.fd, `${indentStr}destroy: ${asyncId}\n`);
},
}).enable();
Expand Down Expand Up @@ -66,14 +63,36 @@ the value of the current execution context; which is delineated by calls to
Only using `execution` to graph resource allocation results in the following:

```console
Timeout(7) -> TickObject(6) -> root(1)
root(1)
^
|
TickObject(6)
^
|
Timeout(7)
```

The `TCPSERVERWRAP` is not part of this graph, even though it was the reason for
`console.log()` being called. This is because binding to a port without a host
name is a *synchronous* operation, but to maintain a completely asynchronous
API the user's callback is placed in a `process.nextTick()`.
API the user's callback is placed in a `process.nextTick()`. Which is why
`TickObject` is present in the output and is a 'parent' for `.listen()`
callback.

The graph only shows *when* a resource was created, not *why*, so to track
the *why* use `triggerAsyncId`.
the *why* use `triggerAsyncId`. Which can be represented with the following
graph:

```console
bootstrap(1)
|
˅
TCPSERVERWRAP(5)
|
˅
TickObject(6)
|
˅
Timeout(7)
```

2 changes: 1 addition & 1 deletion async_hooks/resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ been initialized. This can contain useful information that can vary based on
the value of `type`. For instance, for the `GETADDRINFOREQWRAP` resource type,
`resource` provides the host name used when looking up the IP address for the
host in `net.Server.listen()`. The API for accessing this information is
currently not considered public, but using the Embedder API, users can provide
not supported, but using the Embedder API, users can provide
and document their own resource objects. For example, such a resource object
could contain the SQL query being executed.

Expand Down
6 changes: 3 additions & 3 deletions buffer/buf_byteoffset.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

* {integer} 创建 `Buffer` 对象时基于的底层 `ArrayBuffer` 对象的 `byteOffset`
* {integer} `Buffer` 底层的 `ArrayBuffer` 对象的 `byteOffset`

`Buffer.from(ArrayBuffer, byteOffset, length)` 设置了 `byteOffset` 或创建一个小于 `Buffer.poolSize` buffer 时,底层的 `ArrayBuffer` 的偏移量并不是从 0 开始。
`Buffer.from(ArrayBuffer, byteOffset, length)` 设置了 `byteOffset` 或创建一个小于 `Buffer.poolSize` `Buffer` 时,底层的 `ArrayBuffer` 的偏移量并不是从 0 开始。

当直接使用 `buf.buffer` 访问底层的 `ArrayBuffer` 时可能会导致问题,因为 `ArrayBuffer` 的其他部分可能并不指向 `buf` 对象。
当直接使用 `buf.buffer` 访问底层的 `ArrayBuffer` 时可能会导致问题,因为 `ArrayBuffer` 的其他部分可能并不指向 `Buffer` 对象。

当创建与 `Buffer` 共享其内存的 `TypedArray` 对象时,需要正确地指定 `byteOffset`

Expand Down
2 changes: 1 addition & 1 deletion buffer/buf_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name: [index]
该值指向单个字节,所以有效的值的范围是 `0x00` `0xFF`(十六进制)、或 `0` `255`(十进制)。

该操作符继承自 `Uint8Array`,所以对越界访问的行为与 `Uint8Array` 相同。
也就是说,当 `index` 为负数或 `>= buf.length` 时,则 `buf[index]` 返回 `undefined`,而如果 `index` 为负数或 `>= buf.length` 时,则 `buf[index] = value` 不会修改该 buffer。
也就是说,当 `index` 为负数或大于或等于 `buf.length` 时,则 `buf[index]` 返回 `undefined`,而如果 `index` 为负数或 `>= buf.length` 时,则 `buf[index] = value` 不会修改该 buffer。

```js
// 拷贝 ASCII 字符串到 `Buffer`,每次拷贝一个字节。
Expand Down
13 changes: 13 additions & 0 deletions buffer/buf_readbigint64be_offset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- YAML
added:
- v12.0.0
- v10.20.0
-->

* `offset` {integer} 开始读取之前要跳过的字节数。必须满足:`0 <= offset <= buf.length - 8`**默认值:** `0`
* 返回: {bigint}

`buf` 中指定的 `offset` 读取一个有符号大端序的 64 位整数值。

`Buffer` 中读取的整数值会被解析为二进制补码值。

2 changes: 1 addition & 1 deletion buffer/buf_readbigint64le_offset.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ added:
* `offset` {integer} 开始读取之前要跳过的字节数。必须满足:`0 <= offset <= buf.length - 8`**默认值:** `0`
* 返回: {bigint}

用指定的[字节序][endianness]`readBigInt64BE()` 读取为大端序,`readBigInt64LE()` 读取为小端序) `buf` 中指定的 `offset` 读取一个有符号的 64 位整数值。
`buf` 中指定的 `offset` 读取一个有符号小端序的 64 位整数值。

`Buffer` 中读取的整数值会被解析为二进制补码值。

18 changes: 18 additions & 0 deletions buffer/buf_readbiguint64be_offset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!-- YAML
added:
- v12.0.0
- v10.20.0
-->

* `offset` {integer} 开始读取之前要跳过的字节数。必须满足:`0 <= offset <= buf.length - 8`**默认值:** `0`
* 返回: {bigint}

`buf` 中指定的 `offset` 读取一个无符号大端序的 64 位整数值。

```js
const buf = Buffer.from([0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff]);
console.log(buf.readBigUInt64BE(0));
// 打印: 4294967295n
```

5 changes: 1 addition & 4 deletions buffer/buf_readbiguint64le_offset.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ added:
* `offset` {integer} 开始读取之前要跳过的字节数。必须满足:`0 <= offset <= buf.length - 8`**默认值:** `0`
* 返回: {bigint}

用指定的[字节序][endianness]`readBigUInt64BE()` 读取为大端序,`readBigUInt64LE()` 读取为小端序) `buf` 中指定的 `offset` 读取一个无符号的 64 位整数值。
`buf` 中指定的 `offset` 读取一个无符号小端序的 64 位整数值。

```js
const buf = Buffer.from([0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff]);
console.log(buf.readBigUInt64BE(0));
// 打印: 4294967295n
console.log(buf.readBigUInt64LE(0));
// 打印: 18446744069414584320n
```
Expand Down
21 changes: 21 additions & 0 deletions buffer/buf_readdoublebe_offset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!-- YAML
added: v0.11.15
changes:
- version: v10.0.0
pr-url: https://github.com/nodejs/node/pull/18395
description: Removed `noAssert` and no implicit coercion of the offset
to `uint32` anymore.
-->

* `offset` {integer} 开始读取之前要跳过的字节数。必须满足:`0 <= offset <= buf.length - 8`**默认值:** `0`
* 返回: {number}

`buf` 中指定的 `offset` 读取一个 64 位的大端序双精度值。

```js
const buf = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
console.log(buf.readDoubleBE(0));
// 打印: 8.20788039913184e-304
```

4 changes: 1 addition & 3 deletions buffer/buf_readdoublele_offset.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ changes:
* `offset` {integer} 开始读取之前要跳过的字节数。必须满足:`0 <= offset <= buf.length - 8`**默认值:** `0`
* 返回: {number}

用指定的[字节序][endianness]`readDoubleBE()` 读取为大端序,`readDoubleLE()` 读取为小端序) `buf` 中指定的 `offset` 读取一个 64 位双精度值
`buf` 中指定的 `offset` 读取一个 64 位的小端序双精度值

```js
const buf = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
console.log(buf.readDoubleBE(0));
// 打印: 8.20788039913184e-304
console.log(buf.readDoubleLE(0));
// 打印: 5.447603722011605e-270
console.log(buf.readDoubleLE(1));
Expand Down
Loading

0 comments on commit 68287e2

Please sign in to comment.