Skip to content

Commit

Permalink
v8.6
Browse files Browse the repository at this point in the history
  • Loading branch information
h7lin committed Oct 4, 2017
1 parent b827482 commit 5333907
Show file tree
Hide file tree
Showing 192 changed files with 714 additions and 828 deletions.
2 changes: 2 additions & 0 deletions addons/c_addons.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

<!--introduced_in=v0.10.0-->

Node.js 插件是用 C++ 编写的动态链接共享对象,可以使用 [`require()`] 函数加载到 Node.js 中,且像普通的 Node.js 模块一样被使用。
它们主要用于为运行在 Node.js 中的 JavaScript C/C++ 库之间提供接口。

Expand Down
2 changes: 1 addition & 1 deletion addons/callbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void Init(Local<Object> exports, Local<Object> module) {
NODE_SET_METHOD(module, "exports", RunCallback);
}
NODE_MODULE(addon, Init)
NODE_MODULE(NODE_GYP_MODULE_NAME, Init)
} // namespace demo
```
Expand Down
2 changes: 1 addition & 1 deletion addons/factory_of_wrapped_objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void InitAll(Local<Object> exports, Local<Object> module) {
NODE_SET_METHOD(module, "exports", CreateObject);
}
NODE_MODULE(addon, InitAll)
NODE_MODULE(NODE_GYP_MODULE_NAME, InitAll)
} // namespace demo
```
Expand Down
2 changes: 1 addition & 1 deletion addons/function_arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void Init(Local<Object> exports) {
NODE_SET_METHOD(exports, "add", Add);
}
NODE_MODULE(addon, Init)
NODE_MODULE(NODE_GYP_MODULE_NAME, Init)
} // namespace demo
```
Expand Down
2 changes: 1 addition & 1 deletion addons/function_factory.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void Init(Local<Object> exports, Local<Object> module) {
NODE_SET_METHOD(module, "exports", CreateFunction);
}
NODE_MODULE(addon, Init)
NODE_MODULE(NODE_GYP_MODULE_NAME, Init)
} // namespace demo
```
Expand Down
4 changes: 2 additions & 2 deletions addons/hello_world.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void init(Local<Object> exports) {
NODE_SET_METHOD(exports, "hello", Method);
}
NODE_MODULE(addon, init)
NODE_MODULE(NODE_GYP_MODULE_NAME, Init)
} // namespace demo
```
Expand All @@ -38,7 +38,7 @@ NODE_MODULE(addon, init)

```cpp
void Initialize(Local<Object> exports);
NODE_MODULE(module_name, Initialize)
NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize)
```

`NODE_MODULE` 后面没有分号,因为它不是一个函数(详见 `node.h`)。
Expand Down
2 changes: 1 addition & 1 deletion addons/object_factory.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void Init(Local<Object> exports, Local<Object> module) {
NODE_SET_METHOD(module, "exports", CreateObject);
}
NODE_MODULE(addon, Init)
NODE_MODULE(NODE_GYP_MODULE_NAME, Init)
} // namespace demo
```
Expand Down
2 changes: 1 addition & 1 deletion addons/passing_wrapped_objects_around.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void InitAll(Local<Object> exports) {
NODE_SET_METHOD(exports, "add", Add);
}
NODE_MODULE(addon, InitAll)
NODE_MODULE(NODE_GYP_MODULE_NAME, InitAll)
} // namespace demo
```
Expand Down
2 changes: 1 addition & 1 deletion addons/void_atexit_callback_args.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void init(Local<Object> exports) {
AtExit(sanity_check);
}
NODE_MODULE(addon, init)
NODE_MODULE(NODE_GYP_MODULE_NAME, init)
} // namespace demo
```
Expand Down
2 changes: 1 addition & 1 deletion addons/wrapping_c_objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void InitAll(Local<Object> exports) {
MyObject::Init(exports);
}
NODE_MODULE(addon, InitAll)
NODE_MODULE(NODE_GYP_MODULE_NAME, InitAll)
} // namespace demo
```
Expand Down
1 change: 1 addition & 0 deletions assert/__link.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
[enumerable "own" properties]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties
[mdn-equality-guide]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness
[prototype-spec]: https://tc39.github.io/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots
[Object wrappers]: https://developer.mozilla.org/en-US/docs/Glossary/Primitive#Primitive_wrapper_objects_in_JavaScript

[正则表达式]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
[相等运算符]: https://tc39.github.io/ecma262/#sec-abstract-equality-comparison
Expand Down
2 changes: 2 additions & 0 deletions assert/assert.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

<!--introduced_in=v0.10.0-->

> 稳定性: 2 - 稳定的

`assert` 模块提供了断言测试的函数,用于测试不变式。
Expand Down
4 changes: 2 additions & 2 deletions assert/assert_deepequal_actual_expected_message.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ changes:
原始值使用[相等运算符]`==`)比较。

只测试[可枚举的自身属性],不测试对象的[原型]、连接符、或不可枚举的属性(这些情况使用 [`assert.deepStrictEqual()`])。
例如,下面的例子不会抛出 `AssertionError`,因为 [`Error`] 对象的属性不是可枚举的:
例如,下面的例子不会抛出 `AssertionError`,因为 [`RegExp`] 对象的属性不是可枚举的:

```js
// 不会抛出 AssertionError。
assert.deepEqual(Error('a'), Error('b'));
assert.deepEqual(/a/gi, new Date());
```

[`Map`] [`Set`] 包含的子项也会被测试。
Expand Down
11 changes: 10 additions & 1 deletion assert/assert_deepstrictequal_actual_expected_message.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<!-- YAML
added: v1.2.0
changes:
- version: v8.5.0
pr-url: https://github.com/nodejs/node/pull/15001
description: Error names and messages are now properly compared
- version: v8.0.0
pr-url: https://github.com/nodejs/node/pull/12142
description: Set and Map content is also compared
Expand All @@ -18,11 +21,12 @@ changes:
* `expected` {any}
* `message` {any}

`assert.deepEqual()` 大致相同,但有三个区别
`assert.deepEqual()` 大致相同,但有一些区别

1. 原始值使用[全等运算符]`===`)比较。`Set` 的值与 `Map` 的键使用 [SameValueZero] 比较。
2. 对象的[原型]也使用全等运算符比较。
3. 对象的[类型标签]要求相同。
4. [Object wrappers][] are compared both as objects and unwrapped values.

```js
const assert = require('assert');
Expand Down Expand Up @@ -52,6 +56,11 @@ assert.deepEqual(date, fakeDate);
assert.deepStrictEqual(date, fakeDate);
// 抛出 AssertionError: 2017-03-11T14:25:31.849Z deepStrictEqual Date {}
// 因为类型标签不同。
assert.deepStrictEqual(new Number(1), new Number(2));
// Fails because the wrapped number is unwrapped and compared as well.
assert.deepStrictEqual(new String('foo'), Object('foo'));
// OK because the object and the string are identical when unwrapped.
```

如果两个值不相等,则抛出一个带有 `message` 属性的 `AssertionError`,其中 `message` 属性的值等于传入的 `message` 参数的值。
Expand Down
2 changes: 1 addition & 1 deletion async_hooks/after_asyncid.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Called immediately after the callback specified in `before` is completed.

*Note:* If an uncaught exception occurs during execution of the callback then
`after` will run after the `'uncaughtException'` event is emitted or a
`after` will run *after* the `'uncaughtException'` event is emitted or a
`domain`'s handler runs.


31 changes: 30 additions & 1 deletion async_hooks/async_hooks_createhook_callbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
added: v8.1.0
-->

* `callbacks` {Object} the callbacks to register
* `callbacks` {Object} the [Hook Callbacks][] to register
* `init` {Function} The [`init` callback][].
* `before` {Function} The [`before` callback][].
* `after` {Function} The [`after` callback][].
* `destroy` {Function} The [`destroy` callback][].
* Returns: `{AsyncHook}` instance used for disabling and enabling hooks

Registers functions to be called for different lifetime events of each async
Expand All @@ -17,3 +21,28 @@ be tracked then only the `destroy` callback needs to be passed. The
specifics of all functions that can be passed to `callbacks` is in the section
[`Hook Callbacks`][].

```js
const async_hooks = require('async_hooks');
const asyncHook = async_hooks.createHook({
init(asyncId, type, triggerAsyncId, resource) { },
destroy(asyncId) { }
});
```

Note that the callbacks will be inherited via the prototype chain:

```js
class MyAsyncCallbacks {
init(asyncId, type, triggerAsyncId, resource) { }
destroy(asyncId) {}
}
class MyAddedCallbacks extends MyAsyncCallbacks {
before(asyncId) { }
after(asyncId) { }
}
const asyncHook = async_hooks.createHook(new MyAddedCallbacks());
```

6 changes: 4 additions & 2 deletions async_hooks/async_hooks_executionasyncid.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@

* Returns {number} the `asyncId` of the current execution context. Useful to track
when something calls.
* Returns {number} the `asyncId` of the current execution context. Useful to
track when something calls.

For example:

```js
const async_hooks = require('async_hooks');
console.log(async_hooks.executionAsyncId()); // 1 - bootstrap
fs.open(path, 'r', (err, fd) => {
console.log(async_hooks.executionAsyncId()); // 6 - open()
Expand Down
8 changes: 4 additions & 4 deletions async_hooks/asynchronous_context_example.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Below is another example with additional information about the calls to
The following is an example with additional information about the calls to
`init` between the `before` and `after` calls, specifically what the
callback to `listen()` will look like. The output formatting is slightly more
elaborate to make calling context easier to see.
Expand Down Expand Up @@ -75,10 +75,10 @@ Only using `execution` to graph resource allocation results in the following:
TTYWRAP(6) -> Timeout(4) -> TIMERWRAP(5) -> TickObject(3) -> root(1)
```

The `TCPWRAP` isn't part of this graph; even though it was the reason for
The `TCPWRAP` 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
hostname is actually synchronous, but to maintain a completely asynchronous API
the user's callback is placed in a `process.nextTick()`.
hostname is a *synchronous* operation, but to maintain a completely asynchronous
API the user's callback is placed in a `process.nextTick()`.

The graph only shows *when* a resource was created, not *why*, so to track
the *why* use `triggerAsyncId`.
Expand Down
6 changes: 3 additions & 3 deletions async_hooks/asyncresource_emitafter.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Call all `after` callbacks. If nested calls to `emitBefore()` were made, then
make sure the stack is unwound properly. Otherwise an error will be thrown.

If the user's callback throws an exception then `emitAfter()` will
automatically be called for all `asyncId`s on the stack if the error is handled by
a domain or `'uncaughtException'` handler.
If the user's callback throws an exception, `emitAfter()` will automatically be
called for all `asyncId`s on the stack if the error is handled by a domain or
`'uncaughtException'` handler.

6 changes: 3 additions & 3 deletions async_hooks/asyncresource_emitbefore.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

* Returns {undefined}

Call all `before` callbacks and let them know a new asynchronous execution
context is being entered. If nested calls to `emitBefore()` are made, the stack
of `asyncId`s will be tracked and properly unwound.
Call all `before` callbacks to notify that a new asynchronous execution context
is being entered. If nested calls to `emitBefore()` are made, the stack of
`asyncId`s will be tracked and properly unwound.

4 changes: 4 additions & 0 deletions async_hooks/asyncresource_triggerasyncid.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
* Returns {number} the same `triggerAsyncId` that is passed to the `AsyncResource`
constructor.

[`after` callback]: #async_hooks_after_asyncid
[`before` callback]: #async_hooks_before_asyncid
[`destroy` callback]: #async_hooks_before_asyncid
[`Hook Callbacks`]: #async_hooks_hook_callbacks
[`init` callback]: #async_hooks_init_asyncid_type_triggerasyncid_resource
6 changes: 3 additions & 3 deletions async_hooks/asyncresource_type_triggerasyncid.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

* arguments
* `type` {string} the type of ascyc event
* `triggerAsyncId` {number} the ID of the execution context that created this async
event
* `type` {string} the type of async event
* `triggerAsyncId` {number} the ID of the execution context that created this
async event

Example usage:

Expand Down
7 changes: 4 additions & 3 deletions async_hooks/before_asyncid.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ resource about to execute the callback.
The `before` callback will be called 0 to N times. The `before` callback
will typically be called 0 times if the asynchronous operation was cancelled
or for example if no connections are received by a TCP server. Asynchronous
like the TCP server will typically call the `before` callback multiple times,
while other operations like `fs.open()` will only call it once.
or, for example, if no connections are received by a TCP server. Persistent
asynchronous resources like a TCP server will typically call the `before`
callback multiple times, while other operations like `fs.open()` will only call
it only once.


4 changes: 2 additions & 2 deletions async_hooks/class_asyncresource.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ own resources.

The `init` hook will trigger when an `AsyncResource` is instantiated.

It is important that `before`/`after` calls are unwound
*Note*: It is important that `before`/`after` calls are unwound
in the same order they are called. Otherwise an unrecoverable exception
will occur and node will abort.
will occur and the process will abort.

The following is an overview of the `AsyncResource` API.

Expand Down
15 changes: 8 additions & 7 deletions async_hooks/destroy_asyncid.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@

* `asyncId` {number}

Called after the resource corresponding to `asyncId` is destroyed. It is also called
asynchronously from the embedder API `emitDestroy()`.

*Note:* Some resources depend on GC for cleanup, so if a reference is made to
the `resource` object passed to `init` it's possible that `destroy` is
never called, causing a memory leak in the application. Of course if
the resource doesn't depend on GC then this isn't an issue.
Called after the resource corresponding to `asyncId` is destroyed. It is also
called asynchronously from the embedder API `emitDestroy()`.

*Note:* Some resources depend on garbage collection for cleanup, so if a
reference is made to the `resource` object passed to `init` it is possible that
`destroy` will never be called, causing a memory leak in the application. If
the resource does not depend on garbage collection, then this will not be an
issue.

3 changes: 2 additions & 1 deletion async_hooks/init_asyncid_type_triggerasyncid_resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ require('net').createServer().listen(function() { this.close(); });
clearTimeout(setTimeout(() => {}, 10));
```

Every new resource is assigned a unique ID.
Every new resource is assigned an ID that is unique within the scope of the
current process.

7 changes: 3 additions & 4 deletions async_hooks/javascript_embedder_api.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

Library developers that handle their own I/O, a connection pool, or
callback queues will need to hook into the AsyncWrap API so that all the
appropriate callbacks are called. To accommodate this a JavaScript API is
provided.
Library developers that handle their own asychronous resources performing tasks
like I/O, connection pooling, or managing callback queues may use the `AsyncWrap`
JavaScript API so that all the appropriate callbacks are called.

8 changes: 7 additions & 1 deletion async_hooks/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const eid = async_hooks.executionAsyncId();
const tid = async_hooks.triggerAsyncId();
// Create a new AsyncHook instance. All of these callbacks are optional.
const asyncHook = async_hooks.createHook({ init, before, after, destroy });
const asyncHook =
async_hooks.createHook({ init, before, after, destroy, promiseResolve });
// Allow callbacks of this AsyncHook instance to call. This is not an implicit
// action after running the constructor, and must be explicitly run to begin
Expand Down Expand Up @@ -41,5 +42,10 @@ function after(asyncId) { }
// destroy is called when an AsyncWrap instance is destroyed.
function destroy(asyncId) { }
// promiseResolve is called only for promise resources, when the
// `resolve` function passed to the `Promise` constructor is invoked
// (either directly or through other means of resolving a promise).
function promiseResolve(asyncId) { }
```

Loading

0 comments on commit 5333907

Please sign in to comment.