Debian Codegraph @

testing/web-platform/tests/streams/transform-streams/patched-global.any.js

raw
1 // META: global=window,worker,shadowrealm
2 'use strict';
3
4 // Tests which patch the global environment are kept separate to avoid
5 // interfering with other tests.
6
7 test(t => {
8 // eslint-disable-next-line no-extend-native, accessor-pairs
9 Object.defineProperty(Object.prototype, 'highWaterMark', {
10 set() { throw new Error('highWaterMark setter called'); },
11 configurable: true
12 });
13
14 // eslint-disable-next-line no-extend-native, accessor-pairs
15 Object.defineProperty(Object.prototype, 'size', {
16 set() { throw new Error('size setter called'); },
17 configurable: true
18 });
19
20 t.add_cleanup(() => {
21 delete Object.prototype.highWaterMark;
22 delete Object.prototype.size;
23 });
24
25 assert_not_equals(new TransformStream(), null, 'constructor should work');
26 }, 'TransformStream constructor should not call setters for highWaterMark or size');
27
28 test(t => {
29 const oldReadableStream = ReadableStream;
30 const oldWritableStream = WritableStream;
31 const getReader = ReadableStream.prototype.getReader;
32 const getWriter = WritableStream.prototype.getWriter;
33
34 // Replace ReadableStream and WritableStream with broken versions.
35 ReadableStream = function () {
36 throw new Error('Called the global ReadableStream constructor');
37 };
38 WritableStream = function () {
39 throw new Error('Called the global WritableStream constructor');
40 };
41 t.add_cleanup(() => {
42 ReadableStream = oldReadableStream;
43 WritableStream = oldWritableStream;
44 });
45
46 const ts = new TransformStream();
47
48 // Just to be sure, ensure the readable and writable pass brand checks.
49 assert_not_equals(getReader.call(ts.readable), undefined,
50 'getReader should work when called on ts.readable');
51 assert_not_equals(getWriter.call(ts.writable), undefined,
52 'getWriter should work when called on ts.writable');
53 }, 'TransformStream should use the original value of ReadableStream and WritableStream');