Skip to content

Commit 2149b0d

Browse files
committed
Import Node 10.9.0. Redo the fix for util.inspect.custom
Fixes #355
1 parent ddce1af commit 2149b0d

File tree

11 files changed

+96
-79
lines changed

11 files changed

+96
-79
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ npm install --save readable-stream
1515

1616
This package is a mirror of the streams implementations in Node.js.
1717

18-
Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v10.8.0/docs/api/stream.html).
18+
Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v10.9.0/docs/api/stream.html).
1919

2020
If you want to guarantee a stable streams base, regardless of what version of
2121
Node you, or the users of your libraries are using, use **readable-stream** *only* and avoid the *"stream"* module in Node-core, for background see [this blogpost](http://r.va.gg/2014/06/why-i-dont-use-nodes-core-stream-module.html).

build/files.js

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,6 @@ function CorkedRequest(state) {
180180
/Object\.getPrototypeOf\((chunk)\) !== Buffer\.prototype/g
181181
, '!Buffer.isBuffer($1)'
182182
]
183-
, fixCopyBuffer = [
184-
/Buffer\.prototype\.copy\.call\(src, target, offset\);/
185-
, 'src.copy(target, offset);'
186-
]
187183
, errorsOneLevel = [
188184
/internal\/errors/
189185
, '../errors'
@@ -280,24 +276,15 @@ module.exports['_stream_writable.js'] = [
280276

281277
module.exports['internal/streams/buffer_list.js'] = [
282278
[
283-
/(?:var|const) (?:{ )Buffer(?: }) = require\('buffer'\)(?:\.Buffer)?;/,
279+
/const \{ inspect \} = require\('util'\);/,
284280
`
285-
const Buffer = require('buffer').Buffer
286-
const util = require('util')
281+
const { inspect } = require('util')
282+
const custom = inspect && inspect.custom || Symbol('useless')
287283
`
288284
]
289-
, fixCopyBuffer
290285
, [
291-
/$/,
292-
`
293-
294-
if (util && util.inspect && util.inspect.custom) {
295-
module.exports.prototype[util.inspect.custom] = function () {
296-
const obj = util.inspect({ length: this.length });
297-
return \`\${this.constructor.name} \${obj}\`;
298-
}
299-
}
300-
`
286+
/inspect.custom/g,
287+
'custom'
301288
]
302289

303290
]

lib/_stream_readable.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ Readable.prototype.read = function (n) {
381381
// if we're doing read(0) to trigger a readable event, but we
382382
// already have a bunch of data in the buffer, then just trigger
383383
// the 'readable' event and move on.
384-
if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
384+
if (n === 0 && state.needReadable && ((state.highWaterMark !== 0 ? state.length >= state.highWaterMark : state.length > 0) || state.ended)) {
385385
debug('read: emitReadable', state.length, state.ended);
386386
if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
387387
return null;
@@ -768,6 +768,7 @@ Readable.prototype.on = function (ev, fn) {
768768
if (!state.endEmitted && !state.readableListening) {
769769
state.readableListening = state.needReadable = true;
770770
state.emittedReadable = false;
771+
debug('on readable', state.length, state.reading);
771772
if (state.length) {
772773
emitReadable(this);
773774
} else if (!state.reading) {

lib/internal/streams/buffer_list.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22

33
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
44

5-
var Buffer = require('buffer').Buffer;
6-
var util = require('util');
5+
var _require = require('buffer'),
6+
Buffer = _require.Buffer;
77

8-
var _require = require('util'),
9-
inspect = _require.inspect;
8+
var _require2 = require('util'),
9+
inspect = _require2.inspect;
10+
11+
var custom = inspect && custom || Symbol('useless');
1012

1113
function copyBuffer(src, target, offset) {
12-
src.copy(target, offset);
14+
Buffer.prototype.copy.call(src, target, offset);
1315
}
1416

1517
module.exports = function () {
@@ -152,17 +154,10 @@ module.exports = function () {
152154
return ret;
153155
};
154156

155-
BufferList.prototype[inspect.custom] = function () {
157+
BufferList.prototype[custom] = function () {
156158
var obj = inspect({ length: this.length });
157159
return this.constructor.name + ' ' + obj;
158160
};
159161

160162
return BufferList;
161-
}();
162-
163-
if (util && util.inspect && util.inspect.custom) {
164-
module.exports.prototype[util.inspect.custom] = function () {
165-
var obj = util.inspect({ length: this.length });
166-
return this.constructor.name + ' ' + obj;
167-
};
168-
}
163+
}();

test/common/README.md

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,6 @@ Tests whether `name`, `expected`, and `code` are part of a raised warning. If
125125
an expected warning does not have a code then `common.noWarnCode` can be used
126126
to indicate this.
127127

128-
### fileExists(pathname)
129-
* pathname [<string>]
130-
* return [<boolean>]
131-
132-
Checks if `pathname` exists
133-
134128
### getArrayBufferViews(buf)
135129
* `buf` [<Buffer>]
136130
* return [<ArrayBufferView[]>]
@@ -582,7 +576,7 @@ one listed below. (`heap.validateSnapshotNodes(...)` is a shortcut for
582576

583577
Create a heap dump and an embedder graph copy and validate occurrences.
584578

585-
<!-- eslint-disable no-undef, no-unused-vars, node-core/required-modules, strict -->
579+
<!-- eslint-disable no-undef, node-core/required-modules -->
586580
```js
587581
validateSnapshotNodes('TLSWRAP', [
588582
{
@@ -600,7 +594,7 @@ validateSnapshotNodes('TLSWRAP', [
600594
The http2.js module provides a handful of utilities for creating mock HTTP/2
601595
frames for testing of HTTP/2 endpoints
602596

603-
<!-- eslint-disable no-undef, no-unused-vars, node-core/required-modules, strict -->
597+
<!-- eslint-disable no-unused-vars, node-core/required-modules -->
604598
```js
605599
const http2 = require('../common/http2');
606600
```
@@ -610,7 +604,7 @@ const http2 = require('../common/http2');
610604
The `http2.Frame` is a base class that creates a `Buffer` containing a
611605
serialized HTTP/2 frame header.
612606

613-
<!-- eslint-disable no-undef, no-unused-vars, node-core/required-modules, strict -->
607+
<!-- eslint-disable no-undef, node-core/required-modules -->
614608
```js
615609
// length is a 24-bit unsigned integer
616610
// type is an 8-bit unsigned integer identifying the frame type
@@ -629,7 +623,7 @@ The serialized `Buffer` may be retrieved using the `frame.data` property.
629623
The `http2.DataFrame` is a subclass of `http2.Frame` that serializes a `DATA`
630624
frame.
631625

632-
<!-- eslint-disable no-undef, no-unused-vars, node-core/required-modules, strict -->
626+
<!-- eslint-disable no-undef, node-core/required-modules -->
633627
```js
634628
// id is the 32-bit stream identifier
635629
// payload is a Buffer containing the DATA payload
@@ -646,7 +640,7 @@ socket.write(frame.data);
646640
The `http2.HeadersFrame` is a subclass of `http2.Frame` that serializes a
647641
`HEADERS` frame.
648642

649-
<!-- eslint-disable no-undef, no-unused-vars, node-core/required-modules, strict -->
643+
<!-- eslint-disable no-undef, node-core/required-modules -->
650644
```js
651645
// id is the 32-bit stream identifier
652646
// payload is a Buffer containing the HEADERS payload (see either
@@ -664,7 +658,7 @@ socket.write(frame.data);
664658
The `http2.SettingsFrame` is a subclass of `http2.Frame` that serializes an
665659
empty `SETTINGS` frame.
666660

667-
<!-- eslint-disable no-undef, no-unused-vars, node-core/required-modules, strict -->
661+
<!-- eslint-disable no-undef, node-core/required-modules -->
668662
```js
669663
// ack is a boolean indicating whether or not to set the ACK flag.
670664
const frame = new http2.SettingsFrame(ack);
@@ -677,7 +671,7 @@ socket.write(frame.data);
677671
Set to a `Buffer` instance that contains a minimal set of serialized HTTP/2
678672
request headers to be used as the payload of a `http2.HeadersFrame`.
679673

680-
<!-- eslint-disable no-undef, no-unused-vars, node-core/required-modules, strict -->
674+
<!-- eslint-disable no-undef, node-core/required-modules -->
681675
```js
682676
const frame = new http2.HeadersFrame(1, http2.kFakeRequestHeaders, 0, true);
683677

@@ -689,7 +683,7 @@ socket.write(frame.data);
689683
Set to a `Buffer` instance that contains a minimal set of serialized HTTP/2
690684
response headers to be used as the payload a `http2.HeadersFrame`.
691685

692-
<!-- eslint-disable no-undef, no-unused-vars, node-core/required-modules, strict -->
686+
<!-- eslint-disable no-undef, node-core/required-modules -->
693687
```js
694688
const frame = new http2.HeadersFrame(1, http2.kFakeResponseHeaders, 0, true);
695689

@@ -701,7 +695,7 @@ socket.write(frame.data);
701695
Set to a `Buffer` containing the preamble bytes an HTTP/2 client must send
702696
upon initial establishment of a connection.
703697

704-
<!-- eslint-disable no-undef, no-unused-vars, node-core/required-modules, strict -->
698+
<!-- eslint-disable no-undef, node-core/required-modules -->
705699
```js
706700
socket.write(http2.kClientMagic);
707701
```

test/common/benchmark.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ function runBenchmark(name, args, env) {
3636

3737
var mergedEnv = Object.assign({}, process.env, env);
3838

39-
var child = fork(runjs, argv, { env: mergedEnv, stdio: 'pipe' });
39+
var child = fork(runjs, argv, {
40+
env: mergedEnv,
41+
stdio: ['inherit', 'pipe', 'inherit', 'ipc']
42+
});
4043
child.stdout.setEncoding('utf8');
4144

4245
var stdout = '';

test/common/index.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -518,17 +518,8 @@ exports.hasMultiLocalhost = function hasMultiLocalhost() {
518518
return ret === 0;
519519
};
520520

521-
exports.fileExists = function (pathname) {
522-
try {
523-
fs.accessSync(pathname);
524-
return true;
525-
} catch (err) {
526-
return false;
527-
}
528-
};
529-
530521
exports.skipIfEslintMissing = function () {
531-
if (!exports.fileExists(path.join(__dirname, '..', '..', 'tools', 'node_modules', 'eslint'))) {
522+
if (!fs.existsSync(path.join(__dirname, '..', '..', 'tools', 'node_modules', 'eslint'))) {
532523
exports.skip('missing ESLint');
533524
}
534525
};
@@ -768,7 +759,8 @@ exports.expectsError = function expectsError(fn, settings, exact) {
768759
assert.fail('Expected one argument, got ' + util.inspect(arguments));
769760
}
770761
var descriptor = Object.getOwnPropertyDescriptor(error, 'message');
771-
assert.strictEqual(descriptor.enumerable, false, 'The error message should be non-enumerable');
762+
// The error message should be non-enumerable
763+
assert.strictEqual(descriptor.enumerable, false);
772764

773765
var innerSettings = settings;
774766
if ('type' in settings) {

test/common/index.mjs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import common from './index.js';
88

99
const {
10-
PORT,
1110
isMainThread,
1211
isWindows,
1312
isWOW64,
@@ -38,7 +37,6 @@ const {
3837
mustCallAtLeast,
3938
mustCallAsync,
4039
hasMultiLocalhost,
41-
fileExists,
4240
skipIfEslintMissing,
4341
canCreateSymLink,
4442
getCallSite,
@@ -67,7 +65,6 @@ const {
6765
} = common;
6866

6967
export {
70-
PORT,
7168
isMainThread,
7269
isWindows,
7370
isWOW64,
@@ -98,7 +95,6 @@ export {
9895
mustCallAtLeast,
9996
mustCallAsync,
10097
hasMultiLocalhost,
101-
fileExists,
10298
skipIfEslintMissing,
10399
canCreateSymLink,
104100
getCallSite,
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'use strict';
2+
3+
/*<replacement>*/
4+
var bufferShim = require('safe-buffer').Buffer;
5+
/*</replacement>*/
6+
7+
var common = require('../common');
8+
9+
// This test ensures that Readable stream will call _read() for streams
10+
// with highWaterMark === 0 upon .read(0) instead of just trying to
11+
// emit 'readable' event.
12+
13+
var assert = require('assert/');
14+
15+
var _require = require('../../'),
16+
Readable = _require.Readable;
17+
18+
var r = new Readable({
19+
// must be called only once upon setting 'readable' listener
20+
read: common.mustCall(),
21+
highWaterMark: 0
22+
});
23+
24+
var pushedNull = false;
25+
// this will trigger read(0) but must only be called after push(null)
26+
// because the we haven't pushed any data
27+
r.on('readable', common.mustCall(function () {
28+
assert.strictEqual(r.read(), null);
29+
assert.strictEqual(pushedNull, true);
30+
}));
31+
r.on('end', common.mustCall());
32+
process.nextTick(function () {
33+
assert.strictEqual(r.read(), null);
34+
pushedNull = true;
35+
r.push(null);
36+
});
37+
;require('tap').pass('sync run');var _list = process.listeners('uncaughtException');process.removeAllListeners('uncaughtException');_list.pop();_list.forEach(function (e) {
38+
return process.on('uncaughtException', e);
39+
});

test/parallel/test-stream-transform-final.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,46 +63,56 @@ The order things are called
6363
var t = new stream.Transform({
6464
objectMode: true,
6565
transform: common.mustCall(function (chunk, _, next) {
66-
assert.strictEqual(++state, chunk, 'transformCallback part 1');
66+
// transformCallback part 1
67+
assert.strictEqual(++state, chunk);
6768
this.push(state);
68-
assert.strictEqual(++state, chunk + 2, 'transformCallback part 2');
69+
// transformCallback part 2
70+
assert.strictEqual(++state, chunk + 2);
6971
process.nextTick(next);
7072
}, 3),
7173
final: common.mustCall(function (done) {
7274
state++;
73-
assert.strictEqual(state, 10, 'finalCallback part 1');
75+
// finalCallback part 1
76+
assert.strictEqual(state, 10);
7477
setTimeout(function () {
7578
state++;
76-
assert.strictEqual(state, 11, 'finalCallback part 2');
79+
// finalCallback part 2
80+
assert.strictEqual(state, 11);
7781
done();
7882
}, 100);
7983
}, 1),
8084
flush: common.mustCall(function (done) {
8185
state++;
82-
assert.strictEqual(state, 12, 'flushCallback part 1');
86+
// flushCallback part 1
87+
assert.strictEqual(state, 12);
8388
process.nextTick(function () {
8489
state++;
85-
assert.strictEqual(state, 15, 'flushCallback part 2');
90+
// flushCallback part 2
91+
assert.strictEqual(state, 15);
8692
done();
8793
});
8894
}, 1)
8995
});
9096
t.on('finish', common.mustCall(function () {
9197
state++;
92-
assert.strictEqual(state, 13, 'finishListener');
98+
// finishListener
99+
assert.strictEqual(state, 13);
93100
}, 1));
94101
t.on('end', common.mustCall(function () {
95102
state++;
96-
assert.strictEqual(state, 16, 'end event');
103+
// end event
104+
assert.strictEqual(state, 16);
97105
}, 1));
98106
t.on('data', common.mustCall(function (d) {
99-
assert.strictEqual(++state, d + 1, 'dataListener');
107+
// dataListener
108+
assert.strictEqual(++state, d + 1);
100109
}, 3));
101110
t.write(1);
102111
t.write(4);
103112
t.end(7, common.mustCall(function () {
104113
state++;
105-
assert.strictEqual(state, 14, 'endMethodCallback');
114+
// endMethodCallback
115+
assert.strictEqual(state, 14);
106116
}, 1));
107117
;require('tap').pass('sync run');var _list = process.listeners('uncaughtException');process.removeAllListeners('uncaughtException');_list.pop();_list.forEach(function (e) {
108118
return process.on('uncaughtException', e);

0 commit comments

Comments
 (0)