| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2425,7 +2425,8 @@ and `stream.Readable` classes, respectively. The `'finish'` event is emitted | |||
| 2425 | 2425 | after [`stream.end()`][stream-end] is called and all chunks have been processed | |
| 2426 | 2426 | by [`stream._transform()`][stream-_transform]. The `'end'` event is emitted | |
| 2427 | 2427 | after all data has been output, which occurs after the callback in | |
| 2428 | - [`transform._flush()`][stream-_flush] has been called. | ||
| 2428 | + [`transform._flush()`][stream-_flush] has been called. In the case of an error, | ||
| 2429 | + neither `'finish'` nor `'end'` should be emitted. | ||
| 2429 | 2430 | ||
| 2430 | 2431 | #### transform.\_flush(callback) | |
| 2431 | 2432 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -437,19 +437,12 @@ function onwriteError(stream, state, sync, er, cb) { | |||
| 437 | 437 | // Defer the callback if we are being called synchronously | |
| 438 | 438 | // to avoid piling up things on the stack | |
| 439 | 439 | process.nextTick(cb, er); | |
| 440 | - // This can emit finish, and it will always happen | ||
| 441 | - // after error | ||
| 442 | - process.nextTick(finishMaybe, stream, state); | ||
| 443 | - errorOrDestroy(stream, er); | ||
| 444 | 440 | } else { | |
| 445 | 441 | // The caller expect this to happen before if | |
| 446 | 442 | // it is async | |
| 447 | 443 | cb(er); | |
| 448 | - errorOrDestroy(stream, er); | ||
| 449 | - // This can emit finish, but finish must | ||
| 450 | - // always follow error | ||
| 451 | - finishMaybe(stream, state); | ||
| 452 | 444 | } | |
| 445 | + errorOrDestroy(stream, er); | ||
| 453 | 446 | } | |
| 454 | 447 | ||
| 455 | 448 | function onwrite(stream, er) { | |
@@ -618,6 +611,7 @@ Object.defineProperty(Writable.prototype, 'writableLength', { | |||
| 618 | 611 | function needFinish(state) { | |
| 619 | 612 | return (state.ending && | |
| 620 | 613 | state.length === 0 && | |
| 614 | + !state.errorEmitted && | ||
| 621 | 615 | state.bufferedRequest === null && | |
| 622 | 616 | !state.finished && | |
| 623 | 617 | !state.writing); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -51,34 +51,6 @@ tcp.listen(0, common.mustCall(function() { | |||
| 51 | 51 | assert.strictEqual(socket.connecting, true); | |
| 52 | 52 | assert.strictEqual(socket.readyState, 'opening'); | |
| 53 | 53 | ||
| 54 | - // Make sure that anything besides a buffer or a string throws. | ||
| 55 | - common.expectsError(() => socket.write(null), | ||
| 56 | - { | ||
| 57 | - code: 'ERR_STREAM_NULL_VALUES', | ||
| 58 | - type: TypeError, | ||
| 59 | - message: 'May not write null values to stream' | ||
| 60 | - }); | ||
| 61 | - [ | ||
| 62 | - true, | ||
| 63 | - false, | ||
| 64 | - undefined, | ||
| 65 | - 1, | ||
| 66 | - 1.0, | ||
| 67 | - +Infinity, | ||
| 68 | - -Infinity, | ||
| 69 | - [], | ||
| 70 | - {} | ||
| 71 | - ].forEach((value) => { | ||
| 72 | - // We need to check the callback since 'error' will only | ||
| 73 | - // be emitted once per instance. | ||
| 74 | - socket.write(value, common.expectsError({ | ||
| 75 | - code: 'ERR_INVALID_ARG_TYPE', | ||
| 76 | - type: TypeError, | ||
| 77 | - message: 'The "chunk" argument must be one of type string or Buffer. ' + | ||
| 78 | - `Received type ${typeof value}` | ||
| 79 | - })); | ||
| 80 | - }); | ||
| 81 | - | ||
| 82 | 54 | // Write a string that contains a multi-byte character sequence to test that | |
| 83 | 55 | // `bytesWritten` is incremented with the # of bytes, not # of characters. | |
| 84 | 56 | const a = "L'État, c'est "; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,7 +13,7 @@ function connectToServer() { | |||
| 13 | 13 | type: TypeError | |
| 14 | 14 | }); | |
| 15 | 15 | ||
| 16 | - client.end(); | ||
| 16 | + client.destroy(); | ||
| 17 | 17 | }) | |
| 18 | - .on('end', () => server.close()); | ||
| 18 | + .on('close', () => server.close()); | ||
| 19 | 19 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,33 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const net = require('net'); | ||
| 4 | + | ||
| 5 | + const socket = net.Stream({ highWaterMark: 0 }); | ||
| 6 | + | ||
| 7 | + // Make sure that anything besides a buffer or a string throws. | ||
| 8 | + common.expectsError(() => socket.write(null), | ||
| 9 | + { | ||
| 10 | + code: 'ERR_STREAM_NULL_VALUES', | ||
| 11 | + type: TypeError, | ||
| 12 | + message: 'May not write null values to stream' | ||
| 13 | + }); | ||
| 14 | + [ | ||
| 15 | + true, | ||
| 16 | + false, | ||
| 17 | + undefined, | ||
| 18 | + 1, | ||
| 19 | + 1.0, | ||
| 20 | + +Infinity, | ||
| 21 | + -Infinity, | ||
| 22 | + [], | ||
| 23 | + {} | ||
| 24 | + ].forEach((value) => { | ||
| 25 | + // We need to check the callback since 'error' will only | ||
| 26 | + // be emitted once per instance. | ||
| 27 | + socket.write(value, common.expectsError({ | ||
| 28 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 29 | + type: TypeError, | ||
| 30 | + message: 'The "chunk" argument must be one of type string or Buffer. ' + | ||
| 31 | + `Received type ${typeof value}` | ||
| 32 | + })); | ||
| 33 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,16 +14,10 @@ const stream = require('stream'); | |||
| 14 | 14 | cb(new Error('write test error')); | |
| 15 | 15 | }; | |
| 16 | 16 | ||
| 17 | - let firstError = false; | ||
| 18 | - writable.on('finish', common.mustCall(function() { | ||
| 19 | - assert.strictEqual(firstError, true); | ||
| 20 | - })); | ||
| 21 | - | ||
| 22 | - writable.on('prefinish', common.mustCall()); | ||
| 23 | - | ||
| 17 | + writable.on('finish', common.mustNotCall()); | ||
| 18 | + writable.on('prefinish', common.mustNotCall()); | ||
| 24 | 19 | writable.on('error', common.mustCall((er) => { | |
| 25 | 20 | assert.strictEqual(er.message, 'write test error'); | |
| 26 | - firstError = true; | ||
| 27 | 21 | })); | |
| 28 | 22 | ||
| 29 | 23 | writable.end('test'); | |
@@ -36,16 +30,10 @@ const stream = require('stream'); | |||
| 36 | 30 | setImmediate(cb, new Error('write test error')); | |
| 37 | 31 | }; | |
| 38 | 32 | ||
| 39 | - let firstError = false; | ||
| 40 | - writable.on('finish', common.mustCall(function() { | ||
| 41 | - assert.strictEqual(firstError, true); | ||
| 42 | - })); | ||
| 43 | - | ||
| 44 | - writable.on('prefinish', common.mustCall()); | ||
| 45 | - | ||
| 33 | + writable.on('finish', common.mustNotCall()); | ||
| 34 | + writable.on('prefinish', common.mustNotCall()); | ||
| 46 | 35 | writable.on('error', common.mustCall((er) => { | |
| 47 | 36 | assert.strictEqual(er.message, 'write test error'); | |
| 48 | - firstError = true; | ||
| 49 | 37 | })); | |
| 50 | 38 | ||
| 51 | 39 | writable.end('test'); | |
@@ -62,16 +50,10 @@ const stream = require('stream'); | |||
| 62 | 50 | cb(new Error('writev test error')); | |
| 63 | 51 | }; | |
| 64 | 52 | ||
| 65 | - let firstError = false; | ||
| 66 | - writable.on('finish', common.mustCall(function() { | ||
| 67 | - assert.strictEqual(firstError, true); | ||
| 68 | - })); | ||
| 69 | - | ||
| 70 | - writable.on('prefinish', common.mustCall()); | ||
| 71 | - | ||
| 53 | + writable.on('finish', common.mustNotCall()); | ||
| 54 | + writable.on('prefinish', common.mustNotCall()); | ||
| 72 | 55 | writable.on('error', common.mustCall((er) => { | |
| 73 | 56 | assert.strictEqual(er.message, 'writev test error'); | |
| 74 | - firstError = true; | ||
| 75 | 57 | })); | |
| 76 | 58 | ||
| 77 | 59 | writable.cork(); | |
@@ -93,16 +75,10 @@ const stream = require('stream'); | |||
| 93 | 75 | setImmediate(cb, new Error('writev test error')); | |
| 94 | 76 | }; | |
| 95 | 77 | ||
| 96 | - let firstError = false; | ||
| 97 | - writable.on('finish', common.mustCall(function() { | ||
| 98 | - assert.strictEqual(firstError, true); | ||
| 99 | - })); | ||
| 100 | - | ||
| 101 | - writable.on('prefinish', common.mustCall()); | ||
| 102 | - | ||
| 78 | + writable.on('finish', common.mustNotCall()); | ||
| 79 | + writable.on('prefinish', common.mustNotCall()); | ||
| 103 | 80 | writable.on('error', common.mustCall((er) => { | |
| 104 | 81 | assert.strictEqual(er.message, 'writev test error'); | |
| 105 | - firstError = true; | ||
| 106 | 82 | })); | |
| 107 | 83 | ||
| 108 | 84 | writable.cork(); | |
@@ -123,14 +99,9 @@ const stream = require('stream'); | |||
| 123 | 99 | rs._read = () => {}; | |
| 124 | 100 | ||
| 125 | 101 | const ws = new stream.Writable(); | |
| 126 | - let firstError = false; | ||
| 127 | 102 | ||
| 128 | - ws.on('finish', common.mustCall(function() { | ||
| 129 | - assert.strictEqual(firstError, true); | ||
| 130 | - })); | ||
| 131 | - ws.on('error', common.mustCall(function() { | ||
| 132 | - firstError = true; | ||
| 133 | - })); | ||
| 103 | + ws.on('finish', common.mustNotCall()); | ||
| 104 | + ws.on('error', common.mustCall()); | ||
| 134 | 105 | ||
| 135 | 106 | ws._write = (chunk, encoding, done) => { | |
| 136 | 107 | setImmediate(done, new Error()); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments