forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-webstreams-duplex-fromweb-writev-unhandled-rejection.js
More file actions
55 lines (45 loc) · 1.69 KB
/
test-webstreams-duplex-fromweb-writev-unhandled-rejection.js
File metadata and controls
55 lines (45 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'use strict';
// Regression test for https://github.com/nodejs/node/issues/62199
//
// When Duplex.fromWeb is corked, writes are batched into _writev. If destroy()
// is called in the same microtask (after uncork()), writer.ready rejects with a
// non-array value. The done() callback inside _writev unconditionally called
// error.filter(), which throws TypeError on non-arrays. This TypeError became
// an unhandled rejection that crashed the process.
//
// The same bug exists in newStreamWritableFromWritableStream (Writable.fromWeb).
const common = require('../common');
const { Duplex, Writable } = require('stream');
const { TransformStream, WritableStream } = require('stream/web');
// Exact reproduction from the issue report (davidje13).
// Before the fix: process crashes with unhandled TypeError.
// After the fix: stream closes cleanly with no unhandled rejection.
{
const output = Duplex.fromWeb(new TransformStream());
output.on('close', common.mustCall());
output.cork();
output.write('test');
output.write('test');
output.uncork();
output.destroy();
}
// Same bug in Writable.fromWeb (newStreamWritableFromWritableStream).
{
const writable = Writable.fromWeb(new WritableStream());
writable.on('close', common.mustCall());
writable.cork();
writable.write('test');
writable.write('test');
writable.uncork();
writable.destroy();
}
// Regression: normal cork/uncork/_writev success path must still work.
// Verifies that () => done() correctly signals success via callback().
{
const writable = Writable.fromWeb(new WritableStream({ write() {} }));
writable.cork();
writable.write('foo');
writable.write('bar');
writable.uncork();
writable.end(common.mustCall());
}