Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
meta: merge node/master into node-chakracore/master
Browse files Browse the repository at this point in the history
Merge b41ed29 as of 2018-03-23
This commit was automatically generated. For any problems, please contact jackhorton

Reviewed-By: Kyle Farnung <kfarnung@microsoft.com>
  • Loading branch information
chakrabot committed Mar 24, 2018
2 parents 7cfa11f + b41ed29 commit 39281f6
Show file tree
Hide file tree
Showing 34 changed files with 297 additions and 182 deletions.
55 changes: 55 additions & 0 deletions benchmark/streams/creation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
'use strict';
const common = require('../common.js');
const Duplex = require('stream').Duplex;
const Readable = require('stream').Readable;
const Transform = require('stream').Transform;
const Writable = require('stream').Writable;

const bench = common.createBenchmark(main, {
n: [50e6],
kind: ['duplex', 'readable', 'transform', 'writable']
});

function main({ n, kind }) {
var i = 0;
switch (kind) {
case 'duplex':
new Duplex({});
new Duplex();

bench.start();
for (; i < n; ++i)
new Duplex();
bench.end(n);
break;
case 'readable':
new Readable({});
new Readable();

bench.start();
for (; i < n; ++i)
new Readable();
bench.end(n);
break;
case 'writable':
new Writable({});
new Writable();

bench.start();
for (; i < n; ++i)
new Writable();
bench.end(n);
break;
case 'transform':
new Transform({});
new Transform();

bench.start();
for (; i < n; ++i)
new Transform();
bench.end(n);
break;
default:
throw new Error('Invalid kind');
}
}
21 changes: 0 additions & 21 deletions benchmark/streams/transform-creation.js

This file was deleted.

22 changes: 15 additions & 7 deletions doc/api/child_process.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@ ls.on('close', (code) => {
```

By default, pipes for `stdin`, `stdout`, and `stderr` are established between
the parent Node.js process and the spawned child. It is possible to stream data
through these pipes in a non-blocking way. *Note, however, that some programs
use line-buffered I/O internally. While that does not affect Node.js, it can
mean that data sent to the child process may not be immediately consumed.*
the parent Node.js process and the spawned child. These pipes have
limited (and platform-specific) capacity. If the child process writes to
stdout in excess of that limit without the output being captured, the child
process will block waiting for the pipe buffer to accept more data. This is
identical to the behavior of pipes in the shell. Use the `{ stdio: 'ignore' }`
option if the output will not be consumed.
It is possible to stream data through these pipes in a non-blocking way. Note,
however, that some programs use line-buffered I/O internally. While that does
not affect Node.js, it can mean that data sent to the child process may not be
immediately consumed.

The [`child_process.spawn()`][] method spawns the child process asynchronously,
without blocking the Node.js event loop. The [`child_process.spawnSync()`][]
Expand Down Expand Up @@ -223,8 +229,9 @@ the existing process and uses a shell to execute the command.

If this method is invoked as its [`util.promisify()`][]ed version, it returns
a Promise for an object with `stdout` and `stderr` properties. In case of an
error, a rejected promise is returned, with the same `error` object given in the
callback, but with an additional two properties `stdout` and `stderr`.
error (including any error resulting in an exit code other than 0), a rejected
promise is returned, with the same `error` object given in the callback, but
with an additional two properties `stdout` and `stderr`.

```js
const util = require('util');
Expand Down Expand Up @@ -301,7 +308,8 @@ encoding, `Buffer` objects will be passed to the callback instead.

If this method is invoked as its [`util.promisify()`][]ed version, it returns
a Promise for an object with `stdout` and `stderr` properties. In case of an
error, a rejected promise is returned, with the same `error` object given in the
error (including any error resulting in an exit code other than 0), a rejected
promise is returned, with the same `error` object given in the
callback, but with an additional two properties `stdout` and `stderr`.

```js
Expand Down
8 changes: 4 additions & 4 deletions doc/api/http2.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ Immediately terminates the `Http2Session` and the associated `net.Socket` or
`tls.TLSSocket`.

Once destroyed, the `Http2Session` will emit the `'close'` event. If `error`
is not undefined, an `'error'` event will be emitted immediately after the
is not undefined, an `'error'` event will be emitted immediately before the
`'close'` event.

If there are any remaining open `Http2Streams` associated with the
Expand Down Expand Up @@ -816,9 +816,9 @@ added: v8.4.0
The `'close'` event is emitted when the `Http2Stream` is destroyed. Once
this event is emitted, the `Http2Stream` instance is no longer usable.

The listener callback is passed a single argument specifying the HTTP/2 error
code specified when closing the stream. If the code is any value other than
`NGHTTP2_NO_ERROR` (`0`), an `'error'` event will also be emitted.
The HTTP/2 error code used when closing the stream can be retrieved using
the `http2stream.rstCode` property. If the code is any value other than
`NGHTTP2_NO_ERROR` (`0`), an `'error'` event will have also been emitted.

#### Event: 'error'
<!-- YAML
Expand Down
22 changes: 21 additions & 1 deletion doc/api/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,21 @@ tarball.
- `'Argon'` for the 4.x LTS line beginning with 4.2.0.
- `'Boron'` for the 6.x LTS line beginning with 6.9.0.
- `'Carbon'` for the 8.x LTS line beginning with 8.9.1.
* `majorVersion` {number} The major version of Node.js.
* `minorVersion` {number} The minor version of Node.js.
* `patchVersion` {number} The patch version of Node.js.
* `prereleaseTag` {string} The SemVer pre-release tag for Node.js.
* `computedVersion` {number} A number representing the current version, created
using the following method:
`(majorVersion << 16) + (minorVersion << 8) + patchVersion`
* `compareVersion` {function} Perform a SemVer comparison to the release
version.
* `major`
* `minor`
* `patch`
* Returns: {number} `-1` if the given version is lower than the release
version, `0` if the given version matches the process version, and `1`
if the given version is greater than the release version.

<!-- eslint-skip -->
```js
Expand All @@ -1511,7 +1526,12 @@ tarball.
lts: 'Argon',
sourceUrl: 'https://nodejs.org/download/release/v4.4.5/node-v4.4.5.tar.gz',
headersUrl: 'https://nodejs.org/download/release/v4.4.5/node-v4.4.5-headers.tar.gz',
libUrl: 'https://nodejs.org/download/release/v4.4.5/win-x64/node.lib'
libUrl: 'https://nodejs.org/download/release/v4.4.5/win-x64/node.lib',
majorVersion: 4,
minorVersion: 4,
patchVersion: 5,
prereleaseTag: '',
computedVersion: 263173,
}
```

Expand Down
11 changes: 8 additions & 3 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,16 @@ function prependListener(emitter, event, fn) {
emitter._events[event] = [fn, emitter._events[event]];
}

function ReadableState(options, stream) {
function ReadableState(options, stream, isDuplex) {
options = options || {};

// Duplex streams are both readable and writable, but share
// the same options object.
// However, some cases require setting options to different
// values for the readable and the writable sides of the duplex stream.
// These options can be provided separately as readableXXX and writableXXX.
var isDuplex = stream instanceof Stream.Duplex;
if (typeof isDuplex !== 'boolean')
isDuplex = stream instanceof Stream.Duplex;

// object stream flag. Used to make read(n) ignore n and to
// make all the buffer merging and length checks go away
Expand Down Expand Up @@ -142,7 +143,11 @@ function Readable(options) {
if (!(this instanceof Readable))
return new Readable(options);

this._readableState = new ReadableState(options, this);
// Checking for a Stream.Duplex instance is faster here instead of inside
// the ReadableState constructor, at least with V8 6.5
const isDuplex = (this instanceof Stream.Duplex);

this._readableState = new ReadableState(options, this, isDuplex);

// legacy
this.readable = true;
Expand Down
16 changes: 10 additions & 6 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@ util.inherits(Writable, Stream);

function nop() {}

function WritableState(options, stream) {
function WritableState(options, stream, isDuplex) {
options = options || {};

// Duplex streams are both readable and writable, but share
// the same options object.
// However, some cases require setting options to different
// values for the readable and the writable sides of the duplex stream.
// These options can be provided separately as readableXXX and writableXXX.
var isDuplex = stream instanceof Stream.Duplex;
if (typeof isDuplex !== 'boolean')
isDuplex = stream instanceof Stream.Duplex;

// object stream flag to indicate whether or not this stream
// contains buffers or objects.
Expand Down Expand Up @@ -201,12 +202,15 @@ function Writable(options) {
// Trying to use the custom `instanceof` for Writable here will also break the
// Node.js LazyTransform implementation, which has a non-trivial getter for
// `_writableState` that would lead to infinite recursion.
if (!(realHasInstance.call(Writable, this)) &&
!(this instanceof Stream.Duplex)) {

// Checking for a Stream.Duplex instance is faster here instead of inside
// the WritableState constructor, at least with V8 6.5
const isDuplex = (this instanceof Stream.Duplex);

if (!isDuplex && !realHasInstance.call(Writable, this))
return new Writable(options);
}

this._writableState = new WritableState(options, this);
this._writableState = new WritableState(options, this, isDuplex);

// legacy.
this.writable = true;
Expand Down
2 changes: 2 additions & 0 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2051,6 +2051,7 @@ ReadStream.prototype.open = function() {

self.fd = fd;
self.emit('open', fd);
self.emit('ready');
// start the flow of data.
self.read();
});
Expand Down Expand Up @@ -2207,6 +2208,7 @@ WriteStream.prototype.open = function() {

this.fd = fd;
this.emit('open', fd);
this.emit('ready');
});
};

Expand Down
1 change: 1 addition & 0 deletions lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
_process.setupConfig(NativeModule._source);
_process.setupSignalHandlers();
_process.setupUncaughtExceptionCapture(exceptionHandlerState);
_process.setupCompareVersion();
NativeModule.require('internal/process/warning').setup();
NativeModule.require('internal/process/next_tick').setup();
NativeModule.require('internal/process/stdio').setup();
Expand Down
25 changes: 11 additions & 14 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ function onSettings() {
session[kUpdateTimer]();
debug(`Http2Session ${sessionName(session[kType])}: new settings received`);
session[kRemoteSettings] = undefined;
process.nextTick(emit, session, 'remoteSettings', session.remoteSettings);
session.emit('remoteSettings', session.remoteSettings);
}

// If the stream exists, an attempt will be made to emit an event
Expand All @@ -425,7 +425,7 @@ function onPriority(id, parent, weight, exclusive) {
const emitter = session[kState].streams.get(id) || session;
if (!emitter.destroyed) {
emitter[kUpdateTimer]();
process.nextTick(emit, emitter, 'priority', id, parent, weight, exclusive);
emitter.emit('priority', id, parent, weight, exclusive);
}
}

Expand All @@ -439,7 +439,7 @@ function onFrameError(id, type, code) {
`type ${type} on stream ${id}, code: ${code}`);
const emitter = session[kState].streams.get(id) || session;
emitter[kUpdateTimer]();
process.nextTick(emit, emitter, 'frameError', type, code, id);
emitter.emit('frameError', type, code, id);
}

function onAltSvc(stream, origin, alt) {
Expand All @@ -449,7 +449,7 @@ function onAltSvc(stream, origin, alt) {
debug(`Http2Session ${sessionName(session[kType])}: altsvc received: ` +
`stream: ${stream}, origin: ${origin}, alt: ${alt}`);
session[kUpdateTimer]();
process.nextTick(emit, session, 'altsvc', alt, origin, stream);
session.emit('altsvc', alt, origin, stream);
}

// Receiving a GOAWAY frame from the connected peer is a signal that no
Expand Down Expand Up @@ -771,7 +771,7 @@ function setupHandle(socket, type, options) {
// core will check for session.destroyed before progressing, this
// ensures that those at l`east get cleared out.
if (this.destroyed) {
process.nextTick(emit, this, 'connect', this, socket);
this.emit('connect', this, socket);
return;
}
debug(`Http2Session ${sessionName(type)}: setting up session handle`);
Expand Down Expand Up @@ -813,7 +813,7 @@ function setupHandle(socket, type, options) {
options.settings : {};

this.settings(settings);
process.nextTick(emit, this, 'connect', this, socket);
this.emit('connect', this, socket);
}

// Emits a close event followed by an error event if err is truthy. Used
Expand Down Expand Up @@ -1262,7 +1262,7 @@ class Http2Session extends EventEmitter {
}
}

process.nextTick(emit, this, 'timeout');
this.emit('timeout');
}

ref() {
Expand Down Expand Up @@ -1485,8 +1485,8 @@ function streamOnPause() {
function abort(stream) {
if (!stream.aborted &&
!(stream._writableState.ended || stream._writableState.ending)) {
process.nextTick(emit, stream, 'aborted');
stream[kState].flags |= STREAM_FLAGS_ABORTED;
stream.emit('aborted');
}
}

Expand All @@ -1503,7 +1503,6 @@ class Http2Stream extends Duplex {
constructor(session, options) {
options.allowHalfOpen = true;
options.decodeStrings = false;
options.emitClose = false;
super(options);
this[async_id_symbol] = -1;

Expand Down Expand Up @@ -1612,7 +1611,7 @@ class Http2Stream extends Duplex {
}
}

process.nextTick(emit, this, 'timeout');
this.emit('timeout');
}

// true if the HEADERS frame has been sent
Expand Down Expand Up @@ -1681,7 +1680,7 @@ class Http2Stream extends Duplex {
req.async = false;
const err = createWriteReq(req, handle, data, encoding);
if (err)
throw errnoException(err, 'write', req.error);
return this.destroy(errnoException(err, 'write', req.error), cb);
trackWriteState(this, req.bytes);
}

Expand Down Expand Up @@ -1724,7 +1723,7 @@ class Http2Stream extends Duplex {
}
const err = handle.writev(req, chunks);
if (err)
throw errnoException(err, 'write', req.error);
return this.destroy(errnoException(err, 'write', req.error), cb);
trackWriteState(this, req.bytes);
}

Expand Down Expand Up @@ -1888,9 +1887,7 @@ class Http2Stream extends Duplex {
// will destroy if it has been closed and there are no other open or
// pending streams.
session[kMaybeDestroy]();
process.nextTick(emit, this, 'close', code);
callback(err);

}
// The Http2Stream can be destroyed if it has closed and if the readable
// side has received the final chunk.
Expand Down
Loading

0 comments on commit 39281f6

Please sign in to comment.