gecko-dev/testing/web-platform/tests/streams/transform-streams/patched-global.any.js
Jason Orendorff 47519c94b2 Bug 1513570 - Part 1: Adapt stream tests to run in the shell. r=Ms2ger
We don't support byte streams, transform streams, writable streams, or piping
yet, but we will, and in the meantime our own meta files disable those tests
for us.

Differential Revision: https://phabricator.services.mozilla.com/D14314

--HG--
extra : moz-landing-system : lando
2018-12-14 18:14:56 +00:00

45 lines
1.7 KiB
JavaScript

// META: global=worker,jsshell
'use strict';
// Tests which patch the global environment are kept separate to avoid interfering with other tests.
// eslint-disable-next-line no-extend-native, accessor-pairs
Object.defineProperty(Object.prototype, 'highWaterMark', {
set() { throw new Error('highWaterMark setter called'); }
});
// eslint-disable-next-line no-extend-native, accessor-pairs
Object.defineProperty(Object.prototype, 'size', {
set() { throw new Error('size setter called'); }
});
test(() => {
assert_not_equals(new TransformStream(), null, 'constructor should work');
}, 'TransformStream constructor should not call setters for highWaterMark or size');
test(t => {
const oldReadableStream = ReadableStream;
const oldWritableStream = WritableStream;
const getReader = ReadableStream.prototype.getReader;
const getWriter = WritableStream.prototype.getWriter;
// Replace ReadableStream and WritableStream with broken versions.
ReadableStream = function () {
throw new Error('Called the global ReadableStream constructor');
};
WritableStream = function () {
throw new Error('Called the global WritableStream constructor');
};
t.add_cleanup(() => {
ReadableStream = oldReadableStream;
WritableStream = oldWritableStream;
});
const ts = new TransformStream();
// Just to be sure, ensure the readable and writable pass brand checks.
assert_not_equals(getReader.call(ts.readable), undefined,
'getReader should work when called on ts.readable');
assert_not_equals(getWriter.call(ts.writable), undefined,
'getWriter should work when called on ts.writable');
}, 'TransformStream should use the original value of ReadableStream and WritableStream');