-
Notifications
You must be signed in to change notification settings - Fork 54
/
constructor.any.js
48 lines (41 loc) · 1.67 KB
/
constructor.any.js
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
// META: global=worker,jsshell
// META: script=../resources/constructor-ordering.js
'use strict';
const operations = [
op('get', 'size'),
op('get', 'highWaterMark'),
op('get', 'type'),
op('validate', 'type'),
op('validate', 'size'),
op('tonumber', 'highWaterMark'),
op('validate', 'highWaterMark'),
op('get', 'pull'),
op('validate', 'pull'),
op('get', 'cancel'),
op('validate', 'cancel'),
op('get', 'autoAllocateChunkSize'),
op('tonumber', 'autoAllocateChunkSize'),
op('validate', 'autoAllocateChunkSize'),
op('get', 'start'),
op('validate', 'start')
];
for (const failureOp of operations) {
test(() => {
const record = new OpRecorder(failureOp);
const underlyingSource = createRecordingObjectWithProperties(record, ['start', 'pull', 'cancel']);
// The valid value for "type" is "bytes", so set it separately.
defineCheckedProperty(record, underlyingSource, 'type', () => record.check('type') ? 'invalid' : 'bytes');
// autoAllocateChunkSize is a special case because it has a tonumber step.
defineCheckedProperty(record, underlyingSource, 'autoAllocateChunkSize',
() => createRecordingNumberObject(record, 'autoAllocateChunkSize'));
const strategy = createRecordingStrategy(record);
try {
new ReadableStream(underlyingSource, strategy);
assert_unreached('constructor should throw');
} catch (e) {
assert_equals(typeof e, 'object', 'e should be an object');
}
assert_equals(record.actual(), expectedAsString(operations, failureOp),
'operations should be performed in the right order');
}, `ReadableStream constructor should stop after ${failureOp} fails`);
}