Debian Codegraph @

testing/web-platform/tests/streams/writable-streams/error.any.js

raw
1 // META: global=window,worker,shadowrealm
2 'use strict';
3
4 const error1 = new Error('error1');
5 error1.name = 'error1';
6
7 const error2 = new Error('error2');
8 error2.name = 'error2';
9
10 promise_test(t => {
11 const ws = new WritableStream({
12 start(controller) {
13 controller.error(error1);
14 }
15 });
16 return promise_rejects_exactly(t, error1, ws.getWriter().closed, 'stream should be errored');
17 }, 'controller.error() should error the stream');
18
19 test(() => {
20 let controller;
21 const ws = new WritableStream({
22 start(c) {
23 controller = c;
24 }
25 });
26 ws.abort();
27 controller.error(error1);
28 }, 'controller.error() on erroring stream should not throw');
29
30 promise_test(t => {
31 let controller;
32 const ws = new WritableStream({
33 start(c) {
34 controller = c;
35 }
36 });
37 controller.error(error1);
38 controller.error(error2);
39 return promise_rejects_exactly(t, error1, ws.getWriter().closed, 'first controller.error() should win');
40 }, 'surplus calls to controller.error() should be a no-op');
41
42 promise_test(() => {
43 let controller;
44 const ws = new WritableStream({
45 start(c) {
46 controller = c;
47 }
48 });
49 return ws.abort().then(() => {
50 controller.error(error1);
51 });
52 }, 'controller.error() on errored stream should not throw');
53
54 promise_test(() => {
55 let controller;
56 const ws = new WritableStream({
57 start(c) {
58 controller = c;
59 }
60 });
61 return ws.getWriter().close().then(() => {
62 controller.error(error1);
63 });
64 }, 'controller.error() on closed stream should not throw');