| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ad793ab commit 56c27c6
35 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,7 +9,7 @@ just as if they were an ordinary Node.js module. They are used primarily to | |||
| 9 | 9 | provide an interface between JavaScript running in Node.js and C/C++ libraries. | |
| 10 | 10 | ||
| 11 | 11 | At the moment, the method for implementing Addons is rather complicated, | |
| 12 | - involving knowledge of several components and APIs : | ||
| 12 | + involving knowledge of several components and APIs: | ||
| 13 | 13 | ||
| 14 | 14 | - V8: the C++ library Node.js currently uses to provide the | |
| 15 | 15 | JavaScript implementation. V8 provides the mechanisms for creating objects, | |
@@ -93,7 +93,7 @@ There is no semi-colon after `NODE_MODULE` as it's not a function (see | |||
| 93 | 93 | `node.h`). | |
| 94 | 94 | ||
| 95 | 95 | The `module_name` must match the filename of the final binary (excluding | |
| 96 | - the .node suffix). | ||
| 96 | + the `.node` suffix). | ||
| 97 | 97 | ||
| 98 | 98 | In the `hello.cc` example, then, the initialization function is `init` and the | |
| 99 | 99 | Addon module name is `addon`. | |
@@ -1085,9 +1085,9 @@ console.log(result); | |||
| 1085 | 1085 | ||
| 1086 | 1086 | ### AtExit hooks | |
| 1087 | 1087 | ||
| 1088 | - An "AtExit" hook is a function that is invoked after the Node.js event loop | ||
| 1088 | + An `AtExit` hook is a function that is invoked after the Node.js event loop | ||
| 1089 | 1089 | has ended but before the JavaScript VM is terminated and Node.js shuts down. | |
| 1090 | - "AtExit" hooks are registered using the `node::AtExit` API. | ||
| 1090 | + `AtExit` hooks are registered using the `node::AtExit` API. | ||
| 1091 | 1091 | ||
| 1092 | 1092 | #### void AtExit(callback, args) | |
| 1093 | 1093 | ||
@@ -1099,12 +1099,12 @@ has ended but before the JavaScript VM is terminated and Node.js shuts down. | |||
| 1099 | 1099 | Registers exit hooks that run after the event loop has ended but before the VM | |
| 1100 | 1100 | is killed. | |
| 1101 | 1101 | ||
| 1102 | - AtExit takes two parameters: a pointer to a callback function to run at exit, | ||
| 1102 | + `AtExit` takes two parameters: a pointer to a callback function to run at exit, | ||
| 1103 | 1103 | and a pointer to untyped context data to be passed to that callback. | |
| 1104 | 1104 | ||
| 1105 | 1105 | Callbacks are run in last-in first-out order. | |
| 1106 | 1106 | ||
| 1107 | - The following `addon.cc` implements AtExit: | ||
| 1107 | + The following `addon.cc` implements `AtExit`: | ||
| 1108 | 1108 | ||
| 1109 | 1109 | ```cpp | |
| 1110 | 1110 | // addon.cc | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -165,10 +165,10 @@ added: v0.1.21 | |||
| 165 | 165 | changes: | |
| 166 | 166 | - version: v9.0.0 | |
| 167 | 167 | pr-url: https://github.com/nodejs/node/pull/15001 | |
| 168 | - description: Error names and messages are now properly compared | ||
| 168 | + description: The `Error` names and messages are now properly compared | ||
| 169 | 169 | - version: v8.0.0 | |
| 170 | 170 | pr-url: https://github.com/nodejs/node/pull/12142 | |
| 171 | - description: Set and Map content is also compared | ||
| 171 | + description: The `Set` and `Map` content is also compared | ||
| 172 | 172 | - version: v6.4.0, v4.7.1 | |
| 173 | 173 | pr-url: https://github.com/nodejs/node/pull/8002 | |
| 174 | 174 | description: Typed array slices are handled correctly now. | |
@@ -208,7 +208,7 @@ the [`RegExp`][] object are not enumerable: | |||
| 208 | 208 | assert.deepEqual(/a/gi, new Date()); | |
| 209 | 209 | ``` | |
| 210 | 210 | ||
| 211 | - An exception is made for [`Map`][] and [`Set`][]. Maps and Sets have their | ||
| 211 | + An exception is made for [`Map`][] and [`Set`][]. `Map`s and `Set`s have their | ||
| 212 | 212 | contained items compared too, as expected. | |
| 213 | 213 | ||
| 214 | 214 | "Deep" equality means that the enumerable "own" properties of child objects | |
@@ -264,15 +264,15 @@ changes: | |||
| 264 | 264 | description: Enumerable symbol properties are now compared. | |
| 265 | 265 | - version: v9.0.0 | |
| 266 | 266 | pr-url: https://github.com/nodejs/node/pull/15036 | |
| 267 | - description: NaN is now compared using the | ||
| 267 | + description: The `NaN` is now compared using the | ||
| 268 | 268 | [SameValueZero](https://tc39.github.io/ecma262/#sec-samevaluezero) | |
| 269 | 269 | comparison. | |
| 270 | 270 | - version: v8.5.0 | |
| 271 | 271 | pr-url: https://github.com/nodejs/node/pull/15001 | |
| 272 | - description: Error names and messages are now properly compared | ||
| 272 | + description: The `Error` names and messages are now properly compared | ||
| 273 | 273 | - version: v8.0.0 | |
| 274 | 274 | pr-url: https://github.com/nodejs/node/pull/12142 | |
| 275 | - description: Set and Map content is also compared | ||
| 275 | + description: The `Set` and `Map` content is also compared | ||
| 276 | 276 | - version: v6.4.0, v4.7.1 | |
| 277 | 277 | pr-url: https://github.com/nodejs/node/pull/8002 | |
| 278 | 278 | description: Typed array slices are handled correctly now. | |
@@ -303,8 +303,8 @@ are recursively evaluated also by the following rules. | |||
| 303 | 303 | enumerable properties. | |
| 304 | 304 | * Enumerable own [`Symbol`][] properties are compared as well. | |
| 305 | 305 | * [Object wrappers][] are compared both as objects and unwrapped values. | |
| 306 | - * Object properties are compared unordered. | ||
| 307 | - * Map keys and Set items are compared unordered. | ||
| 306 | + * `Object` properties are compared unordered. | ||
| 307 | + * `Map` keys and `Set` items are compared unordered. | ||
| 308 | 308 | * Recursion stops when both sides differ or both sides encounter a circular | |
| 309 | 309 | reference. | |
| 310 | 310 | * [`WeakMap`][] and [`WeakSet`][] comparison does not rely on their values. See | |
@@ -413,10 +413,10 @@ function and awaits the returned promise to complete. It will then check that | |||
| 413 | 413 | the promise is not rejected. | |
| 414 | 414 | ||
| 415 | 415 | If `block` is a function and it throws an error synchronously, | |
| 416 | - `assert.doesNotReject()` will return a rejected Promise with that error. If the | ||
| 417 | - function does not return a promise, `assert.doesNotReject()` will return a | ||
| 418 | - rejected Promise with an [`ERR_INVALID_RETURN_VALUE`][] error. In both cases the | ||
| 419 | - error handler is skipped. | ||
| 416 | + `assert.doesNotReject()` will return a rejected `Promise` with that error. If | ||
| 417 | + the function does not return a promise, `assert.doesNotReject()` will return a | ||
| 418 | + rejected `Promise` with an [`ERR_INVALID_RETURN_VALUE`][] error. In both cases | ||
| 419 | + the error handler is skipped. | ||
| 420 | 420 | ||
| 421 | 421 | Please note: Using `assert.doesNotReject()` is actually not useful because there | |
| 422 | 422 | is little benefit by catching a rejection and then rejecting it again. Instead, | |
@@ -494,7 +494,7 @@ assert.doesNotThrow( | |||
| 494 | 494 | ``` | |
| 495 | 495 | ||
| 496 | 496 | However, the following will result in an `AssertionError` with the message | |
| 497 | - 'Got unwanted exception (TypeError)..': | ||
| 497 | + 'Got unwanted exception...': | ||
| 498 | 498 | ||
| 499 | 499 | <!-- eslint-disable no-restricted-syntax --> | |
| 500 | 500 | ```js | |
@@ -519,7 +519,7 @@ assert.doesNotThrow( | |||
| 519 | 519 | /Wrong value/, | |
| 520 | 520 | 'Whoops' | |
| 521 | 521 | ); | |
| 522 | - // Throws: AssertionError: Got unwanted exception (TypeError). Whoops | ||
| 522 | + // Throws: AssertionError: Got unwanted exception: Whoops | ||
| 523 | 523 | ``` | |
| 524 | 524 | ||
| 525 | 525 | ## assert.equal(actual, expected[, message]) | |
@@ -656,7 +656,7 @@ changes: | |||
| 656 | 656 | - version: v10.0.0 | |
| 657 | 657 | pr-url: https://github.com/nodejs/node/pull/18247 | |
| 658 | 658 | description: Instead of throwing the original error it is now wrapped into | |
| 659 | - a AssertionError that contains the full stack trace. | ||
| 659 | + an `AssertionError` that contains the full stack trace. | ||
| 660 | 660 | - version: v10.0.0 | |
| 661 | 661 | pr-url: https://github.com/nodejs/node/pull/18247 | |
| 662 | 662 | description: Value may now only be `undefined` or `null`. Before any truthy | |
@@ -701,10 +701,10 @@ added: v0.1.21 | |||
| 701 | 701 | changes: | |
| 702 | 702 | - version: v9.0.0 | |
| 703 | 703 | pr-url: https://github.com/nodejs/node/pull/15001 | |
| 704 | - description: Error names and messages are now properly compared | ||
| 704 | + description: The `Error` names and messages are now properly compared | ||
| 705 | 705 | - version: v8.0.0 | |
| 706 | 706 | pr-url: https://github.com/nodejs/node/pull/12142 | |
| 707 | - description: Set and Map content is also compared | ||
| 707 | + description: The `Set` and `Map` content is also compared | ||
| 708 | 708 | - version: v6.4.0, v4.7.1 | |
| 709 | 709 | pr-url: https://github.com/nodejs/node/pull/8002 | |
| 710 | 710 | description: Typed array slices are handled correctly now. | |
@@ -774,18 +774,18 @@ added: v1.2.0 | |||
| 774 | 774 | changes: | |
| 775 | 775 | - version: v9.0.0 | |
| 776 | 776 | pr-url: https://github.com/nodejs/node/pull/15398 | |
| 777 | - description: -0 and +0 are not considered equal anymore. | ||
| 777 | + description: The `-0` and `+0` are not considered equal anymore. | ||
| 778 | 778 | - version: v9.0.0 | |
| 779 | 779 | pr-url: https://github.com/nodejs/node/pull/15036 | |
| 780 | - description: NaN is now compared using the | ||
| 780 | + description: The `NaN` is now compared using the | ||
| 781 | 781 | [SameValueZero](https://tc39.github.io/ecma262/#sec-samevaluezero) | |
| 782 | 782 | comparison. | |
| 783 | 783 | - version: v9.0.0 | |
| 784 | 784 | pr-url: https://github.com/nodejs/node/pull/15001 | |
| 785 | - description: Error names and messages are now properly compared | ||
| 785 | + description: The `Error` names and messages are now properly compared | ||
| 786 | 786 | - version: v8.0.0 | |
| 787 | 787 | pr-url: https://github.com/nodejs/node/pull/12142 | |
| 788 | - description: Set and Map content is also compared | ||
| 788 | + description: The `Set` and `Map` content is also compared | ||
| 789 | 789 | - version: v6.4.0, v4.7.1 | |
| 790 | 790 | pr-url: https://github.com/nodejs/node/pull/8002 | |
| 791 | 791 | description: Typed array slices are handled correctly now. | |
@@ -893,7 +893,8 @@ added: v0.1.21 | |||
| 893 | 893 | changes: | |
| 894 | 894 | - version: v10.0.0 | |
| 895 | 895 | pr-url: https://github.com/nodejs/node/pull/18319 | |
| 896 | - description: assert.ok() (no arguments) will now use a predefined error msg. | ||
| 896 | + description: The `assert.ok()` (no arguments) will now use a predefined | ||
| 897 | + error message. | ||
| 897 | 898 | --> | |
| 898 | 899 | * `value` {any} | |
| 899 | 900 | * `message` {any} | |
@@ -907,7 +908,7 @@ parameter is `undefined`, a default error message is assigned. If the `message` | |||
| 907 | 908 | parameter is an instance of an [`Error`][] then it will be thrown instead of the | |
| 908 | 909 | `AssertionError`. | |
| 909 | 910 | If no arguments are passed in at all `message` will be set to the string: | |
| 910 | - "No value argument passed to assert.ok". | ||
| 911 | + ``'No value argument passed to `assert.ok()`'``. | ||
| 911 | 912 | ||
| 912 | 913 | Be aware that in the `repl` the error message will be different to the one | |
| 913 | 914 | thrown in a file! See below for further details. | |
@@ -966,9 +967,9 @@ function and awaits the returned promise to complete. It will then check that | |||
| 966 | 967 | the promise is rejected. | |
| 967 | 968 | ||
| 968 | 969 | If `block` is a function and it throws an error synchronously, | |
| 969 | - `assert.rejects()` will return a rejected Promise with that error. If the | ||
| 970 | + `assert.rejects()` will return a rejected `Promise` with that error. If the | ||
| 970 | 971 | function does not return a promise, `assert.rejects()` will return a rejected | |
| 971 | - Promise with an [`ERR_INVALID_RETURN_VALUE`][] error. In both cases the error | ||
| 972 | + `Promise` with an [`ERR_INVALID_RETURN_VALUE`][] error. In both cases the error | ||
| 972 | 973 | handler is skipped. | |
| 973 | 974 | ||
| 974 | 975 | Besides the async nature to await the completion behaves identically to | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,8 +17,8 @@ const async_hooks = require('async_hooks'); | |||
| 17 | 17 | An asynchronous resource represents an object with an associated callback. | |
| 18 | 18 | This callback may be called multiple times, for example, the `'connection'` | |
| 19 | 19 | event in `net.createServer()`, or just a single time like in `fs.open()`. | |
| 20 | - A resource can also be closed before the callback is called. AsyncHook does not | ||
| 21 | - explicitly distinguish between these different cases but will represent them | ||
| 20 | + A resource can also be closed before the callback is called. `AsyncHook` does | ||
| 21 | + not explicitly distinguish between these different cases but will represent them | ||
| 22 | 22 | as the abstract concept that is a resource. | |
| 23 | 23 | ||
| 24 | 24 | ## Public API | |
@@ -188,7 +188,7 @@ const hook = async_hooks.createHook(callbacks).enable(); | |||
| 188 | 188 | * Returns: {AsyncHook} A reference to `asyncHook`. | |
| 189 | 189 | ||
| 190 | 190 | Disable the callbacks for a given `AsyncHook` instance from the global pool of | |
| 191 | - AsyncHook callbacks to be executed. Once a hook has been disabled it will not | ||
| 191 | + `AsyncHook` callbacks to be executed. Once a hook has been disabled it will not | ||
| 192 | 192 | be called again until enabled. | |
| 193 | 193 | ||
| 194 | 194 | For API consistency `disable()` also returns the `AsyncHook` instance. | |
@@ -299,10 +299,10 @@ and document their own resource objects. For example, such a resource object | |||
| 299 | 299 | could contain the SQL query being executed. | |
| 300 | 300 | ||
| 301 | 301 | In the case of Promises, the `resource` object will have `promise` property | |
| 302 | - that refers to the Promise that is being initialized, and a `isChainedPromise` | ||
| 303 | - property, set to `true` if the promise has a parent promise, and `false` | ||
| 304 | - otherwise. For example, in the case of `b = a.then(handler)`, `a` is considered | ||
| 305 | - a parent Promise of `b`. Here, `b` is considered a chained promise. | ||
| 302 | + that refers to the `Promise` that is being initialized, and an | ||
| 303 | + `isChainedPromise` property, set to `true` if the promise has a parent promise, | ||
| 304 | + and `false` otherwise. For example, in the case of `b = a.then(handler)`, `a` is | ||
| 305 | + considered a parent `Promise` of `b`. Here, `b` is considered a chained promise. | ||
| 306 | 306 | ||
| 307 | 307 | In some cases the resource object is reused for performance reasons, it is | |
| 308 | 308 | thus not safe to use it as a key in a `WeakMap` or add properties to it. | |
@@ -466,7 +466,7 @@ added: v8.1.0 | |||
| 466 | 466 | changes: | |
| 467 | 467 | - version: v8.2.0 | |
| 468 | 468 | pr-url: https://github.com/nodejs/node/pull/13490 | |
| 469 | - description: Renamed from currentId | ||
| 469 | + description: Renamed from `currentId` | ||
| 470 | 470 | --> | |
| 471 | 471 | ||
| 472 | 472 | * Returns: {number} The `asyncId` of the current execution context. Useful to | |
@@ -498,7 +498,7 @@ const server = net.createServer(function onConnection(conn) { | |||
| 498 | 498 | }); | |
| 499 | 499 | ``` | |
| 500 | 500 | ||
| 501 | - Note that promise contexts may not get precise executionAsyncIds by default. | ||
| 501 | + Note that promise contexts may not get precise `executionAsyncIds` by default. | ||
| 502 | 502 | See the section on [promise execution tracking][]. | |
| 503 | 503 | ||
| 504 | 504 | #### async_hooks.triggerAsyncId() | |
@@ -521,12 +521,12 @@ const server = net.createServer((conn) => { | |||
| 521 | 521 | }); | |
| 522 | 522 | ``` | |
| 523 | 523 | ||
| 524 | - Note that promise contexts may not get valid triggerAsyncIds by default. See | ||
| 524 | + Note that promise contexts may not get valid `triggerAsyncId`s by default. See | ||
| 525 | 525 | the section on [promise execution tracking][]. | |
| 526 | 526 | ||
| 527 | 527 | ## Promise execution tracking | |
| 528 | 528 | ||
| 529 | - By default, promise executions are not assigned asyncIds due to the relatively | ||
| 529 | + By default, promise executions are not assigned `asyncId`s due to the relatively | ||
| 530 | 530 | expensive nature of the [promise introspection API][PromiseHooks] provided by | |
| 531 | 531 | V8. This means that programs using promises or `async`/`await` will not get | |
| 532 | 532 | correct execution and trigger ids for promise callback contexts by default. | |
@@ -542,10 +542,10 @@ Promise.resolve(1729).then(() => { | |||
| 542 | 542 | // eid 1 tid 0 | |
| 543 | 543 | ``` | |
| 544 | 544 | ||
| 545 | - Observe that the `then` callback claims to have executed in the context of the | ||
| 545 | + Observe that the `then()` callback claims to have executed in the context of the | ||
| 546 | 546 | outer scope even though there was an asynchronous hop involved. Also note that | |
| 547 | - the triggerAsyncId value is 0, which means that we are missing context about the | ||
| 548 | - resource that caused (triggered) the `then` callback to be executed. | ||
| 547 | + the `triggerAsyncId` value is `0`, which means that we are missing context about | ||
| 548 | + the resource that caused (triggered) the `then()` callback to be executed. | ||
| 549 | 549 | ||
| 550 | 550 | Installing async hooks via `async_hooks.createHook` enables promise execution | |
| 551 | 551 | tracking. Example: | |
@@ -562,15 +562,16 @@ Promise.resolve(1729).then(() => { | |||
| 562 | 562 | ||
| 563 | 563 | In this example, adding any actual hook function enabled the tracking of | |
| 564 | 564 | promises. There are two promises in the example above; the promise created by | |
| 565 | - `Promise.resolve()` and the promise returned by the call to `then`. In the | ||
| 566 | - example above, the first promise got the asyncId 6 and the latter got asyncId 7. | ||
| 567 | - During the execution of the `then` callback, we are executing in the context of | ||
| 568 | - promise with asyncId 7. This promise was triggered by async resource 6. | ||
| 565 | + `Promise.resolve()` and the promise returned by the call to `then()`. In the | ||
| 566 | + example above, the first promise got the `asyncId` `6` and the latter got | ||
| 567 | + `asyncId` `7`. During the execution of the `then()` callback, we are executing | ||
| 568 | + in the context of promise with `asyncId` `7`. This promise was triggered by | ||
| 569 | + async resource `6`. | ||
| 569 | 570 | ||
| 570 | 571 | Another subtlety with promises is that `before` and `after` callbacks are run | |
| 571 | - only on chained promises. That means promises not created by `then`/`catch` will | ||
| 572 | - not have the `before` and `after` callbacks fired on them. For more details see | ||
| 573 | - the details of the V8 [PromiseHooks][] API. | ||
| 572 | + only on chained promises. That means promises not created by `then()`/`catch()` | ||
| 573 | + will not have the `before` and `after` callbacks fired on them. For more details | ||
| 574 | + see the details of the V8 [PromiseHooks][] API. | ||
| 574 | 575 | ||
| 575 | 576 | ## JavaScript Embedder API | |
| 576 | 577 | ||
@@ -632,8 +633,9 @@ asyncResource.emitAfter(); | |||
| 632 | 633 | async event. **Default:** `executionAsyncId()`. | |
| 633 | 634 | * `requireManualDestroy` {boolean} Disables automatic `emitDestroy` when the | |
| 634 | 635 | object is garbage collected. This usually does not need to be set (even if | |
| 635 | - `emitDestroy` is called manually), unless the resource's asyncId is retrieved | ||
| 636 | - and the sensitive API's `emitDestroy` is called with it. **Default:** `false`. | ||
| 636 | + `emitDestroy` is called manually), unless the resource's `asyncId` is | ||
| 637 | + retrieved and the sensitive API's `emitDestroy` is called with it. | ||
| 638 | + **Default:** `false`. | ||
| 637 | 639 | ||
| 638 | 640 | Example usage: | |
| 639 | 641 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments