(stream, er)
| 613 | } |
| 614 | |
| 615 | function onwrite(stream, er) { |
| 616 | const state = stream._writableState; |
| 617 | |
| 618 | if ((state[kState] & kExpectWriteCb) === 0) { |
| 619 | errorOrDestroy(stream, new ERR_MULTIPLE_CALLBACK()); |
| 620 | return; |
| 621 | } |
| 622 | |
| 623 | const sync = (state[kState] & kSync) !== 0; |
| 624 | const cb = (state[kState] & kWriteCb) !== 0 ? state[kWriteCbValue] : nop; |
| 625 | |
| 626 | state.writecb = null; |
| 627 | state[kState] &= ~(kWriting | kExpectWriteCb); |
| 628 | state.length -= state.writelen; |
| 629 | state.writelen = 0; |
| 630 | |
| 631 | if (er) { |
| 632 | // Avoid V8 leak, https://github.com/nodejs/node/pull/34103#issuecomment-652002364 |
| 633 | er.stack; // eslint-disable-line no-unused-expressions |
| 634 | |
| 635 | if ((state[kState] & kErrored) === 0) { |
| 636 | state[kErroredValue] = er; |
| 637 | state[kState] |= kErrored; |
| 638 | } |
| 639 | |
| 640 | // In case of duplex streams we need to notify the readable side of the |
| 641 | // error. |
| 642 | if (stream._readableState && !stream._readableState.errored) { |
| 643 | stream._readableState.errored = er; |
| 644 | } |
| 645 | |
| 646 | if (sync) { |
| 647 | process.nextTick(onwriteError, stream, state, er, cb); |
| 648 | } else { |
| 649 | onwriteError(stream, state, er, cb); |
| 650 | } |
| 651 | } else { |
| 652 | if ((state[kState] & kBuffered) !== 0) { |
| 653 | clearBuffer(stream, state); |
| 654 | } |
| 655 | |
| 656 | if (sync) { |
| 657 | const needDrain = (state[kState] & kNeedDrain) !== 0 && state.length === 0; |
| 658 | const needTick = needDrain || (state[kState] & kDestroyed !== 0) || cb !== nop; |
| 659 | |
| 660 | // It is a common case that the callback passed to .write() is always |
| 661 | // the same. In that case, we do not schedule a new nextTick(), but |
| 662 | // rather just increase a counter, to improve performance and avoid |
| 663 | // memory allocations. |
| 664 | if (cb === nop) { |
| 665 | if ((state[kState] & kAfterWritePending) === 0 && needTick) { |
| 666 | process.nextTick(afterWrite, stream, state, 1, cb); |
| 667 | state[kState] |= kAfterWritePending; |
| 668 | } else { |
| 669 | state.pendingcb--; |
| 670 | if ((state[kState] & kEnding) !== 0) { |
| 671 | finishMaybe(stream, state, true); |
| 672 | } |
no test coverage detected
searching dependent graphs…