Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/nodejs/node into psj-dev
Browse files Browse the repository at this point in the history
I added a testcase about executionAsyncResource with Http Agent.

Refs: https://github.com/nodejs/node/blob/master/test/async-hooks/test-async-exec-resource-http.js
Signed-off-by: psj-tar-gz <[email protected]>
  • Loading branch information
psj-tar-gz committed Sep 4, 2020
2 parents 4de4483 + 6e8701b commit 54c958c
Show file tree
Hide file tree
Showing 144 changed files with 6,789 additions and 605 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@

/doc/api/modules.md @nodejs/modules
/doc/api/esm.md @nodejs/modules
/doc/api/module.md @nodejs/modules
/doc/api/packages.md @nodejs/modules
/lib/module.js @nodejs/modules
/lib/internal/modules/* @nodejs/modules
/lib/internal/bootstrap/loaders.js @nodejs/modules
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/close-stalled.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Close stalled issues and PRs
on:
schedule:
- cron: "0 0 * * *"

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
days-before-close: 30
stale-pr-label: stalled
stale-issue-label: stalled
close-issue-message: Closing this because it has stalled. Feel free to reopen if this issue is still relevant, or to ping the collaborator who labelled it stalled if you have any questions.
close-pr-message: Closing this because it has stalled. Feel free to reopen if this PR is still relevant, or to ping the collaborator who labelled it stalled if you have any questions.
# deactivates automatic removal of stalled label if issue gets any activity
remove-stale-when-updated: false
# deactivates automatic stale labelling as we prefer to do that manually
days-before-stale: -1
20 changes: 20 additions & 0 deletions .github/workflows/comment-stalled.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Comment on issues and PRs when labelled stalled
on:
issues:
types: [labeled]
pull_request_target:
types: [labeled]

jobs:
staleComment:
runs-on: ubuntu-latest
steps:
- name: Post comment
if: github.event.label.name == 'stalled'
env:
COMMENTS_URL: ${{ github.event.issue.comments_url || github.event.pull_request.comments_url }}
run: |
curl -X POST $COMMENTS_URL \
-H "Content-Type: application/json" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
--data '{ "body": "This issue/PR was marked as stalled, it will be automatically closed in 30 days. If it should remain open, please leave a comment explaining why it should remain open." }'
4 changes: 1 addition & 3 deletions .github/workflows/commit-queue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get install jq -y
# TODO(mmarchini): install from npm after next ncu release is out
npm install -g 'https://github.com/mmarchini/node-core-utils#commit-queue-branch'
# npm install -g node-core-utils
npm install -g node-core-utils@latest
- name: Set variables
run: |
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/require-allow-edits.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Require “Allow Edits”

on: [pull_request]

jobs:
_:
name: "Require “Allow Edits”"

runs-on: ubuntu-latest

steps:
- uses: ljharb/require-allow-edits@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions benchmark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ directory, see [the guide on benchmarks](../doc/guides/writing-and-running-bench
| module | Benchmarks for the `module` subsystem. |
| net | Benchmarks for the `net` subsystem. |
| path | Benchmarks for the `path` subsystem. |
| perf_hooks | Benchmarks for the `perf_hooks` subsystem. |
| process | Benchmarks for the `process` subsystem. |
| querystring | Benchmarks for the `querystring` subsystem. |
| streams | Benchmarks for the `streams` subsystem. |
Expand Down
64 changes: 64 additions & 0 deletions benchmark/perf_hooks/bench-eventlooputil.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
'use strict';

const common = require('../common.js');
const assert = require('assert').ok;
const { performance } = require('perf_hooks');
const { nodeTiming, eventLoopUtilization } = performance;

const bench = common.createBenchmark(main, {
n: [1e6],
method: [
'idleTime',
'ELU_simple',
'ELU_passed',
],
});

function main({ method, n }) {
switch (method) {
case 'idleTime':
benchIdleTime(n);
break;
case 'ELU_simple':
benchELUSimple(n);
break;
case 'ELU_passed':
benchELUPassed(n);
break;
default:
throw new Error(`Unsupported method ${method}`);
}
}

function benchIdleTime(n) {
bench.start();
for (let i = 0; i < n; i++)
nodeTiming.idleTime;
bench.end(n);
}

function benchELUSimple(n) {
// Need to put this in setImmediate or will always return 0.
setImmediate(() => {
const elu = eventLoopUtilization();
assert(elu.active + elu.idle > 0);

bench.start();
for (let i = 0; i < n; i++)
eventLoopUtilization();
bench.end(n);
});
}

function benchELUPassed(n) {
// Need to put this in setImmediate or will always return 0.
setImmediate(() => {
let elu = eventLoopUtilization();
assert(elu.active + elu.idle > 0);

bench.start();
for (let i = 0; i < n; i++)
elu = eventLoopUtilization(elu);
bench.end(n);
});
}
22 changes: 19 additions & 3 deletions doc/api/buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ string into a `Buffer` as decoding.
tabs, and new lines contained within the base64-encoded string are ignored.

* `'hex'`: Encode each byte as two hexadecimal characters. Data truncation
may occur when decoding string that do exclusively contain valid hexadecimal
may occur when decoding strings that do exclusively contain valid hexadecimal
characters. See below for an example.

The following legacy character encodings are also supported:

* `'ascii'`: For 7-bit [ASCII][] data only. When encoding a string into a
`Buffer`, this is equivalent to using `'latin1'`. When decoding a `Buffer`
into a string, using encoding this will additionally unset the highest bit of
into a string, using this encoding will additionally unset the highest bit of
each byte before decoding as `'latin1'`.
Generally, there should be no reason to use this encoding, as `'utf8'`
(or, if the data is known to always be ASCII-only, `'latin1'`) will be a
Expand Down Expand Up @@ -176,7 +176,7 @@ In particular:
There are two ways to create new [`TypedArray`][] instances from a `Buffer`:

* Passing a `Buffer` to a [`TypedArray`][] constructor will copy the `Buffer`s
contents, interpreted an array array of integers, and not as a byte sequence
contents, interpreted as an array of integers, and not as a byte sequence
of the target type.

```js
Expand Down Expand Up @@ -1379,6 +1379,10 @@ values.
added:
- v12.0.0
- v10.20.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/34960
description: This function is also available as `buf.readBigUint64BE()`.
-->

* `offset` {integer} Number of bytes to skip before starting to read. Must
Expand All @@ -1400,6 +1404,10 @@ console.log(buf.readBigUInt64BE(0));
added:
- v12.0.0
- v10.20.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/34960
description: This function is also available as `buf.readBigUint64LE()`.
-->

* `offset` {integer} Number of bytes to skip before starting to read. Must
Expand Down Expand Up @@ -2304,6 +2312,10 @@ console.log(buf);
added:
- v12.0.0
- v10.20.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/34960
description: This function is also available as `buf.writeBigUint64BE()`.
-->

* `value` {bigint} Number to be written to `buf`.
Expand All @@ -2327,6 +2339,10 @@ console.log(buf);
added:
- v12.0.0
- v10.20.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/34960
description: This function is also available as `buf.writeBigUint64LE()`.
-->

* `value` {bigint} Number to be written to `buf`.
Expand Down
39 changes: 39 additions & 0 deletions doc/api/crypto.md
Original file line number Diff line number Diff line change
Expand Up @@ -2801,6 +2801,44 @@ threadpool request. To minimize threadpool task length variation, partition
large `randomFill` requests when doing so as part of fulfilling a client
request.

### `crypto.randomInt([min, ]max[, callback])`
<!-- YAML
added: REPLACEME
-->

* `min` {integer} Start of random range (inclusive). **Default**: `0`.
* `max` {integer} End of random range (exclusive).
* `callback` {Function} `function(err, n) {}`.

Return a random integer `n` such that `min <= n < max`. This
implementation avoids [modulo bias][].

The range (`max - min`) must be less than `2^48`. `min` and `max` must
be safe integers.

If the `callback` function is not provided, the random integer is
generated synchronously.

```js
// Asynchronous
crypto.randomInt(3, (err, n) => {
if (err) throw err;
console.log(`Random number chosen from (0, 1, 2): ${n}`);
});
```

```js
// Synchronous
const n = crypto.randomInt(3);
console.log(`Random number chosen from (0, 1, 2): ${n}`);
```

```js
// With `min` argument
const n = crypto.randomInt(1, 7);
console.log(`The dice rolled: ${n}`);
```

### `crypto.scrypt(password, salt, keylen[, options], callback)`
<!-- YAML
added: v10.5.0
Expand Down Expand Up @@ -3573,6 +3611,7 @@ See the [list of SSL OP Flags][] for details.
[NIST SP 800-131A]: https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-131Ar1.pdf
[NIST SP 800-132]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-132.pdf
[NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
[modulo bias]: https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#Modulo_bias
[Nonce-Disrespecting Adversaries]: https://github.com/nonce-disrespect/nonce-disrespect
[OpenSSL's SPKAC implementation]: https://www.openssl.org/docs/man1.1.0/apps/openssl-spkac.html
[RFC 1421]: https://www.rfc-editor.org/rfc/rfc1421.txt
Expand Down
2 changes: 1 addition & 1 deletion doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -2858,7 +2858,7 @@ The [`crypto.Certificate()` constructor][] is deprecated. Use
[`response.socket`]: http.html#http_response_socket
[`response.connection`]: http.html#http_response_connection
[`response.end()`]: http.html#http_response_end_data_encoding_callback
[`response.finished`]: #http_response_finished
[`response.finished`]: http.html#http_response_finished
[`response.writableFinished`]: #http_response_writablefinished
[`response.writableEnded`]: #http_response_writableended
[`script.createCachedData()`]: vm.html#vm_script_createcacheddata
Expand Down
2 changes: 1 addition & 1 deletion doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ _conditions_)
> 1. Otherwise, throw an _Invalid Package Target_ error.
> 1. If _target_ split on _"/"_ or _"\\"_ contains any _"."_, _".."_ or
> _"node_modules"_ segments after the first segment, throw an
> _Invalid Module Specifier_ error.
> _Invalid Package Target_ error.
> 1. Let _resolvedTarget_ be the URL resolution of the concatenation of
> _packageURL_ and _target_.
> 1. Assert: _resolvedTarget_ is contained in _packageURL_.
Expand Down
61 changes: 59 additions & 2 deletions doc/api/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ class MyClass extends EventEmitter {
}
```

## `events.once(emitter, name)`
## `events.once(emitter, name[, options])`
<!-- YAML
added:
- v11.13.0
Expand All @@ -834,6 +834,8 @@ added:

* `emitter` {EventEmitter}
* `name` {string}
* `options` {Object}
* `signal` {AbortSignal} Can be used to cancel waiting for the event.
* Returns: {Promise}

Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given
Expand Down Expand Up @@ -892,6 +894,32 @@ ee.emit('error', new Error('boom'));
// Prints: ok boom
```

An {AbortSignal} can be used to cancel waiting for the event:

```js
const { EventEmitter, once } = require('events');

const ee = new EventEmitter();
const ac = new AbortController();

async function foo(emitter, event, signal) {
try {
await once(emitter, event, { signal });
console.log('event emitted!');
} catch (error) {
if (error.name === 'AbortError') {
console.error('Waiting for the event was canceled!');
} else {
console.error('There was an error', error.message);
}
}
}

foo(ee, 'foo', ac.signal);
ac.abort(); // Abort waiting for the event
ee.emit('foo'); // Prints: Waiting for the event was canceled!
```

### Awaiting multiple events emitted on `process.nextTick()`

There is an edge case worth noting when using the `events.once()` function
Expand Down Expand Up @@ -972,7 +1000,7 @@ Value: `Symbol.for('nodejs.rejection')`

See how to write a custom [rejection handler][rejection].

## `events.on(emitter, eventName)`
## `events.on(emitter, eventName[, options])`
<!-- YAML
added:
- v13.6.0
Expand All @@ -981,6 +1009,8 @@ added:

* `emitter` {EventEmitter}
* `eventName` {string|symbol} The name of the event being listened for
* `options` {Object}
* `signal` {AbortSignal} Can be used to cancel awaiting events.
* Returns: {AsyncIterator} that iterates `eventName` events emitted by the `emitter`

```js
Expand Down Expand Up @@ -1010,6 +1040,33 @@ if the `EventEmitter` emits `'error'`. It removes all listeners when
exiting the loop. The `value` returned by each iteration is an array
composed of the emitted event arguments.

An {AbortSignal} can be used to cancel waiting on events:

```js
const { on, EventEmitter } = require('events');
const ac = new AbortController();

(async () => {
const ee = new EventEmitter();

// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});

for await (const event of on(ee, 'foo', { signal: ac.signal })) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here
})();

process.nextTick(() => ac.abort());
```

## `EventTarget` and `Event` API
<!-- YAML
added: v14.5.0
Expand Down
Loading

0 comments on commit 54c958c

Please sign in to comment.