Re: [whatwg/streams] add @@asyncIterator to ReadableStreamDefaultReader (#950)

mcollina commented on this pull request.



> +</emu-alg>
+
+<h5 id="default-reader-@@asynciterator" for="ReadableStreamDefaultReader">[@@asyncIterator]()</h5>
+
+<div class="note">
+  The <code>@@asyncIterator</code> method is an alias of {{ReadableStreamDefaultReader/iterator}}.
+</div>
+
+<emu-alg>
+  1. Let _iterator_ be ? GetMethod(*this*, "iterator").
+  1. Return ? Call(_iterator_, *this*).
+</emu-alg>
+
+<h3 id="default-reader-asynciterator-prototype" interface lt="ReadableStreamDefaultReaderAsyncIteratorPrototype">
+  ReadableStreamDefaultReaderAsyncIteratorPrototype
+</h3>

is this a must for implementers? Or is it how things are spec'ed?

> @@ -1402,6 +1405,87 @@ lt="ReadableStreamDefaultReader(stream)">new ReadableStreamDefaultReader(<var>st
   1. Perform ! ReadableStreamReaderGenericRelease(*this*).
 </emu-alg>
 
+<h5 id="default-reader-iterator" method for="ReadableStreamDefaultReader">
+  iterator({ cancel = true } = {})

@domenic The default for this would be `preventCancel = false`, right?

> +    if (typeof O !== 'object') {
+      throw new TypeError();
+    }
+    const reader = O._reader;
+    const read = reader.read;
+    return read.call(reader);
+  },
+  return() {
+    const O = this;
+    if (typeof O !== 'object') {
+      throw new TypeError();
+    }
+    if (O._cancel === true) {
+      const reader = O._reader;
+      const cancel = reader.cancel;
+      cancel.call(reader);

I think it should be `return cancel.call(reader);`

> +    const reader = O._reader;
+    const read = reader.read;
+    return read.call(reader);
+  },
+  return() {
+    const O = this;
+    if (typeof O !== 'object') {
+      throw new TypeError();
+    }
+    if (O._cancel === true) {
+      const reader = O._reader;
+      const cancel = reader.cancel;
+      cancel.call(reader);
+    }
+  }
+}, Object.getPrototypeOf(Object.getPrototypeOf(async function* () {}).prototype));

What benefit does it add setting the prototype to this?

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/pull/950#pullrequestreview-148160198

Received on Tuesday, 21 August 2018 17:14:46 UTC