Bug 1561911 - Part 1: Update ReadableStreamReaderGenericInitialize steps. r=jwalden
authorTooru Fujisawa <arai_a@mac.com>
Wed, 04 Dec 2019 09:46:53 +0000
changeset 505290 c4b38fbe9db01dba1b52e02f5b81c135cfd6e63d
parent 505289 6ee737ea06ad42c9c5a5bf06253b49ad16b204af
child 505291 fc547f512ed850b4b618d69890b4fd0885257cac
push id36881
push userdvarga@mozilla.com
push dateWed, 04 Dec 2019 16:22:31 +0000
treeherdermozilla-central@13fb375eaf14 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalden
bugs1561911
milestone73.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1561911 - Part 1: Update ReadableStreamReaderGenericInitialize steps. r=jwalden Differential Revision: https://phabricator.services.mozilla.com/D55613
js/src/builtin/streams/ReadableStreamReader.cpp
--- a/js/src/builtin/streams/ReadableStreamReader.cpp
+++ b/js/src/builtin/streams/ReadableStreamReader.cpp
@@ -65,39 +65,42 @@ MOZ_MUST_USE JSObject* js::ReadableStrea
  * Streams spec, 3.8.4.
  *      ReadableStreamReaderGenericInitialize ( reader, stream )
  */
 MOZ_MUST_USE bool js::ReadableStreamReaderGenericInitialize(
     JSContext* cx, Handle<ReadableStreamReader*> reader,
     Handle<ReadableStream*> unwrappedStream, ForAuthorCodeBool forAuthorCode) {
   cx->check(reader);
 
-  // Step 1: Set reader.[[ownerReadableStream]] to stream.
+  // Step 1: Set reader.[[forAuthorCode]] to true.
+  reader->setForAuthorCode(forAuthorCode);
+
+  // Step 2: Set reader.[[ownerReadableStream]] to stream.
   {
     Rooted<JSObject*> readerCompartmentStream(cx, unwrappedStream);
     if (!cx->compartment()->wrap(cx, &readerCompartmentStream)) {
       return false;
     }
     reader->setStream(readerCompartmentStream);
   }
 
-  // Step 2 is moved to the end.
+  // Step 3 is moved to the end.
 
-  // Step 3: If stream.[[state]] is "readable",
+  // Step 4: If stream.[[state]] is "readable",
   Rooted<JSObject*> promise(cx);
   if (unwrappedStream->readable()) {
     // Step a: Set reader.[[closedPromise]] to a new promise.
     promise = PromiseObject::createSkippingExecutor(cx);
   } else if (unwrappedStream->closed()) {
-    // Step 4: Otherwise, if stream.[[state]] is "closed",
-    // Step a: Set reader.[[closedPromise]] to a new promise resolved with
+    // Step 5: Otherwise, if stream.[[state]] is "closed",
+    // Step a: Set reader.[[closedPromise]] to a promise resolved with
     //         undefined.
     promise = PromiseObject::unforgeableResolve(cx, UndefinedHandleValue);
   } else {
-    // Step 5: Otherwise,
+    // Step 6: Otherwise,
     // Step a: Assert: stream.[[state]] is "errored".
     MOZ_ASSERT(unwrappedStream->errored());
 
     // Step b: Set reader.[[closedPromise]] to a promise rejected with
     //         stream.[[storedError]].
     Rooted<Value> storedError(cx, unwrappedStream->storedError());
     if (!cx->compartment()->wrap(cx, &storedError)) {
       return false;
@@ -113,29 +116,25 @@ MOZ_MUST_USE bool js::ReadableStreamRead
   }
 
   if (!promise) {
     return false;
   }
 
   reader->setClosedPromise(promise);
 
-  // Extra step not in the standard. See the comment on
-  // `ReadableStreamReader::forAuthorCode()`.
-  reader->setForAuthorCode(forAuthorCode);
-
   // Step 4 of caller 3.6.3. new ReadableStreamDefaultReader(stream):
   // Step 5 of caller 3.7.3. new ReadableStreamBYOBReader(stream):
   //     Set this.[[read{Into}Requests]] to a new empty List.
   if (!StoreNewListInFixedSlot(cx, reader,
                                ReadableStreamReader::Slot_Requests)) {
     return false;
   }
 
-  // Step 2: Set stream.[[reader]] to reader.
+  // Step 3: Set stream.[[reader]] to reader.
   // Doing this last prevents a partially-initialized reader from being
   // attached to the stream (and possibly left there on OOM).
   {
     AutoRealm ar(cx, unwrappedStream);
     Rooted<JSObject*> streamCompartmentReader(cx, reader);
     if (!cx->compartment()->wrap(cx, &streamCompartmentReader)) {
       return false;
     }