-
Notifications
You must be signed in to change notification settings - Fork 54
/
garbage-collection.any.js
70 lines (47 loc) · 1.68 KB
/
garbage-collection.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// META: global=worker,jsshell
// META: script=../resources/test-utils.js
'use strict';
promise_test(() => {
let controller;
new ReadableStream({
start(c) {
controller = c;
}
});
garbageCollect();
return delay(50).then(() => {
controller.close();
assert_throws_js(TypeError, () => controller.close(), 'close should throw a TypeError the second time');
controller.error();
});
}, 'ReadableStreamController methods should continue working properly when scripts lose their reference to the ' +
'readable stream');
promise_test(() => {
let controller;
const closedPromise = new ReadableStream({
start(c) {
controller = c;
}
}).getReader().closed;
garbageCollect();
return delay(50).then(() => controller.close()).then(() => closedPromise);
}, 'ReadableStream closed promise should fulfill even if the stream and reader JS references are lost');
promise_test(t => {
const theError = new Error('boo');
let controller;
const closedPromise = new ReadableStream({
start(c) {
controller = c;
}
}).getReader().closed;
garbageCollect();
return delay(50).then(() => controller.error(theError))
.then(() => promise_rejects_exactly(t, theError, closedPromise));
}, 'ReadableStream closed promise should reject even if stream and reader JS references are lost');
promise_test(() => {
const rs = new ReadableStream({});
rs.getReader();
garbageCollect();
return delay(50).then(() => assert_throws_js(TypeError, () => rs.getReader(),
'old reader should still be locking the stream even after garbage collection'));
}, 'Garbage-collecting a ReadableStreamDefaultReader should not unlock its stream');