11cb0ef41Sopenharmony_ci// META: global=window,worker
21cb0ef41Sopenharmony_ci'use strict';
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ci// Tests which patch the global environment are kept separate to avoid
51cb0ef41Sopenharmony_ci// interfering with other tests.
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_citest(t => {
81cb0ef41Sopenharmony_ci  // eslint-disable-next-line no-extend-native, accessor-pairs
91cb0ef41Sopenharmony_ci  Object.defineProperty(Object.prototype, 'highWaterMark', {
101cb0ef41Sopenharmony_ci    set() { throw new Error('highWaterMark setter called'); },
111cb0ef41Sopenharmony_ci    configurable: true
121cb0ef41Sopenharmony_ci  });
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci  // eslint-disable-next-line no-extend-native, accessor-pairs
151cb0ef41Sopenharmony_ci  Object.defineProperty(Object.prototype, 'size', {
161cb0ef41Sopenharmony_ci    set() { throw new Error('size setter called'); },
171cb0ef41Sopenharmony_ci    configurable: true
181cb0ef41Sopenharmony_ci  });
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ci  t.add_cleanup(() => {
211cb0ef41Sopenharmony_ci    delete Object.prototype.highWaterMark;
221cb0ef41Sopenharmony_ci    delete Object.prototype.size;
231cb0ef41Sopenharmony_ci  });
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci  assert_not_equals(new TransformStream(), null, 'constructor should work');
261cb0ef41Sopenharmony_ci}, 'TransformStream constructor should not call setters for highWaterMark or size');
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_citest(t => {
291cb0ef41Sopenharmony_ci  const oldReadableStream = ReadableStream;
301cb0ef41Sopenharmony_ci  const oldWritableStream = WritableStream;
311cb0ef41Sopenharmony_ci  const getReader = ReadableStream.prototype.getReader;
321cb0ef41Sopenharmony_ci  const getWriter = WritableStream.prototype.getWriter;
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ci  // Replace ReadableStream and WritableStream with broken versions.
351cb0ef41Sopenharmony_ci  ReadableStream = function () {
361cb0ef41Sopenharmony_ci    throw new Error('Called the global ReadableStream constructor');
371cb0ef41Sopenharmony_ci  };
381cb0ef41Sopenharmony_ci  WritableStream = function () {
391cb0ef41Sopenharmony_ci    throw new Error('Called the global WritableStream constructor');
401cb0ef41Sopenharmony_ci  };
411cb0ef41Sopenharmony_ci  t.add_cleanup(() => {
421cb0ef41Sopenharmony_ci    ReadableStream = oldReadableStream;
431cb0ef41Sopenharmony_ci    WritableStream = oldWritableStream;
441cb0ef41Sopenharmony_ci  });
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_ci  const ts = new TransformStream();
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ci  // Just to be sure, ensure the readable and writable pass brand checks.
491cb0ef41Sopenharmony_ci  assert_not_equals(getReader.call(ts.readable), undefined,
501cb0ef41Sopenharmony_ci                    'getReader should work when called on ts.readable');
511cb0ef41Sopenharmony_ci  assert_not_equals(getWriter.call(ts.writable), undefined,
521cb0ef41Sopenharmony_ci                    'getWriter should work when called on ts.writable');
531cb0ef41Sopenharmony_ci}, 'TransformStream should use the original value of ReadableStream and WritableStream');
54