2022-09-21 23:27:13 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								/*
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Copyright  ( c )  2022 ,  Linus  Groh  < linusg @ serenityos . org > 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-26 18:54:24 +13:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  Copyright  ( c )  2023 - 2024 ,  Shannon  Booth  < shannon @ serenityos . org > 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-06 19:02:28 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  Copyright  ( c )  2024 ,  Kenneth  Myhra  < kennethmyhra @ serenityos . org > 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-21 23:27:13 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  SPDX - License - Identifier :  BSD - 2 - Clause 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-03-28 20:01:04 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  <LibJS/Runtime/PromiseCapability.h> 
 
							 
						 
					
						
							
								
									
										
										
											
												LibWeb: Remove unecessary dependence on Window from assorted classes
These classes only needed Window to get at its realm. Pass a realm
directly to construct Crypto, Encoding, HRT, IntersectionObserver,
NavigationTiming, Page, RequestIdleCallback, Selection, Streams, URL,
and XML classes.
											 
										 
										
											2022-09-25 18:11:21 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  <LibWeb/Bindings/Intrinsics.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-27 12:09:58 +12:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  <LibWeb/Bindings/ReadableStreamPrototype.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-06 19:02:28 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  <LibWeb/DOM/AbortSignal.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-21 23:27:13 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								# include  <LibWeb/Streams/AbstractOperations.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-08 12:25:32 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  <LibWeb/Streams/ReadableByteStreamController.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-21 23:27:13 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								# include  <LibWeb/Streams/ReadableStream.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-09 01:26:48 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  <LibWeb/Streams/ReadableStreamBYOBReader.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-28 18:56:11 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  <LibWeb/Streams/ReadableStreamDefaultController.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-28 18:30:22 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  <LibWeb/Streams/ReadableStreamDefaultReader.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-28 19:11:22 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  <LibWeb/Streams/UnderlyingSource.h> 
 
							 
						 
					
						
							
								
									
										
										
											
												LibWeb: Remove unecessary dependence on Window from assorted classes
These classes only needed Window to get at its realm. Pass a realm
directly to construct Crypto, Encoding, HRT, IntersectionObserver,
NavigationTiming, Page, RequestIdleCallback, Selection, Streams, URL,
and XML classes.
											 
										 
										
											2022-09-25 18:11:21 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  <LibWeb/WebIDL/ExceptionOr.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-21 23:27:13 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								namespace  Web : : Streams  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-11-19 19:47:52 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								JS_DEFINE_ALLOCATOR ( ReadableStream ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-21 23:27:13 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								// https://streams.spec.whatwg.org/#rs-constructor
 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-18 21:57:07 +12:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								WebIDL : : ExceptionOr < JS : : NonnullGCPtr < ReadableStream > >  ReadableStream : : construct_impl ( JS : : Realm &  realm ,  Optional < JS : : Handle < JS : : Object > >  const &  underlying_source_object ,  QueuingStrategy  const &  strategy ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-21 23:27:13 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-12 23:21:17 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    auto &  vm  =  realm . vm ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-08-13 13:05:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    auto  readable_stream  =  realm . heap ( ) . allocate < ReadableStream > ( realm ,  realm ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-28 19:11:22 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // 1. If underlyingSource is missing, set it to null.
 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-18 14:01:39 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    auto  underlying_source  =  underlying_source_object . has_value ( )  ?  JS : : Value ( underlying_source_object . value ( ) )  :  JS : : js_null ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-28 19:11:22 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // 2. Let underlyingSourceDict be underlyingSource, converted to an IDL value of type UnderlyingSource.
 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-12 23:21:17 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    auto  underlying_source_dict  =  TRY ( UnderlyingSource : : from_value ( vm ,  underlying_source ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-28 19:11:22 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // 3. Perform ! InitializeReadableStream(this).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // 4. If underlyingSourceDict["type"] is "bytes":
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( underlying_source_dict . type . has_value ( )  & &  underlying_source_dict . type . value ( )  = =  ReadableStreamType : : Bytes )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        // 1. If strategy["size"] exists, throw a RangeError exception.
 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-18 21:57:07 +12:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( strategy . size ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  WebIDL : : SimpleException  {  WebIDL : : SimpleExceptionType : : RangeError ,  " Size strategy not allowed for byte stream " sv  } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-03-28 19:11:22 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        // 2. Let highWaterMark be ? ExtractHighWaterMark(strategy, 0).
 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-18 21:57:07 +12:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        auto  high_water_mark  =  TRY ( extract_high_water_mark ( strategy ,  0 ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-03-28 19:11:22 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        // 3. Perform ? SetUpReadableByteStreamControllerFromUnderlyingSource(this, underlyingSource, underlyingSourceDict, highWaterMark).
 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-18 21:57:07 +12:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        TRY ( set_up_readable_byte_stream_controller_from_underlying_source ( * readable_stream ,  underlying_source ,  underlying_source_dict ,  high_water_mark ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-28 19:11:22 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // 5. Otherwise,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        // 1. Assert: underlyingSourceDict["type"] does not exist.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        VERIFY ( ! underlying_source_dict . type . has_value ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-18 21:57:07 +12:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        // 2. Let sizeAlgorithm be ! ExtractSizeAlgorithm(strategy).
 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-26 18:54:24 +13:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        auto  size_algorithm  =  extract_size_algorithm ( vm ,  strategy ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-28 19:11:22 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-18 21:57:07 +12:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        // 3. Let highWaterMark be ? ExtractHighWaterMark(strategy, 1).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        auto  high_water_mark  =  TRY ( extract_high_water_mark ( strategy ,  1 ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-28 19:11:22 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        // 4. Perform ? SetUpReadableStreamDefaultControllerFromUnderlyingSource(this, underlyingSource, underlyingSourceDict, highWaterMark, sizeAlgorithm).
 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-26 18:54:24 +13:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        TRY ( set_up_readable_stream_default_controller_from_underlying_source ( * readable_stream ,  underlying_source ,  underlying_source_dict ,  high_water_mark ,  size_algorithm ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-28 19:11:22 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  readable_stream ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-21 23:27:13 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
											
												LibWeb: Remove unecessary dependence on Window from assorted classes
These classes only needed Window to get at its realm. Pass a realm
directly to construct Crypto, Encoding, HRT, IntersectionObserver,
NavigationTiming, Page, RequestIdleCallback, Selection, Streams, URL,
and XML classes.
											 
										 
										
											2022-09-25 18:11:21 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								ReadableStream : : ReadableStream ( JS : : Realm &  realm ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    :  PlatformObject ( realm ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-21 23:27:13 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								ReadableStream : : ~ ReadableStream ( )  =  default ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-03-28 20:01:04 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// https://streams.spec.whatwg.org/#rs-locked
 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-18 21:34:41 +12:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								bool  ReadableStream : : locked ( )  const 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-28 20:01:04 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // 1. Return ! IsReadableStreamLocked(this).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  is_readable_stream_locked ( * this ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// https://streams.spec.whatwg.org/#rs-cancel
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								WebIDL : : ExceptionOr < JS : : GCPtr < JS : : Object > >  ReadableStream : : cancel ( JS : : Value  reason ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-12 23:21:17 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    auto &  realm  =  this - > realm ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-03-28 20:01:04 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // 1. If ! IsReadableStreamLocked(this) is true, return a promise rejected with a TypeError exception.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( is_readable_stream_locked ( * this ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-09-06 08:18:01 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        auto  exception  =  JS : : TypeError : : create ( realm ,  " Cannot cancel a locked stream " sv ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-12 23:21:17 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  WebIDL : : create_rejected_promise ( realm ,  JS : : Value  {  exception  } ) - > promise ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-28 20:01:04 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // 2. Return ! ReadableStreamCancel(this, reason).
 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-29 16:45:50 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  readable_stream_cancel ( * this ,  reason ) - > promise ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-28 20:01:04 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// https://streams.spec.whatwg.org/#rs-get-reader
 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-29 20:53:19 +12:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								WebIDL : : ExceptionOr < ReadableStreamReader >  ReadableStream : : get_reader ( ReadableStreamGetReaderOptions  const &  options ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-28 20:01:04 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // 1. If options["mode"] does not exist, return ? AcquireReadableStreamDefaultReader(this).
 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-29 20:53:19 +12:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( ! options . mode . has_value ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-07-26 19:02:37 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  ReadableStreamReader  {  TRY ( acquire_readable_stream_default_reader ( * this ) )  } ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-29 20:53:19 +12:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-03-28 20:01:04 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // 2. Assert: options["mode"] is "byob".
 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-29 20:53:19 +12:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    VERIFY ( * options . mode  = =  Bindings : : ReadableStreamReaderMode : : Byob ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-28 20:01:04 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-29 20:53:19 +12:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // 3. Return ? AcquireReadableStreamBYOBReader(this).
 
							 
						 
					
						
							
								
									
										
										
										
											2023-07-26 19:02:37 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  ReadableStreamReader  {  TRY ( acquire_readable_stream_byob_reader ( * this ) )  } ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-28 20:01:04 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-04-07 13:01:33 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								WebIDL : : ExceptionOr < JS : : NonnullGCPtr < ReadableStream > >  ReadableStream : : pipe_through ( ReadableWritablePair  transform ,  StreamPipeOptions  const &  options ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // 1. If ! IsReadableStreamLocked(this) is true, throw a TypeError exception.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( is_readable_stream_locked ( * this ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  WebIDL : : SimpleException  {  WebIDL : : SimpleExceptionType : : TypeError ,  " Failed to execute 'pipeThrough' on 'ReadableStream': Cannot pipe a locked stream " sv  } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // 2. If ! IsWritableStreamLocked(transform["writable"]) is true, throw a TypeError exception.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( is_writable_stream_locked ( * transform . writable ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  WebIDL : : SimpleException  {  WebIDL : : SimpleExceptionType : : TypeError ,  " Failed to execute 'pipeThrough' on 'ReadableStream': parameter 1's 'writable' is locked " sv  } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // 3. Let signal be options["signal"] if it exists, or undefined otherwise.
 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-07 15:10:36 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    auto  signal  =  options . signal  ?  JS : : Value ( options . signal )  :  JS : : js_undefined ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-07 13:01:33 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // 4. Let promise be ! ReadableStreamPipeTo(this, transform["writable"], options["preventClose"], options["preventAbort"], options["preventCancel"], signal).
 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-29 16:45:50 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    auto  promise  =  readable_stream_pipe_to ( * this ,  * transform . writable ,  options . prevent_close ,  options . prevent_abort ,  options . prevent_cancel ,  signal ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-07 13:01:33 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // 5. Set promise.[[PromiseIsHandled]] to true.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    WebIDL : : mark_promise_as_handled ( * promise ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // 6. Return transform["readable"].
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  JS : : NonnullGCPtr  {  * transform . readable  } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-04-06 19:02:28 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								WebIDL : : ExceptionOr < JS : : NonnullGCPtr < JS : : Object > >  ReadableStream : : pipe_to ( WritableStream &  destination ,  StreamPipeOptions  const &  options ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    auto &  realm  =  this - > realm ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // 1. If ! IsReadableStreamLocked(this) is true, return a promise rejected with a TypeError exception.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( is_readable_stream_locked ( * this ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        auto  promise  =  WebIDL : : create_promise ( realm ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        WebIDL : : reject_promise ( realm ,  promise ,  JS : : TypeError : : create ( realm ,  " Failed to execute 'pipeTo' on 'ReadableStream': Cannot pipe a locked stream " sv ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  promise - > promise ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // 2. If ! IsWritableStreamLocked(destination) is true, return a promise rejected with a TypeError exception.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( is_writable_stream_locked ( destination ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        auto  promise  =  WebIDL : : create_promise ( realm ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        WebIDL : : reject_promise ( realm ,  promise ,  JS : : TypeError : : create ( realm ,  " Failed to execute 'pipeTo' on 'ReadableStream':  Cannot pipe to a locked stream " sv ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  promise - > promise ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // 3. Let signal be options["signal"] if it exists, or undefined otherwise.
 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-07 15:10:36 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    auto  signal  =  options . signal  ?  JS : : Value ( options . signal )  :  JS : : js_undefined ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-06 19:02:28 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // 4. Return ! ReadableStreamPipeTo(this, destination, options["preventClose"], options["preventAbort"], options["preventCancel"], signal).
 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-29 16:45:50 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  readable_stream_pipe_to ( * this ,  destination ,  options . prevent_close ,  options . prevent_abort ,  options . prevent_cancel ,  signal ) - > promise ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-06 19:02:28 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-28 10:28:59 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// https://streams.spec.whatwg.org/#readablestream-tee
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								WebIDL : : ExceptionOr < ReadableStreamPair >  ReadableStream : : tee ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // To tee a ReadableStream stream, return ? ReadableStreamTee(stream, true).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  TRY ( readable_stream_tee ( realm ( ) ,  * this ,  true ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-08-07 08:41:28 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								void  ReadableStream : : initialize ( JS : : Realm &  realm ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-10 06:28:20 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2023-08-07 08:41:28 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    Base : : initialize ( realm ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-16 13:13:08 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    WEB_SET_PROTOTYPE_FOR_INTERFACE ( ReadableStream ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-10 06:28:20 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-21 23:27:13 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								void  ReadableStream : : visit_edges ( Cell : : Visitor &  visitor ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    Base : : visit_edges ( visitor ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-14 08:43:47 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( m_controller . has_value ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        m_controller - > visit ( [ & ] ( auto &  controller )  {  visitor . visit ( controller ) ;  } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-21 23:27:13 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								    visitor . visit ( m_stored_error ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-09 01:26:48 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( m_reader . has_value ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        m_reader - > visit ( [ & ] ( auto &  reader )  {  visitor . visit ( reader ) ;  } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-21 23:27:13 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// https://streams.spec.whatwg.org/#readablestream-locked
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								bool  ReadableStream : : is_readable ( )  const 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // A ReadableStream stream is readable if stream.[[state]] is "readable".
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  m_state  = =  State : : Readable ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// https://streams.spec.whatwg.org/#readablestream-closed
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								bool  ReadableStream : : is_closed ( )  const 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // A ReadableStream stream is closed if stream.[[state]] is "closed".
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  m_state  = =  State : : Closed ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// https://streams.spec.whatwg.org/#readablestream-errored
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								bool  ReadableStream : : is_errored ( )  const 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // A ReadableStream stream is errored if stream.[[state]] is "errored".
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  m_state  = =  State : : Errored ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// https://streams.spec.whatwg.org/#readablestream-locked
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								bool  ReadableStream : : is_locked ( )  const 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // A ReadableStream stream is locked if ! IsReadableStreamLocked(stream) returns true.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  is_readable_stream_locked ( * this ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// https://streams.spec.whatwg.org/#is-readable-stream-disturbed
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								bool  ReadableStream : : is_disturbed ( )  const 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // A ReadableStream stream is disturbed if stream.[[disturbed]] is true.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  m_disturbed ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}