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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
'use strict';
if (self.importScripts) {
self.importScripts('../resources/test-utils.js');
self.importScripts('/resources/testharness.js');
}
test(() => {
let pipeToArguments;
const thisValue = {
pipeTo() {
pipeToArguments = arguments;
}
};
const input = { readable: {}, writable: {} };
const options = {};
const result = ReadableStream.prototype.pipeThrough.call(thisValue, input, options);
assert_array_equals(pipeToArguments, [input.writable, options],
'correct arguments should be passed to thisValue.pipeTo');
assert_equals(result, input.readable, 'return value should be the passed readable property');
}, 'ReadableStream.prototype.pipeThrough should work generically on its this and its arguments');
test(() => {
const thisValue = {
pipeTo() {
assert_unreached('pipeTo should not be called');
}
};
methodThrows(ReadableStream.prototype, 'pipeThrough', thisValue, [undefined, {}]);
methodThrows(ReadableStream.prototype, 'pipeThrough', thisValue, [null, {}]);
}, 'ReadableStream.prototype.pipeThrough should throw when its first argument is not convertible to an object');
test(() => {
const args = [{ readable: {}, writable: {} }, {}];
methodThrows(ReadableStream.prototype, 'pipeThrough', undefined, args);
methodThrows(ReadableStream.prototype, 'pipeThrough', null, args);
methodThrows(ReadableStream.prototype, 'pipeThrough', 1, args);
methodThrows(ReadableStream.prototype, 'pipeThrough', { pipeTo: 'test' }, args);
}, 'ReadableStream.prototype.pipeThrough should throw when "this" has no pipeTo method');
test(() => {
const error = new Error('potato');
const throwingPipeTo = {
get pipeTo() {
throw error;
}
};
assert_throws(error,
() => ReadableStream.prototype.pipeThrough.call(throwingPipeTo, { readable: { }, writable: { } }, {}),
'pipeThrough should rethrow the error thrown by pipeTo');
const thisValue = {
pipeTo() {
assert_unreached('pipeTo should not be called');
}
};
const throwingWritable = {
readable: {},
get writable() {
throw error;
}
};
assert_throws(error,
() => ReadableStream.prototype.pipeThrough.call(thisValue, throwingWritable, {}),
'pipeThrough should rethrow the error thrown by the writable getter');
const throwingReadable = {
get readable() {
throw error;
},
writable: {}
};
assert_throws(error,
() => ReadableStream.prototype.pipeThrough.call(thisValue, throwingReadable, {}),
'pipeThrough should rethrow the error thrown by the readable getter');
}, 'ReadableStream.prototype.pipeThrough should rethrow errors from accessing pipeTo, readable, or writable');
test(() => {
let count = 0;
const thisValue = {
pipeTo() {
++count;
}
};
ReadableStream.prototype.pipeThrough.call(thisValue, { readable: {}, writable: {} });
ReadableStream.prototype.pipeThrough.call(thisValue, { readable: {} }, {});
ReadableStream.prototype.pipeThrough.call(thisValue, { writable: {} }, {});
assert_equals(count, 3, 'pipeTo was called 3 times');
}, 'ReadableStream.prototype.pipeThrough should work with missing readable, writable, or options');
done();
|