/
brand-checks.js
79 lines (64 loc) · 2.62 KB
/
brand-checks.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
71
72
73
74
75
76
77
78
79
'use strict';
if (self.importScripts) {
self.importScripts('/resources/testharness.js');
self.importScripts('../resources/test-utils.js');
}
const TransformStreamDefaultController = getTransformStreamDefaultControllerConstructor();
function getTransformStreamDefaultControllerConstructor() {
return realTSDefaultController().constructor;
}
function fakeTS() {
return Object.setPrototypeOf({
get readable() { return new ReadableStream(); },
get writable() { return new WritableStream(); }
}, TransformStream.prototype);
}
function realTS() {
return new TransformStream();
}
function fakeTSDefaultController() {
return Object.setPrototypeOf({
get desiredSize() { return 1; },
enqueue() { },
close() { },
error() { }
}, TransformStreamDefaultController.prototype);
}
function realTSDefaultController() {
let controller;
new TransformStream({
start(c) {
controller = c;
}
});
return controller;
}
test(() => {
getterThrowsForAll(TransformStream.prototype, 'readable',
[fakeTS(), realTSDefaultController(), undefined, null]);
}, 'TransformStream.prototype.readable enforces a brand check');
test(() => {
getterThrowsForAll(TransformStream.prototype, 'writable',
[fakeTS(), realTSDefaultController(), undefined, null]);
}, 'TransformStream.prototype.writable enforces a brand check');
test(() => {
constructorThrowsForAll(TransformStreamDefaultController,
[fakeTS(), realTS(), realTSDefaultController(), undefined, null]);
}, 'TransformStreamDefaultConstructor enforces a brand check and doesn\'t permit independent construction');
test(() => {
getterThrowsForAll(TransformStreamDefaultController.prototype, 'desiredSize',
[fakeTSDefaultController(), realTS(), undefined, null]);
}, 'TransformStreamDefaultController.prototype.desiredSize enforces a brand check');
test(() => {
methodThrowsForAll(TransformStreamDefaultController.prototype, 'enqueue',
[fakeTSDefaultController(), realTS(), undefined, null]);
}, 'TransformStreamDefaultController.prototype.enqueue enforces a brand check');
test(() => {
methodThrowsForAll(TransformStreamDefaultController.prototype, 'terminate',
[fakeTSDefaultController(), realTS(), undefined, null]);
}, 'TransformStreamDefaultController.prototype.terminate enforces a brand check');
test(() => {
methodThrowsForAll(TransformStreamDefaultController.prototype, 'error',
[fakeTSDefaultController(), realTS(), undefined, null]);
}, 'TransformStreamDefaultController.prototype.error enforces a brand check');
done();