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

Commit 4ffd791

Browse files
committed
meta: merge node/master into node-chakracore/master
Merge 2ac7ade as of 2017-12-16 This commit was automatically generated. For any problems, please contact jackhorton Reviewed-By: Taylor Woll <tawoll@ntdev.microsoft.com>
2 parents 8b1ebf6 + 2ac7ade commit 4ffd791

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+642
-228
lines changed

CPP_STYLE_GUIDE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* [Formatting](#formatting)
66
* [Left-leaning (C++ style) asterisks for pointer declarations](#left-leaning-c-style-asterisks-for-pointer-declarations)
7+
* [C++ style comments](#c-style-comments)
78
* [2 spaces of indentation for blocks or bodies of conditionals](#2-spaces-of-indentation-for-blocks-or-bodies-of-conditionals)
89
* [4 spaces of indentation for statement continuations](#4-spaces-of-indentation-for-statement-continuations)
910
* [Align function arguments vertically](#align-function-arguments-vertically)
@@ -33,6 +34,26 @@ these rules:
3334

3435
`char* buffer;` instead of `char *buffer;`
3536

37+
## C++ style comments
38+
39+
Use C++ style comments (`//`) for both single-line and multi-line comments.
40+
Comments should also start with uppercase and finish with a dot.
41+
42+
Examples:
43+
44+
```c++
45+
// A single-line comment.
46+
47+
// Multi-line comments
48+
// should also use C++
49+
// style comments.
50+
```
51+
52+
The codebase may contain old C style comments (`/* */`) from before this was the
53+
preferred style. Feel free to update old comments to the preferred style when
54+
working on code in the immediate vicinity or when changing/improving those
55+
comments.
56+
3657
## 2 spaces of indentation for blocks or bodies of conditionals
3758

3859
```c++

benchmark/http/upgrade.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
'use strict';
2+
3+
const common = require('../common.js');
4+
const PORT = common.PORT;
5+
const net = require('net');
6+
7+
const bench = common.createBenchmark(main, {
8+
n: [5, 1000]
9+
});
10+
11+
const reqData = 'GET / HTTP/1.1\r\n' +
12+
'Upgrade: WebSocket\r\n' +
13+
'Connection: Upgrade\r\n' +
14+
'\r\n' +
15+
'WjN}|M(6';
16+
17+
const resData = 'HTTP/1.1 101 Web Socket Protocol Handshake\r\n' +
18+
'Upgrade: WebSocket\r\n' +
19+
'Connection: Upgrade\r\n' +
20+
'\r\n\r\n';
21+
22+
function main({ n }) {
23+
process.env.PORT = PORT;
24+
var server = require('../fixtures/simple-http-server.js')
25+
.listen(common.PORT)
26+
.on('listening', function() {
27+
bench.start();
28+
doBench(server.address(), n, function() {
29+
bench.end(n);
30+
server.close();
31+
});
32+
})
33+
.on('upgrade', function(req, socket, upgradeHead) {
34+
socket.resume();
35+
socket.write(resData);
36+
socket.end();
37+
});
38+
}
39+
40+
function doBench(address, count, done) {
41+
if (count === 0) {
42+
done();
43+
return;
44+
}
45+
46+
const conn = net.createConnection(address.port);
47+
conn.write(reqData);
48+
conn.resume();
49+
50+
conn.on('end', function() {
51+
doBench(address, count - 1, done);
52+
});
53+
}

doc/api/stream.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ object mode is not safe.
6363
<!--type=misc-->
6464

6565
Both [Writable][] and [Readable][] streams will store data in an internal
66-
buffer that can be retrieved using `writable._writableState.getBuffer()` or
67-
`readable._readableState.buffer`, respectively.
66+
buffer that can be retrieved using `writable.writableBuffer` or
67+
`readable.readableBuffer`, respectively.
6868

6969
The amount of data potentially buffered depends on the `highWaterMark` option
7070
passed into the streams constructor. For normal streams, the `highWaterMark`
@@ -602,22 +602,22 @@ Readable stream implementation.
602602
Specifically, at any given point in time, every Readable is in one of three
603603
possible states:
604604

605-
* `readable._readableState.flowing = null`
606-
* `readable._readableState.flowing = false`
607-
* `readable._readableState.flowing = true`
605+
* `readable.readableFlowing = null`
606+
* `readable.readableFlowing = false`
607+
* `readable.readableFlowing = true`
608608

609-
When `readable._readableState.flowing` is `null`, no mechanism for consuming the
609+
When `readable.readableFlowing` is `null`, no mechanism for consuming the
610610
streams data is provided so the stream will not generate its data. While in this
611611
state, attaching a listener for the `'data'` event, calling the `readable.pipe()`
612612
method, or calling the `readable.resume()` method will switch
613-
`readable._readableState.flowing` to `true`, causing the Readable to begin
613+
`readable.readableFlowing` to `true`, causing the Readable to begin
614614
actively emitting events as data is generated.
615615

616616
Calling `readable.pause()`, `readable.unpipe()`, or receiving "back pressure"
617-
will cause the `readable._readableState.flowing` to be set as `false`,
617+
will cause the `readable.readableFlowing` to be set as `false`,
618618
temporarily halting the flowing of events but *not* halting the generation of
619619
data. While in this state, attaching a listener for the `'data'` event
620-
would not cause `readable._readableState.flowing` to switch to `true`.
620+
would not cause `readable.readableFlowing` to switch to `true`.
621621

622622
```js
623623
const { PassThrough, Writable } = require('stream');
@@ -626,14 +626,14 @@ const writable = new Writable();
626626

627627
pass.pipe(writable);
628628
pass.unpipe(writable);
629-
// flowing is now false
629+
// readableFlowing is now false
630630

631631
pass.on('data', (chunk) => { console.log(chunk.toString()); });
632632
pass.write('ok'); // will not emit 'data'
633633
pass.resume(); // must be called to make 'data' being emitted
634634
```
635635

636-
While `readable._readableState.flowing` is `false`, data may be accumulating
636+
While `readable.readableFlowing` is `false`, data may be accumulating
637637
within the streams internal buffer.
638638

639639
#### Choose One

doc/api/url.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,12 +1107,15 @@ forward slash (`/`) character is encoded as `%3C`.
11071107
The [WHATWG URL Standard][] uses a more selective and fine grained approach to
11081108
selecting encoded characters than that used by the Legacy API.
11091109

1110-
The WHATWG algorithm defines three "percent-encode sets" that describe ranges
1110+
The WHATWG algorithm defines four "percent-encode sets" that describe ranges
11111111
of characters that must be percent-encoded:
11121112

11131113
* The *C0 control percent-encode set* includes code points in range U+0000 to
11141114
U+001F (inclusive) and all code points greater than U+007E.
11151115

1116+
* The *fragment percent-encode set* includes the *C0 control percent-encode set*
1117+
and code points U+0020, U+0022, U+003C, U+003E, and U+0060.
1118+
11161119
* The *path percent-encode set* includes the *C0 control percent-encode set*
11171120
and code points U+0020, U+0022, U+0023, U+003C, U+003E, U+003F, U+0060,
11181121
U+007B, and U+007D.
@@ -1123,9 +1126,9 @@ of characters that must be percent-encoded:
11231126

11241127
The *userinfo percent-encode set* is used exclusively for username and
11251128
passwords encoded within the URL. The *path percent-encode set* is used for the
1126-
path of most URLs. The *C0 control percent-encode set* is used for all
1127-
other cases, including URL fragments in particular, but also host and path
1128-
under certain specific conditions.
1129+
path of most URLs. The *fragment percent-encode set* is used for URL fragments.
1130+
The *C0 control percent-encode set* is used for host and path under certain
1131+
specific conditions, in addition to all other cases.
11291132

11301133
When non-ASCII characters appear within a hostname, the hostname is encoded
11311134
using the [Punycode][] algorithm. Note, however, that a hostname *may* contain

doc/api/util.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,19 @@ FOO 3245: hello from foo [123]
104104
where `3245` is the process id. If it is not run with that
105105
environment variable set, then it will not print anything.
106106

107+
The `section` supports wildcard also, for example:
108+
```js
109+
const util = require('util');
110+
const debuglog = util.debuglog('foo-bar');
111+
112+
debuglog('hi there, it\'s foo-bar [%d]', 2333);
113+
```
114+
115+
if it is run with `NODE_DEBUG=foo*` in the environment, then it will output something like:
116+
```txt
117+
FOO-BAR 3257: hi there, it's foo-bar [2333]
118+
```
119+
107120
Multiple comma-separated `section` names may be specified in the `NODE_DEBUG`
108121
environment variable. For example: `NODE_DEBUG=fs,net,tls`.
109122

lib/_http_client.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,7 @@ function socketOnData(d) {
432432
socket.removeListener('close', socketCloseListener);
433433
socket.removeListener('error', socketErrorListener);
434434

435-
// TODO(isaacs): Need a way to reset a stream to fresh state
436-
// IE, not flowing, and not explicitly paused.
437-
socket._readableState.flowing = null;
435+
socket.readableFlowing = null;
438436

439437
req.emit(eventName, res, socket, bodyHead);
440438
req.emit('close');

lib/_http_server.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ function socketOnData(server, socket, parser, state, d) {
449449
onParserExecuteCommon(server, socket, parser, state, ret, d);
450450
}
451451

452-
function onParserExecute(server, socket, parser, state, ret, d) {
452+
function onParserExecute(server, socket, parser, state, ret) {
453453
socket._unrefTimer();
454454
debug('SERVER socketOnParserExecute %d', ret);
455455
onParserExecuteCommon(server, socket, parser, state, ret, undefined);
@@ -502,9 +502,7 @@ function onParserExecuteCommon(server, socket, parser, state, ret, d) {
502502
debug('SERVER have listener for %s', eventName);
503503
var bodyHead = d.slice(bytesParsed, d.length);
504504

505-
// TODO(isaacs): Need a way to reset a stream to fresh state
506-
// IE, not flowing, and not explicitly paused.
507-
socket._readableState.flowing = null;
505+
socket.readableFlowing = null;
508506
server.emit(eventName, req, socket, bodyHead);
509507
} else {
510508
// Got upgrade header or CONNECT method, but have no handler.

lib/_stream_duplex.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
7474
}
7575
});
7676

77+
Object.defineProperty(Duplex.prototype, 'writableBuffer', {
78+
// making it explicit this property is not enumerable
79+
// because otherwise some prototype manipulation in
80+
// userland will fail
81+
enumerable: false,
82+
get: function() {
83+
return this._writableState && this._writableState.getBuffer();
84+
}
85+
});
86+
7787
// the no-half-open enforcer
7888
function onend() {
7989
// if we allow half-open state, or if the writable side ended,

lib/_stream_readable.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,31 @@ Object.defineProperty(Readable.prototype, 'readableHighWaterMark', {
925925
}
926926
});
927927

928+
Object.defineProperty(Readable.prototype, 'readableBuffer', {
929+
// making it explicit this property is not enumerable
930+
// because otherwise some prototype manipulation in
931+
// userland will fail
932+
enumerable: false,
933+
get: function() {
934+
return this._readableState && this._readableState.buffer;
935+
}
936+
});
937+
938+
Object.defineProperty(Readable.prototype, 'readableFlowing', {
939+
// making it explicit this property is not enumerable
940+
// because otherwise some prototype manipulation in
941+
// userland will fail
942+
enumerable: false,
943+
get: function() {
944+
return this._readableState.flowing;
945+
},
946+
set: function(state) {
947+
if (this._readableState) {
948+
this._readableState.flowing = state;
949+
}
950+
}
951+
});
952+
928953
// exposed for testing purposes only.
929954
Readable._fromList = fromList;
930955

lib/_stream_writable.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,7 @@ function validChunk(stream, state, chunk, cb) {
249249

250250
if (chunk === null) {
251251
er = new errors.TypeError('ERR_STREAM_NULL_VALUES');
252-
} else if (typeof chunk !== 'string' &&
253-
chunk !== undefined &&
254-
!state.objectMode) {
252+
} else if (typeof chunk !== 'string' && !state.objectMode) {
255253
er = new errors.TypeError('ERR_INVALID_ARG_TYPE', 'chunk',
256254
['string', 'Buffer']);
257255
}
@@ -326,6 +324,16 @@ Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
326324
return this;
327325
};
328326

327+
Object.defineProperty(Writable.prototype, 'writableBuffer', {
328+
// making it explicit this property is not enumerable
329+
// because otherwise some prototype manipulation in
330+
// userland will fail
331+
enumerable: false,
332+
get: function() {
333+
return this._writableState && this._writableState.getBuffer();
334+
}
335+
});
336+
329337
function decodeChunk(state, chunk, encoding) {
330338
if (!state.objectMode &&
331339
state.decodeStrings !== false &&

0 commit comments

Comments
 (0)