Overview.htm
changeset 138 6cc871794be1
parent 137 142342673c3f
child 139 ea63ef46f36e
equal deleted inserted replaced
137:142342673c3f 138:6cc871794be1
   453 							<li>Push <var>pendingWrite</var> to <a>pendingWriteQueue</a></li>
   453 							<li>Push <var>pendingWrite</var> to <a>pendingWriteQueue</a></li>
   454 
   454 
   455 							<li><a>Process pendingWriteQueue</a></li>
   455 							<li><a>Process pendingWriteQueue</a></li>
   456 
   456 
   457 							<li>
   457 							<li>
   458 								Run these steps possibly asynchronously:
   458 								Run the steps below possibly asynchronously:
   459 
   459 
   460 								<dl class="switch">
   460 								<dl class="switch">
   461 									<dt>If <var>data</var> is a <a>DOMString</a></dt>
   461 									<dt>If <var>data</var> is a <a>DOMString</a></dt>
   462 									<dd>
   462 									<dd>
   463 										Write <var>data</var> to <a>dataSink</a> together with <var>latchedEncoding</var> as <var>encoding</var> parameter.
   463 										Write <var>data</var> to <a>dataSink</a> together with <var>latchedEncoding</var> as <var>encoding</var> parameter.
   534 					<p>
   534 					<p>
   535 						Once this method has been called on a WritableStream, no further method calls can be made on the WritableStream.
   535 						Once this method has been called on a WritableStream, no further method calls can be made on the WritableStream.
   536 					</p>
   536 					</p>
   537 
   537 
   538 					<p>
   538 					<p>
   539 						This method must run these steps:
   539 						This method must run the steps below:
   540 						<ol>
   540 						<ol>
   541 							<li>Let <var>abortPromise</var> be a newly-created <a>Promise</a></li>
   541 							<li>Let <var>abortPromise</var> be a newly-created <a>Promise</a></li>
   542 							<li>
   542 							<li>
   543 								Run these steps possibly asynchronously:
   543 								Run the steps below possibly asynchronously:
   544 								<ol>
   544 								<ol>
   545 									<li><a>Write-abort</a> <a>dataSink</a> with <var>reason</var></li>
   545 									<li><a>Write-abort</a> <a>dataSink</a> with <var>reason</var></li>
   546 									<li>Wait until <a>dataSink</a> acknowledges the <a>write-abort</a></li>
   546 									<li>Wait until <a>dataSink</a> acknowledges the <a>write-abort</a></li>
   547 									<li>Fulfill <var>abortPromise</var> with <code>undefined</code></li>
   547 									<li>Fulfill <var>abortPromise</var> with <code>undefined</code></li>
   548 								</ol>
   548 								</ol>
   614 				This variable is initialized to <code>null</code> on construction.
   614 				This variable is initialized to <code>null</code> on construction.
   615 			</p>
   615 			</p>
   616 
   616 
   617 			<p>
   617 			<p>
   618 				To <dfn>abort awaitSpace</dfn>, run the steps below:
   618 				To <dfn>abort awaitSpace</dfn>, run the steps below:
       
   619 
   619 				<ol>
   620 				<ol>
   620 					<li>If <a>awaitSpacePromise</a> is <code>null</code>, terminate these steps</li>
   621 					<li>If <a>awaitSpacePromise</a> is <code>null</code>, terminate these steps</li>
   621 					<li>Let <var>detachedWaitPromise</var> be <a>awaitSpacePromise</a></li>
   622 					<li>Let <var>detachedWaitPromise</var> be <a>awaitSpacePromise</a></li>
   622 					<li>Set <a>awaitSpacePromise</a> to <code>null</code></li>
   623 					<li>Set <a>awaitSpacePromise</a> to <code>null</code></li>
   623 					<li>Reject <var>detachedWaitPromise</var> with an "<code><a>AbortError</a></code>"</li>
   624 					<li>Reject <var>detachedWaitPromise</var> with an "<code><a>AbortError</a></code>"</li>
   681 							</li>
   682 							</li>
   682 						</ol>
   683 						</ol>
   683 					</li>
   684 					</li>
   684 
   685 
   685 					<li>
   686 					<li>
   686 						If <a>pendingWriteQueue</a> is empty and <a>spaceAvailable</a> is not 0, run the steps below:
   687 						If <a>pendingWriteQueue</a> is empty and <a>spaceAvailable</a> is not 0 and <a>awaitSpacePromise</a> is not <code>null</code>, run the steps below:
       
   688 
   687 						<ol>
   689 						<ol>
   688 							<li>If <a>awaitSpacePromise</a> is <code>null</code>, terminate these steps</li>
   690 							<li>Let <var>detachedPromise</var> be <a>awaitSpacePromise</a></li>
   689 							<li>Let <var>detachedWaitPromise</var> be <a>awaitSpacePromise</a></li>
       
   690 							<li>Set <a>awaitSpacePromise</a> to <code>null</code></li>
   691 							<li>Set <a>awaitSpacePromise</a> to <code>null</code></li>
   691 							<li>Fulfill <var>detachedWaitPromise</var> with <a>spaceAvailable</a></li>
   692 							<li>Fulfill <var>detachedPromise</var> with <a>spaceAvailable</a></li>
   692 						</ol>
   693 						</ol>
   693 					</li>
   694 					</li>
   694 				</ol>
   695 				</ol>
   695 			</p>
   696 			</p>
   696 
   697 
   739 			Interfaces introduced in this section provide simple and convenient ways to consume data.
   740 			Interfaces introduced in this section provide simple and convenient ways to consume data.
   740 			They connect arbitrary data stream producer and data consuming code using Promises and method invocations.
   741 			They connect arbitrary data stream producer and data consuming code using Promises and method invocations.
   741 		</p>
   742 		</p>
   742 
   743 
   743 		<p>
   744 		<p>
   744 			A ReadableStream has a one-to-one mapping with an associated data source, and has defined semantics for <a href='#interactingWithDataSource'>interacting with the data source internally</a>.
   745 			A ReadableStream has a one-to-one mapping with an associated <a href="#readableByteStreamDataSource">data source</a>, and has defined semantics for <a href='#interactingWithDataSource'>interacting with the data source internally</a>.
   745 			A data source, however, can have a one-to-many relationship with ReadableStreams, in cases where <code>fork()</code> is used.
   746 			A data source, however, can have a one-to-many relationship with ReadableStreams, in cases where <code>fork()</code> is used.
   746 		</p>
   747 		</p>
   747 
   748 
   748 		<section class="section" id="readableByteStreamInterface">
   749 		<section class="section" id="readableByteStreamInterface">
   749 			<h3>ReadableStream interface</h3>
   750 			<h3>ReadableStream interface</h3>
   810 						</ul>
   811 						</ul>
   811 						The <a>cost</a> of data returned by this method can be less than <var>size</var> when data cannot be fully converted into the type specified by <a href="#widl-ReadableStream-readBinaryAs">readBinaryAs</a> or the EOF is reached.
   812 						The <a>cost</a> of data returned by this method can be less than <var>size</var> when data cannot be fully converted into the type specified by <a href="#widl-ReadableStream-readBinaryAs">readBinaryAs</a> or the EOF is reached.
   812 					</p>
   813 					</p>
   813 
   814 
   814 					<p>
   815 					<p>
   815 						This method must run these steps:
   816 						This method must run the steps below:
   816 						<ol>
   817 						<ol>
   817 							<li>If <a href="#widl-ReadableStream-readBinaryAs">readBinaryAs</a> is "<code>as-is</code>", return a <a>Promise</a> rejected with a "<code><a>SyntaxError</a></code>"</li>
   818 							<li>If <a href="#widl-ReadableStream-readBinaryAs">readBinaryAs</a> is "<code>as-is</code>", return a <a>Promise</a> rejected with a "<code><a>SyntaxError</a></code>"</li>
   818 
   819 
   819 							<li>If <a>pendingRead</a> is not <code>null</code>, return a <a>Promise</a> rejected with an "<code><a>InvalidStateError</a></code>"</li>
   820 							<li>If <a>pendingRead</a> is not <code>null</code>, return a <a>Promise</a> rejected with an "<code><a>InvalidStateError</a></code>"</li>
   820 
   821 
   824 
   825 
   825 							<li>Set <a>pendingRead</a>.<var>binaryAs</var> to the current value of <a href="#widl-ReadableStream-readBinaryAs">readBinaryAs</a></li>
   826 							<li>Set <a>pendingRead</a>.<var>binaryAs</var> to the current value of <a href="#widl-ReadableStream-readBinaryAs">readBinaryAs</a></li>
   826 							<li>Set <a>pendingRead</a>.<var>encoding</var> to the current value of <a href="#widl-ReadableStream-readEncoding">readEncoding</a></li>
   827 							<li>Set <a>pendingRead</a>.<var>encoding</var> to the current value of <a href="#widl-ReadableStream-readEncoding">readEncoding</a></li>
   827 							<li>Set <a>pendingRead</a>.<var>size</var> to <var>size</var></li>
   828 							<li>Set <a>pendingRead</a>.<var>size</var> to <var>size</var></li>
   828 							<li>Set <a>pendingRead</a>.<var>promise</var> to <var>readPromise</var></li>
   829 							<li>Set <a>pendingRead</a>.<var>promise</var> to <var>readPromise</var></li>
       
   830 							<li>Set <a>pendingRead</a>.<var>destination</var> to <code>undefined</code></li>
   829 
   831 
   830 							<li>Set <a>readUpToPullAmount</a> to <var>size</var></li>
   832 							<li>Set <a>readUpToPullAmount</a> to <var>size</var></li>
   831 							<li>Set <a>amountBeingReturned</a> to 0</li>
   833 							<li>Set <a>amountBeingReturned</a> to 0</li>
   832 
   834 
   833 							<li><a>Retrieve data</a></li>
   835 							<li><a>Retrieve data</a> possibly asynchronously</li>
   834 
   836 
   835 							<li>Return <var>readPromise</var></li>
   837 							<li>Return <var>readPromise</var></li>
   836 						</ol>
   838 						</ol>
   837 					</p>
   839 					</p>
   838 
   840 
   857 						The speed of reading can be roughly adjusted by using <a href="#widl-StreamReadResult-pullAmount">pullAmount</a>.
   859 						The speed of reading can be roughly adjusted by using <a href="#widl-StreamReadResult-pullAmount">pullAmount</a>.
   858 						<a href="#widl-StreamReadResult-pullAmount">pullAmount</a> doesn't necessarily limit the size of data being read by this method.
   860 						<a href="#widl-StreamReadResult-pullAmount">pullAmount</a> doesn't necessarily limit the size of data being read by this method.
   859 					</p>
   861 					</p>
   860 
   862 
   861 					<p>
   863 					<p>
   862 						This method must run these steps:
   864 						This method must run the steps below:
   863 
   865 
   864 						<ol>
   866 						<ol>
   865 							<li>If <a>pendingRead</a> is not <code>null</code>, return a Promise reject with an "<code><a>InvalidStateError</a></code>"</li>
   867 							<li>If <a>pendingRead</a> is not <code>null</code>, return a Promise reject with an "<code><a>InvalidStateError</a></code>"</li>
   866 
   868 
   867 							<li>Let <var>readPromise</var> be a newly-created <a>Promise</a></li>
   869 							<li>Let <var>readPromise</var> be a newly-created <a>Promise</a></li>
   870 
   872 
   871 							<li>Set <a>pendingRead</a>.<var>binaryAs</var> to the current value of <a href="#widl-ReadableStream-readBinaryAs">readBinaryAs</a></li>
   873 							<li>Set <a>pendingRead</a>.<var>binaryAs</var> to the current value of <a href="#widl-ReadableStream-readBinaryAs">readBinaryAs</a></li>
   872 							<li>Set <a>pendingRead</a>.<var>encoding</var> to the current value of <a href="#widl-ReadableStream-readEncoding">readEncoding</a></li>
   874 							<li>Set <a>pendingRead</a>.<var>encoding</var> to the current value of <a href="#widl-ReadableStream-readEncoding">readEncoding</a></li>
   873 							<li>Set <a>pendingRead</a>.<var>size</var> to <code>undefined</code></li>
   875 							<li>Set <a>pendingRead</a>.<var>size</var> to <code>undefined</code></li>
   874 							<li>Set <a>pendingRead</a>.<var>promise</var> to <var>readPromise</var></li>
   876 							<li>Set <a>pendingRead</a>.<var>promise</var> to <var>readPromise</var></li>
       
   877 							<li>Set <a>pendingRead</a>.<var>destination</var> to <code>undefined</code></li>
   875 
   878 
   876 							<li>Set <a>amountBeingReturned</a> to 0</li>
   879 							<li>Set <a>amountBeingReturned</a> to 0</li>
   877 
   880 
   878 							<li><a>Retrieve data</a></li>
   881 							<li><a>Retrieve data</a> possibly asynchronously</li>
   879 
   882 
   880 							<li>Return <var>readPromise</var></li>
   883 							<li>Return <var>readPromise</var></li>
   881 						</ol>
   884 						</ol>
   882 					</p>
   885 					</p>
   883 
   886 
   910 
   913 
   911 					<p>
   914 					<p>
   912 						This method must run the steps below:
   915 						This method must run the steps below:
   913 
   916 
   914 						<ol>
   917 						<ol>
   915 							<li>If <a>readPending</a> is set, return a <a>Promise</a> rejected with an "<code><a>InvalidStateError</a></code>"</li>
   918 							<li>If <a>pendingRead</a> is not <code>null</code>, return a <a>Promise</a> rejected with an "<code><a>InvalidStateError</a></code>"</li>
   916 							<li>Set <a>readPending</a></li>
   919 
   917 
   920 							<li>Set <var>pipePromise</var> be a newly-created <a>Promise</a></li>
   918 							<li>Run <a>abort awaitSpace</a> algorithm on <var>destination</var></a>
   921 
   919 
   922 							<li>Set <a>pendingRead</a> to a newly-created <a>PendingReadDescriptor</a></li>
   920 							<li>Set <a>amountBeingReturned</a> to 0</li>
   923 
   921 
   924 							<li>Set <a>pendingRead</a>.<var>binaryAs</var> to <code>undefined</code></li>
   922 							<li><a>Retrieve data</a></li>
   925 							<li>Set <a>pendingRead</a>.<var>encoding</var> to <code>undefined</code></li>
   923 
   926 							<li>Set <a>pendingRead</a>.<var>size</var> to <var>size</var> argument</li>
   924 							<li>Let <var>pipePromise</var> be a newly-created <a>Promise</a></li>
   927 							<li>Set <a>pendingRead</a>.<var>promise</var> to <var>pipePromise</var></li>
   925 							<li>Return <var>pipePromise</var>, and then continue to process the steps in this algorithm</li>
   928 							<li>Set <a>pendingRead</a>.<var>destination</var> to <var>destination</var> argument</li>
   926 
   929 
   927 							<li>Let <var>totalAmountTransferred</var> be 0</li>
   930 							<li><a>Wait for destination</a> possibly asynchronously</li>
   928 							<li>
   931 
   929 								Repeat the steps below:
   932 							<li>Return <var>pipePromise</var></li>
   930 								<ul>
       
   931 									<li>
       
   932 										Whenever <a>readDataBuffer</a> is not empty or <a>eofReached</a> is set,
       
   933 										<dl class="switch">
       
   934 											<dt>If this happened in the event loop</dt>
       
   935 											<dd>Run the steps below</dd>
       
   936 											<dt>Otherwise</dt>
       
   937 											<dd>Queue a task which runs the steps below</dd>
       
   938 										</dl>
       
   939 										<ol>
       
   940 											<li>
       
   941 												Let <var>readableAmount</var> be the number of bytes in <a>readDataBuffer</a>
       
   942 												<section class="note">
       
   943 													It's fine to process only part of the bytes, and process the rest in the next task.
       
   944 												</section>
       
   945 											</li>
       
   946 											<li>
       
   947 												<dl class="switch">
       
   948 													<dt>If <var>size</var> is specified</dt>
       
   949 													<dd>Let <var>amountToTransfer</var> be min(<var>size</var> - <var>totalAmountTransferred</var>, <var>readableAmount</var>)</dd>
       
   950 													<dt>Otherwise</dt>
       
   951 													<dd>Let <var>amountToTransfer</var> be <var>readableAmount</var></dd>
       
   952 												</dl>
       
   953 											</li>
       
   954 											<li>Set <a>amountBeingReturned</a> to <a>amountBeingReturned</a> + <var>amountToTransfer</var></li>
       
   955 											<li>Pop <var>amountToTransfer</var> bytes from <a>readDataBuffer</a>, and then write it to <a>dataSink</a> of <var>destination</var></li>
       
   956 
       
   957 											<li>Let <var>pendingWrite</var> be a newly-created <a>PendingWriteDescriptor</a></li>
       
   958 											<li>Set <var>pendingWrite.promise</var> to <code>null</code></li>
       
   959 											<li>Set <var>pendingWrite.amount</var> to <var>amountToTransfer</var></li>
       
   960 											<li>Push <var>pendingWrite</var> to <a>pendingWriteQueue</a> of <var>destination</var></li>
       
   961 
       
   962 											<li>Set <var>totalAmountTransferred</var> to <var>totalAmountTransferred</var> + <var>amountToTransfer</var></li>
       
   963 
       
   964 											<li>
       
   965 												<dl class="switch">
       
   966 													<dt>If <a>eofReached</a> is set</dt>
       
   967 													<dd>Break from this loop</dd>
       
   968 													<dt>If <var>size</var> is specified and <var>totalAmountTransferred</var> equals to <var>size</var></dt>
       
   969 													<dd>Break from this loop</dd>
       
   970 												</dl>
       
   971 												<section class="note">
       
   972 													Need to revisit. Finish when write to the destination completes?
       
   973 												</section>
       
   974 											</li>
       
   975 										</ol>
       
   976 									</li>
       
   977 
       
   978 									<li>
       
   979 										Whenever <a>pendingWriteQueue</a> of <var>destination</var> is empty and <a>spaceAvailable</a> of <var>destination</var> is not 0,
       
   980 										<dl class="switch">
       
   981 											<dt>If this happened in the event loop</dt>
       
   982 											<dd>Run the steps below</dd>
       
   983 											<dt>Otherwise</dt>
       
   984 											<dd>Queue a task which runs the steps below</dd>
       
   985 										</dl>
       
   986 										<ol>
       
   987 											<li>Let <var>destSpaceAvailable</var> be <a>spaceAvailable</a> of <var>destination</var></li>
       
   988 											<li>
       
   989 												<dl class="switch">
       
   990 													<dt>If <var>size</var> is specified</dt>
       
   991 													<dd>
       
   992 														Set <a>pipePullAmount</a> to min(<var>size</var> - <var>totalAmountTransferred</var>, <var>destSpaceAvailable</var>)
       
   993 														<section class="note">
       
   994 															If <a href="#widl-ReadableStream-pullAmount">pullAmount</a> is set to 0, pipe() transfers data in pull style.
       
   995 															I.e. only bytes of the same number as the number of bytes writable to <var>destination</var> are retrieved from the data source.
       
   996 														</section>
       
   997 														<section class="note">
       
   998 															Setting <a href="#widl-ReadableStream-pullAmount">pullAmount</a> to a small value doesn't have an effect of throttling the pace of pipe().
       
   999 														</section>
       
  1000 													</dd>
       
  1001 													<dt>Otherwise</dt>
       
  1002 													<dd>Set <a>pipePullAmount</a> to <var>destSpaceAvailable</var></dd>
       
  1003 												</dl>
       
  1004 											</li>
       
  1005 											<li>Set <a>amountBeingReturned</a> to 0</li>
       
  1006 											<li><a>Retrieve data</a></li>
       
  1007 										</ol>
       
  1008 									</li>
       
  1009 								</ul>
       
  1010 							</li>
       
  1011 
       
  1012 							<li>Set <a>pipePullAmount</a> to 0</li>
       
  1013 
       
  1014 							<li>Unset <a>readPending</a></li>
       
  1015 
       
  1016 							<li>Let <var>result</var> be a newly-created <a>StreamReadResult</a></li>
       
  1017 							<li>Set <var>result</var>.<a href="#widl-StreamReadResult-data">data</a> to <code>undefined</code>.
       
  1018 							<li>Set <var>result</var>.<a href="#widl-StreamReadResult-eof">eof</a> to <code>true</code> if <a>eofReached</a></li>
       
  1019 							<li>Set <var>result</var>.<a href="#widl-StreamReadResult-amountConsumed">amountConsumed</a> to <var>totalAmountTransferred</var></li>
       
  1020 							<li>
       
  1021 								Fulfill <var>pipePromise</var> with <var>result</var>
       
  1022 								<section class="note">
       
  1023 									At this point, <a>amountBeingReturned</a> is not yet reset
       
  1024 								</section>
       
  1025 							</li>
       
  1026 						</ol>
   933 						</ol>
  1027 					</p>
   934 					</p>
  1028 
   935 
  1029 					<dl class="parameters">
   936 					<dl class="parameters">
  1030 						<dt>WritableStream destination</dt>
   937 						<dt>WritableStream destination</dt>
  1061 					<p>
   968 					<p>
  1062 						Once this method has been called on a ReadableStream, no further method calls can be made on the ReadableStream.
   969 						Once this method has been called on a ReadableStream, no further method calls can be made on the ReadableStream.
  1063 					</p>
   970 					</p>
  1064 
   971 
  1065 					<p>
   972 					<p>
  1066 						This method must run these steps:
   973 						This method must run the steps below:
  1067 						<ol>
   974 						<ol>
  1068 							<li>Let <var>abortPromise</var> be a newly-created <a>Promise</a></li>
   975 							<li>Let <var>abortPromise</var> be a newly-created <a>Promise</a></li>
  1069 							<li>
   976 							<li>
  1070 								Run these steps possibly asynchronously:
   977 								Run the steps below possibly asynchronously:
  1071 								<ol>
   978 								<ol>
  1072 									<li><a>Read-abort</a> <a>dataSource</a> with <var>reason</var></li>
   979 									<li><a>Read-abort</a> <a>dataSource</a> with <var>reason</var></li>
  1073 									<li>Wait until <a>dataSource</a> acknowledges the <a>read-abort</a></li>
   980 									<li>Wait until <a>dataSource</a> acknowledges the <a>read-abort</a></li>
  1074 									<li>Fulfill <var>abortPromise</var> with <code>undefined</code></li>
   981 									<li>Fulfill <var>abortPromise</var> with <code>undefined</code></li>
  1075 								</ol>
   982 								</ol>
  1083 
   990 
  1084 		<section class="section" id='readableByteStreamDataSource'>
   991 		<section class="section" id='readableByteStreamDataSource'>
  1085 			<h3>Data source model</h3>
   992 			<h3>Data source model</h3>
  1086 
   993 
  1087 			<p>
   994 			<p>
  1088 				A data source produces the bytes to be consumed via the <a>ReadableStream</a> interface instances.
   995 				A data source produces data stream to be consumed via the <a>ReadableStream</a> interface instances.
  1089 				A <a>ReadableStream</a> retrieves bytes from an associated data source.
   996 				A <a>ReadableStream</a> retrieves data from an associated data source.
  1090 				The data source model is not directly surfaced in the API, and is described here to provide details on how internal operations such as <a href="#widl-ReadableStream-fork-ReadableStream">fork()</a> can be handled.
   997 				The data source model is not directly surfaced in the API, and is described here to provide details on how internal operations such as <a href="#widl-ReadableStream-fork-ReadableStream">fork()</a> can be handled.
  1091 			</p>
   998 			</p>
  1092 
   999 
  1093 			<p>
  1000 			<p>
  1094 				A <dfn>data source</dfn> can be anything that:
  1001 				A <dfn>data source</dfn> can be anything that:
  1095 				<ul>
  1002 				<ul>
  1096 					<li>
  1003 					<li>
  1097 						Produces bytes.
  1004 						Produces data.
  1098 						Newly produced bytes will be delivered to the associated <a>ReadableStream</a>.
  1005 						Newly produced data will be delivered to the associated <a>ReadableStream</a>.
  1099 					</li>
  1006 					</li>
  1100 					<li>
  1007 					<li>
  1101 						Notifies <a>ReadableStream</a> of the EOF signal.
  1008 						Notifies <a>ReadableStream</a> of the <dfn>read EOF</dfn> signal.
  1102 						This signal may mean an error.
  1009 						This signal may include indication of an error.
  1103 						If it means an error, an object indicating the details of the error is attached.
  1010 						When it indicates an error, an object which represents the details of the error is attached.
  1104 					</li>
  1011 					</li>
  1105 					<li>
  1012 					<li>
  1106 						Accepts requests for production of bytes from a <a>ReadableStream</a>.
  1013 						Accepts requests for production of data from a <a>ReadableStream</a>.
  1107 						A byte production request consists of an integer indicating the number of bytes to produce in addition to already requested ones.
  1014 						A data production request consists of an integer indicating the total cost of data to produce in addition to already requested ones.
  1108 						Interpretation of the request is up to data sources.
  1015 						Interpretation of the request is up to each data source.
  1109 						Data sources may respond to retrieval requests with data larger than requested.
  1016 						Data sources may respond to retrieval requests with data larger than requested.
  1110 						Requests and delivery of bytes don't need to 1-to-1 correspond.
  1017 						Requests and delivery of data don't need to 1-to-1 correspond.
  1111 						Data sources may produce bytes and send to <a>ReadableStream</a> unsolicitedly without receiving any retrieval request.
  1018 						Data sources may produce data and send to <a>ReadableStream</a> unsolicitedly without receiving any retrieval request.
  1112 					</li>
  1019 					</li>
  1113 					<li>
  1020 					<li>
  1114 						Accepts and acknowledges read-abort signal which means the associated <a>ReadableStream</a> has completed consuming bytes from this data source optionally with indication of any error.
  1021 						Accepts and acknowledges <dfn>read-abort</dfn> signal which means the associated <a>ReadableStream</a> has completed consuming bytes from this data source optionally with indication of any error.
  1115 					</li>
  1022 					</li>
  1116 				</ul>
  1023 				</ul>
  1117 			</p>
  1024 			</p>
  1118 
  1025 
  1119 			<p>
  1026 			<p>
  1199 				<ul>
  1106 				<ul>
  1200 					<li>A <a>Promise</a> <var>promise</var></li>
  1107 					<li>A <a>Promise</a> <var>promise</var></li>
  1201 					<li>An integer <var>amount</var></li>
  1108 					<li>An integer <var>amount</var></li>
  1202 					<li>A <a>DOMString</a> <var>binaryAs</var></li>
  1109 					<li>A <a>DOMString</a> <var>binaryAs</var></li>
  1203 					<li>A <a>DOMString</a> <var>encoding</var></li>
  1110 					<li>A <a>DOMString</a> <var>encoding</var></li>
       
  1111 					<li>A <a>WritableStream</a> <var>destination</var></li>
  1204 				</ul>
  1112 				</ul>
  1205 			</p>
  1113 			</p>
  1206 
  1114 
  1207 			<p>
  1115 			<p>
  1208 				A WritableStream has an associated <a>PendingReadDescriptor</a> <dfn>pendingRead</dfn>.
  1116 				A WritableStream has an associated <a>PendingReadDescriptor</a> <dfn>pendingRead</dfn>.
  1218 			</p>
  1126 			</p>
  1219 
  1127 
  1220 			<p>
  1128 			<p>
  1221 				To <dfn>retrieve data</dfn>, run the steps below:
  1129 				To <dfn>retrieve data</dfn>, run the steps below:
  1222 				<ol>
  1130 				<ol>
  1223 					<li>Let <var>readableAmount</var> be the number of bytes in the <a>readDataBuffer</a></li>
  1131 					<li>Let <var>readableAmount</var> be sum of the total cost in <a>readDataBuffer</a> and the total number of bytes in <a>binaryReadBuffer</a></li>
  1224 					<li>Let <var>amountToRetrieve</var> be max(max(<a href="#widl-ReadableStream-pullAmount">pullAmount</a>, <a>readUpToPullAmount</a>, <a>pipePullAmount</a>) - (<a>amountRequested</a> + <var>readableAmount</var> + <a>amountBeingReturned</a>), 0)</li>
  1132 					<li>Let <var>amountToRetrieve</var> be max(max(<a href="#widl-ReadableStream-pullAmount">pullAmount</a>, <a>readUpToPullAmount</a>, <a>pipePullAmount</a>) - (<a>amountRequested</a> + <var>readableAmount</var> + <a>amountBeingReturned</a>), 0)</li>
  1225 					<li>Set <a>amountRequested</a> to <a>amountRequested</a> + <var>amountToRetrieve</var></li>
  1133 					<li>Set <a>amountRequested</a> to <a>amountRequested</a> + <var>amountToRetrieve</var></li>
  1226 					<li>Send a request to the <a>dataSource</a> to return <var>amountToRetrieve</var> bytes to the ReadableStream</li>
  1134 					<li>Send a request to the <a>dataSource</a> to return <var>amountToRetrieve</var> bytes to the ReadableStream</li>
  1227 				</ol>
  1135 				</ol>
  1228 			</p>
  1136 			</p>
  1229 
  1137 
  1230 			<p>
  1138 			<p>
  1231 				To <dfn>output data</dfn>, run these steps:
  1139 				To <dfn>splice binary data</dfn> with <var>remainingSize</var> and <var>binaryReadBuffer</var> argument, repeat the steps below while <a>readDataBuffer</a> is not empty:
  1232 
  1140 
  1233 				<ol>
  1141 				<ol>
  1234 					<li>Let <var>result</var> be a newly-created <a>StreamReadResult</a></li>
  1142 					<li>If <a>pendingRead</a>.<var>size</var> is 0, return from this algorithm</li>
  1235 
  1143 
       
  1144 					<li>Let <var>head</var> be the first element in <a>readDataBuffer</a></li>
  1236 					<li>
  1145 					<li>
  1237 						<dl class="switch">
  1146 						<dl class="switch">
  1238 							<dt>If <a>pendingRead<a>.<var>binaryAs</var> is "<code>as-is</code>"</dt>
  1147 							<dt>If <var>head</var> is not an object representing binary data</dt>
  1239 							<dd>
  1148 							<dd>
  1240 								<dl class="switch">
  1149 								<ol>
  1241 									<dt>If <a>pendingRead</a>.<var>size</var> is <code>undefined</code></dt>
  1150 									<li>Let <var>readPromise</var> be <a>pendingRead</a>.<var>promise</var></li>
  1242 									<dd>
  1151 									<li>Set <a>pendingRead</a> to <code>null</code></li>
  1243 										<ol>
  1152 									<li>Reject <var>readPromise</var> with an "<code><a>InvalidStateError</a></code>"</li>
  1244 											<li>Pop one element from <a>readDataBuffer</a>, and set <var>result</var>.<a href="#widl-StreamReadResult-data">data</a> to the element</li>
  1153 									<li>Return from this algorithm with failure</li>
  1245 											<li>Let <var>amountConsumed</var> be <a>cost</a> of the element</li>
  1154 								</ol>
  1246 										</ol>
       
  1247 									</dd>
       
  1248 									<dt>Otherwise</dt>
       
  1249 									<dd>Reject <var>pendingRead.promise</var> with a "<code><a>SyntaxError</a></code>"</dd>
       
  1250 								</dl>
       
  1251 							</dd>
  1155 							</dd>
  1252 
  1156 							<dt>If <a>pendingRead</a>.<var>size</var> is <code>undefined</code></dt>
       
  1157 							<dd>
       
  1158 								<ol>
       
  1159 									<li>Pop <var>head</var> from <a>readDataBuffer</a></li>
       
  1160 									<li>Push <var>head</var> to <a>binaryReadBuffer</a></li>
       
  1161 								</ol>
       
  1162 
       
  1163 								<section class="note">
       
  1164 									Implementations may choose to pop only part of bytes readable if it helps reducing memory copy.
       
  1165 								</section>
       
  1166 							</dd>
       
  1167 							<dt>If the number of bytes in <var>head</var> is not greater than <a>pendingRead</a>.<var>size</var></dt>
       
  1168 							<dd>
       
  1169 								<ol>
       
  1170 									<li>Pop <var>head</var> from <a>readDataBuffer</a></li>
       
  1171 									<li>Push <var>head</var> to <a>binaryReadBuffer</a></li>
       
  1172 									<li>Set <a>pendingRead</a>.<var>size</var> to <a>pendingRead</a>.<var>size</var> - (the number of bytes in <var>head</var>)</li>
       
  1173 								</ol>
       
  1174 							</dd>
  1253 							<dt>Otherwise</dt>
  1175 							<dt>Otherwise</dt>
  1254 							<dd>
  1176 							<dd>
  1255 								<ol>
  1177 								<ol>
  1256 									<li>Let <var>temporaryBuffer</var> be an empty queue</li>
  1178 									<li>Split <var>head</var> into two elements <var>first</var> and <var>last</var> where the number of bytes in <var>first</var> is <a>pendingRead</a>.<var>size</var></li>
  1257 									<li>Let <var>remainingSize</var> be <code>undefined</code></li>
  1179 									<li>Replace <var>head</var> in <a>readDataBuffer</a> with <var>last</var></li>
  1258 									<li>If <a>pendingRead</a>.<var>size</var> is <code>undefined</code>, set <var>remainingSize</var> to <var>pendingRead.size</var></li>
  1180 									<li>Push <var>first</var> to <var>binaryReadBuffer</var></li>
  1259 									<li>
  1181 									<li>Set <a>pendingRead</a>.<var>size</var> to 0</li>
  1260 										<dl class="switch">
  1182 								</ol>
  1261 											<dd>
  1183 							</dd>
  1262 												Repeat these steps while <a>readDataBuffer</a> is not empty:
  1184 						</dl>
  1263 												<ol>
  1185 					</li>
  1264 													<li>Let <var>head</var> be the first element in <a>readDataBuffer</a></li>
  1186 				</ol>
  1265 													<li>
  1187 			</p>
  1266 														<dl class="switch">
  1188 
  1267 															<dt>If <var>remainingSize</var> is 0</dt>
  1189 			<p>
  1268 															<dd>
  1190 				To <dfn>output data</dfn>, run the steps below:
  1269 																Exit from this loop
  1191 
  1270 															</dd>
  1192 				<ol>
  1271 															<dt>If <var>head</var> is not an object representing binary data</dt>
  1193 					<li>Let <var>result</var> be a newly-created <a>StreamReadResult</a></li>
  1272 															<dd>
  1194 
  1273 																<ol>
  1195 					<li>
  1274 																	<li>Reject <var>pendingRead.promise</var> with an "<code><a>InvalidStateError</a></code>"</li>
  1196 						<dl class="switch">
  1275 																	<li>Exit from this loop</li>
  1197 							<dt>If <a>pendingRead</a>.<var>binaryAs</var> is "<code>as-is</code>"</dt>
  1276 																</ol>
  1198 							<dd>
  1277 															</dd>
  1199 								<ol>
  1278 															<dt>If <var>remainingSize</var> is <code>undefined</code></dt>
  1200 									<li>Pop one element from <a>readDataBuffer</a>, and set <var>result</var>.<a href="#widl-StreamReadResult-data">data</a> to the element</li>
  1279 															<dd>
  1201 									<li>Let <var>amountConsumed</var> be <a>cost</a> of the element</li>
  1280 																<ol>
  1202 								</ol>
  1281 																	<li>Pop <var>head</var> from <a>readDataBuffer</a></li>
  1203 							</dd>
  1282 																	<li>Push <var>head</var> to <var>temporaryBuffer</var></li>
  1204 
  1283 																</ol>
  1205 							<dt>Otherwise</dt>
  1284 
  1206 							<dd>
  1285 																<section class="note">
  1207 								<ol>
  1286 																	Implementations may choose to pop only part of bytes readable if it helps reducing memory copy.
  1208 									<li><a>Splice binary data</a></li>
  1287 																</section>
  1209 									<li>If the last step failed, terminate these steps</li>
  1288 															</dd>
  1210 
  1289 															<dt>If <var>remainingSize</var> is not <code>undefined</code> and <a>cost</a> of <var>head</var> is not greater than <var>remainingSize</var></dt>
  1211 									<li>If <a>pendingRead</a>.<var>size</var> is not <code>undefined</code> and <a>eofReached</a> is not set and the number of bytes in <a>binaryReadBuffer</a> is less than <a>pendingRead</a>.<var>size</var>, terminate these steps</li>
  1290 															<dd>
       
  1291 																<ol>
       
  1292 																	<li>Pop <var>head</var> from <a>readDataBuffer</a></li>
       
  1293 																	<li>Push <var>head</var> to <var>temporaryBuffer</var></li>
       
  1294 																	<li>Set <var>remainingSize</var> to <var>remainingSize</var> - (<a>cost</a> of <var>head</var>)</li>
       
  1295 																</ol>
       
  1296 															</dd>
       
  1297 															<dt>Otherwise</dt>
       
  1298 															<dd>
       
  1299 																<ol>
       
  1300 																	<li>Split <var>head</var> into two elements <var>first</var> and <var>last</var> where size of <var>first</var> is <var>remainingSize</var></li>
       
  1301 																	<li>Replace <var>head</var> in <a>readDataBuffer</a> with <var>last</var></li>
       
  1302 																	<li>Push <var>first</var> to <var>temporaryBuffer</var></li>
       
  1303 																	<li>Set <var>remainingSize</var> to 0</li>
       
  1304 																</ol>
       
  1305 															</dd>
       
  1306 														</dl>
       
  1307 													</li>
       
  1308 												</ol>
       
  1309 											</dd>
       
  1310 											<dt>Otherwise</dt>
       
  1311 											<dd>
       
  1312 												
       
  1313 											</dd>
       
  1314 										</dl>
       
  1315 									</li>
       
  1316 
  1212 
  1317 									<li>
  1213 									<li>
  1318 										<dl class="switch">
  1214 										<dl class="switch">
  1319 											<dt>If <a>pendingRead</a>.<var>binaryAs</var> is "<code>arraybuffer</code>"</dt>
  1215 											<dt>If <a>pendingRead</a>.<var>binaryAs</var> is "<code>arraybuffer</code>"</dt>
  1320 											<dd>
  1216 											<dd>
  1326 											<dt>If <a>pendingRead</a>.<var>binaryAs</var> is "<code>text</code>"</dt>
  1222 											<dt>If <a>pendingRead</a>.<var>binaryAs</var> is "<code>text</code>"</dt>
  1327 											<dd>
  1223 											<dd>
  1328 												<ol>
  1224 												<ol>
  1329 													<li>Set <var>result</var>.<a href="#widl-StreamReadResult-data">data</a> to a DOMString that is the result of decoding as many bytes in <var>temporaryBuffer</var> as possible using <var>pendingRead.encoding</var></li>
  1225 													<li>Set <var>result</var>.<a href="#widl-StreamReadResult-data">data</a> to a DOMString that is the result of decoding as many bytes in <var>temporaryBuffer</var> as possible using <var>pendingRead.encoding</var></li>
  1330 													<li>Let <var>unusedBytes</var> be the bytes in <var>temporaryBuffer</var> which were not used in the step 1</li>
  1226 													<li>Let <var>unusedBytes</var> be the bytes in <var>temporaryBuffer</var> which were not used in the step 1</li>
  1331 													<li>If <a>eofReached</a> is set and <var>unusedBytes</var> is not empty, reject <var>pendingRead.promise</var> with "<code><a>EncodingError</a></code>"</li>
  1227 													<li>
       
  1228 														If <a>eofReached</a> is set and <var>unusedBytes</var> is not empty, run the steps below:
       
  1229 														<ol>
       
  1230 															<li>Let <var>readPromise</var> be <a>pendingRead</a>.<var>promise</var></li>
       
  1231 															<li>Set <a>pendingRead</a> to <code>null</code></li>
       
  1232 															<li>Reject <var>readPromise</var> with "<code><a>EncodingError</a></code>"</li>
       
  1233 														</ol>
       
  1234 													</li>
  1332 													<li>Prepend <var>unusedBytes</var> to <a>readDataBuffer</a></li>
  1235 													<li>Prepend <var>unusedBytes</var> to <a>readDataBuffer</a></li>
  1333 													<li>Let <var>amountConsumed</var> be the number of bytes in <var>temporaryBuffer</var> used in the step 1</li>
  1236 													<li>Let <var>amountConsumed</var> be the number of bytes in <var>temporaryBuffer</var> used in the step 1</li>
  1334 												</ol>
  1237 												</ol>
  1335 											</dd>
  1238 											</dd>
  1336 											<dt>If <a>pendingRead</a>.<var>binaryAs</var> is "<code>none</code>"</dt>
  1239 											<dt>If <a>pendingRead</a>.<var>binaryAs</var> is "<code>none</code>"</dt>
  1361 					<li>Fulfill <var>readPromise</var> with <var>result</var></li>
  1264 					<li>Fulfill <var>readPromise</var> with <var>result</var></li>
  1362 				</ol>
  1265 				</ol>
  1363 			</p>
  1266 			</p>
  1364 
  1267 
  1365 			<p>
  1268 			<p>
  1366 				When data is received from <a>dataSource</a>, queue a task which runs the steps below:
  1269 				To <dfn>wait for destination</dfn>, run the steps below:
       
  1270 
       
  1271 				<ol>
       
  1272 					<li>
       
  1273 						Let <var>onFulfilled</var> be a callback which runs the steps below:
       
  1274 
       
  1275 						<ol>
       
  1276 							<li>Let <var>space</var> be the first argument</li>
       
  1277 							<li>
       
  1278 								<dl class="switch">
       
  1279 									<dt>If <a>pendingRead</a>.<var>size</var> is specified</dt>
       
  1280 									<dd>
       
  1281 										Set <a>pipePullAmount</a> to min(<a>pendingRead</a>.<var>size</var>, <var>space</var>)
       
  1282 
       
  1283 										<section class="note">
       
  1284 											If <a href="#widl-ReadableStream-pullAmount">pullAmount</a> is set to 0, pipe() transfers data in pull style.
       
  1285 											I.e. only bytes of the same number as the number of bytes writable to <var>destination</var> are retrieved from the data source.
       
  1286 										</section>
       
  1287 										<section class="note">
       
  1288 											Setting <a href="#widl-ReadableStream-pullAmount">pullAmount</a> to a small value doesn't have an effect of throttling the pace of pipe().
       
  1289 										</section>
       
  1290 									</dd>
       
  1291 									<dt>Otherwise</dt>
       
  1292 									<dd>Set <a>pipePullAmount</a> to <var>space</var></dd>
       
  1293 								</dl>
       
  1294 							</li>
       
  1295 							<li>Set <a>amountBeingReturned</a> to 0</li>
       
  1296 							<li><a>Retrieve data</a></li>
       
  1297 						</ol>
       
  1298 					</li>
       
  1299 
       
  1300 					<li>
       
  1301 						Run the algorithm of <code>awaitSpaceAvailable()</code> method on <var>destination</var>, and let <var>promise</var> be the returned <a>Promise</a>
       
  1302 					</li>
       
  1303 					<li>
       
  1304 						Transform <var>promise</var> of <var>destination</var> with <var>onFulfilled</var> and <code>undefined</code>
       
  1305 					</li>
       
  1306 				</ol>
       
  1307 			</p>
       
  1308 
       
  1309 			<p>
       
  1310 				To <dfn>transfer data</dfn>, run the steps below:
       
  1311 
       
  1312 				<ol>
       
  1313 					<li>
       
  1314 						Let <var>onFulfilled</var> be a callback which runs the steps below:
       
  1315 
       
  1316 						<dl class="switch">
       
  1317 							<dt>If <a>eofReached</a> is set or <a>pendingRead</a>.<var>size</var> is 0</dt>
       
  1318 							<dd>
       
  1319 								<ol>
       
  1320 									<li>Set <a>pipePullAmount</a> to 0</li>
       
  1321 
       
  1322 									<li>Unset <a>readPending</a></li>
       
  1323 
       
  1324 									<li>Let <var>result</var> be a newly-created <a>StreamReadResult</a></li>
       
  1325 
       
  1326 									<li>Set <var>result</var>.<a href="#widl-StreamReadResult-data">data</a> to <code>undefined</code>.
       
  1327 									<li>Set <var>result</var>.<a href="#widl-StreamReadResult-eof">eof</a> to <code>true</code> if <a>eofReached</a></li>
       
  1328 									<li>Set <var>result</var>.<a href="#widl-StreamReadResult-amountConsumed">amountConsumed</a> to <var>totalAmountTransferred</var></li>
       
  1329 									<li>
       
  1330 										Fulfill <var>pipePromise</var> with <var>result</var>
       
  1331 										<section class="note">
       
  1332 											At this point, <a>amountBeingReturned</a> is not yet reset
       
  1333 										</section>
       
  1334 									</li>
       
  1335 								</ol>
       
  1336 								<section class="note">
       
  1337 									Need to revisit. Finish when write to the destination completes?
       
  1338 								</section>
       
  1339 							</dd>
       
  1340 							<dt>Otherwise</dt>
       
  1341 							<dd>
       
  1342 							</dd>
       
  1343 						</dl>
       
  1344 					</li>
       
  1345 
       
  1346 					<li>
       
  1347 						<dl class="switch">
       
  1348 							<dt>If <a>pendingRead</a>.<var>size</var> is <code>undefined</code></dt>
       
  1349 							<dd>
       
  1350 								<ol>
       
  1351 									<li>Let <var>writePromises</var> be an array of <a>Promise</a>s.
       
  1352 									<li>
       
  1353 										Repeat the steps below while <a>readDataBuffer</a> is not empty:
       
  1354 										<ol>
       
  1355 											<li>Pop one element from <a>readDataBuffer</a>, and let <var>head</var> be the element</li>
       
  1356 											<li>Set <a>amountBeingReturned</a> to <a>amountBeingReturned</a> + (<a>cost</a> of <var>head</var>)</li>
       
  1357 											<li>Run the algorithm of write() method with <var>head</var> on <a>pendingRead</a>.<var>destination</var></li>
       
  1358 											<li>Push the <a>Promise</a> returned by the last step to <var>writePromises</var></li>
       
  1359 										</ol>
       
  1360 									</li>
       
  1361 
       
  1362 									<li>Let <var>allPromise</var> be waiting for all of <var>writePromises</var></li>
       
  1363 									<li>Transform <var>allPromise</var> with <var>onFulfilled</var> and <code>undefined</code></li>
       
  1364 								</ol>
       
  1365 							</dd>
       
  1366 							<dt>Otherwise</dt>
       
  1367 							<dd>
       
  1368 								<ol>
       
  1369 									<li><a>Splice binary data</a></li>
       
  1370 									<li>If the last step failed, terminate these steps</li>
       
  1371 
       
  1372 									<li>
       
  1373 										Repeat the steps below while <a>binaryReadBuffer</a> is not empty:
       
  1374 
       
  1375 										<ol>
       
  1376 											<li>Pop one element from <a>binaryReadBuffer</a>, and let <var>head</var> be the element</li>
       
  1377 											<li>Run the algorithm of write() method with <var>head</var> to <a>pendingRead</a>.<var>destination</var></li>
       
  1378 										</ol>
       
  1379 									</li>
       
  1380 								</ol>
       
  1381 							</dd>
       
  1382 						</dl>
       
  1383 					</li>
       
  1384 				</ol>
       
  1385 			</p>
       
  1386 
       
  1387 			<p>
       
  1388 				When data is received from <a>dataSource</a>, run the steps below (if not in the event loop, queue a task which runs the steps below):
  1367 				<ol>
  1389 				<ol>
  1368 					<li>Let <var>receivedData</var> be the received bytes</li>
  1390 					<li>Let <var>receivedData</var> be the received bytes</li>
  1369 					<li>Let <var>receivedAmount</var> be the size of <var>receivedData</var></li>
  1391 					<li>Let <var>receivedAmount</var> be the size of <var>receivedData</var></li>
  1370 					<li>Set <a>amountRequested</a> to <a>amountRequested</a> - <var>receivedAmount</var></li>
  1392 					<li>Set <a>amountRequested</a> to <a>amountRequested</a> - <var>receivedAmount</var></li>
  1371 					<li>Push <var>receivedData</var> to <a>readDataBuffer</a></li>
  1393 					<li>Push <var>receivedData</var> to <a>readDataBuffer</a></li>
  1372 
  1394 
  1373 					<li>
  1395 					<li>If <a>pendingRead</a> is <code>null</code>, terminate these steps</li>
  1374 						If <a>pendingRead</a> is not null, <a>output data</a>
  1396 					<li>
       
  1397 						<dl class="switch">
       
  1398 							<dt>If <a>pendingRead</a>.<var>destination</var> is <code>null</code></dt>
       
  1399 							<dd><a>Output data</a></dd>
       
  1400 							<dt>Otherwise</dt>
       
  1401 							<dd><a>Transfer data</a></dd>
       
  1402 						</dl>
  1375 					</li>
  1403 					</li>
  1376 				</ol>
  1404 				</ol>
  1377 			</p>
  1405 			</p>
  1378 
  1406 
  1379 			<p>
  1407 			<p>
  1529 							This method must act as follows:
  1557 							This method must act as follows:
  1530 
  1558 
  1531 							<dl class="switch">
  1559 							<dl class="switch">
  1532 								<dt>If <var>stream</var> is non-null and in scope of the global object's URL property from which this static method is called</dt>
  1560 								<dt>If <var>stream</var> is non-null and in scope of the global object's URL property from which this static method is called</dt>
  1533 								<dd>
  1561 								<dd>
  1534 									Run these steps:
  1562 									Run the steps below:
  1535 									<ol>
  1563 									<ol>
  1536 										<li>If <a>readPending</a> of <var>stream</var> is set, return null</li>
  1564 										<li>If <a>readPending</a> of <var>stream</var> is set, return null</li>
  1537 										<li>Set <a>readPending</a> of <var>stream</var></li>
  1565 										<li>Set <a>readPending</a> of <var>stream</var></li>
  1538 										<li>Return a unique <code>Blob URI</code> that can be used to dereference <var>stream</var></li>
  1566 										<li>Return a unique <code>Blob URI</code> that can be used to dereference <var>stream</var></li>
  1539 										<li>Add an entry to the Blob URL Store for this Blob URL</li>
  1567 										<li>Add an entry to the Blob URL Store for this Blob URL</li>
  1563 							This method must act as follows:
  1591 							This method must act as follows:
  1564 
  1592 
  1565 							<dl class="switch">
  1593 							<dl class="switch">
  1566 								<dt>If <var>stream</var> is non-null and in scope of the global object's URL property from which this static method is called</dt>
  1594 								<dt>If <var>stream</var> is non-null and in scope of the global object's URL property from which this static method is called</dt>
  1567 								<dd>
  1595 								<dd>
  1568 									Run these steps:
  1596 									Run the steps below:
  1569 									<ol>
  1597 									<ol>
  1570 										<li>If <a>readPending</a> of <var>stream</var> is set, return null</li>
  1598 										<li>If <a>readPending</a> of <var>stream</var> is set, return null</li>
  1571 										<li>Set <a>readPending</a> of <var>stream</var></li>
  1599 										<li>Set <a>readPending</a> of <var>stream</var></li>
  1572 										<li>Return a unique <code>Blob URI</code> that can be used to dereference <var>stream</var></li>
  1600 										<li>Return a unique <code>Blob URI</code> that can be used to dereference <var>stream</var></li>
  1573 										<li>Add an entry to the Blob URL Store for this Blob URL</li>
  1601 										<li>Add an entry to the Blob URL Store for this Blob URL</li>
  1792 
  1820 
  1793 		<p>
  1821 		<p>
  1794 			<dfn>AbortError</dfn> is defined in <a href="https://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#aborterror">DOM4 specification</a>.
  1822 			<dfn>AbortError</dfn> is defined in <a href="https://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#aborterror">DOM4 specification</a>.
  1795 			<dfn>InvalidStateError</dfn> is defined in <a href="https://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#invalidstateerror">DOM4 specification</a>.
  1823 			<dfn>InvalidStateError</dfn> is defined in <a href="https://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#invalidstateerror">DOM4 specification</a>.
  1796 			<dfn>SyntaxError</dfn> is defined in <a href="https://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#syntaxerror">DOM4 specification</a>.
  1824 			<dfn>SyntaxError</dfn> is defined in <a href="https://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#syntaxerror">DOM4 specification</a>.
       
  1825 			<dfn>EncodingError</dfn> is defined in <a href="https://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#encodingerror">DOM4 specification</a>.
  1797 		</p>
  1826 		</p>
  1798 	</section>
  1827 	</section>
  1799 
  1828 
  1800 	<section class="section" id="requirements">
  1829 	<section class="section" id="requirements">
  1801 		<h2>Requirements and Use Cases</h2>
  1830 		<h2>Requirements and Use Cases</h2>