|
14 | 14 | const { |
15 | 15 | ArrayPrototypePush, |
16 | 16 | FunctionPrototypeCall, |
| 17 | + ObjectFreeze, |
17 | 18 | Promise, |
18 | 19 | PromisePrototypeThen, |
19 | 20 | PromiseReject, |
@@ -61,6 +62,7 @@ const { |
61 | 62 | } = require('internal/streams/iter/types'); |
62 | 63 |
|
63 | 64 | const { |
| 65 | + PendingRequest, |
64 | 66 | convertChunks, |
65 | 67 | getWriterSignal, |
66 | 68 | onSignalAbort, |
@@ -522,6 +524,18 @@ function toReadableSync(source, options = kNullPrototype) { |
522 | 524 | // Cache: one Writer adapter per Writable instance. |
523 | 525 | const fromWritableCache = new SafeWeakMap(); |
524 | 526 |
|
| 527 | +// A write queued by fromWritable() until the writable can accept it. Like |
| 528 | +// the other per-write records, constructed rather than created as a |
| 529 | +// `{ __proto__: null, ... }` literal (a dictionary-mode object). |
| 530 | +function QueuedWrite(chunks, resolve, reject) { |
| 531 | + this.chunks = chunks; |
| 532 | + this.resolve = resolve; |
| 533 | + this.reject = reject; |
| 534 | + this.signal = undefined; |
| 535 | + this.onAbort = undefined; |
| 536 | +} |
| 537 | +QueuedWrite.prototype = ObjectFreeze({ __proto__: null }); |
| 538 | + |
525 | 539 | /** |
526 | 540 | * Create a stream/iter Writer adapter from a classic Writable (or duck-type). |
527 | 541 | * |
@@ -643,7 +657,7 @@ function fromWritable(writable, options = kNullPrototype) { |
643 | 657 | if (preserveReason) { |
644 | 658 | pending[i].reject(reason); |
645 | 659 | } else { |
646 | | - pending[i].close(); |
| 660 | + pending[i].resolve(false); |
647 | 661 | } |
648 | 662 | } |
649 | 663 |
|
@@ -755,14 +769,7 @@ function fromWritable(writable, options = kNullPrototype) { |
755 | 769 |
|
756 | 770 | function queueWrite(chunks, signal) { |
757 | 771 | const { promise, resolve, reject } = PromiseWithResolvers(); |
758 | | - const entry = { |
759 | | - __proto__: null, |
760 | | - chunks, |
761 | | - resolve, |
762 | | - reject, |
763 | | - signal: undefined, |
764 | | - onAbort: undefined, |
765 | | - }; |
| 772 | + const entry = new QueuedWrite(chunks, resolve, reject); |
766 | 773 | pendingWrites.push(entry); |
767 | 774 | installDrainListener(); |
768 | 775 |
|
@@ -1038,12 +1045,7 @@ function fromWritable(writable, options = kNullPrototype) { |
1038 | 1045 | return PromiseResolve(true); |
1039 | 1046 | } |
1040 | 1047 | const { promise, resolve, reject } = PromiseWithResolvers(); |
1041 | | - ArrayPrototypePush(drainWaiters, { |
1042 | | - __proto__: null, |
1043 | | - resolve, |
1044 | | - reject, |
1045 | | - close() { resolve(false); }, |
1046 | | - }); |
| 1048 | + ArrayPrototypePush(drainWaiters, new PendingRequest(resolve, reject)); |
1047 | 1049 | installDrainListener(); |
1048 | 1050 | return promise; |
1049 | 1051 | }; |
|
0 commit comments