Re: [whatwg/streams] Check precisely the way that transformer.transform() is called (#689)

ricea commented on this pull request.



> +  return Promise.all([
+    promise_rejects(t, new TypeError(), ts.writable.getWriter().write('a'), 'write() should throw'),
+    promise_rejects(t, new TypeError(), ts.readable.getReader().read(), 'read() should throw')
+  ]);
+}, 'transformer.transform should be checked for undefined before being called');
+
+promise_test(() => {
+  let transformGetterCalls = 0;
+  const ts = new TransformStream({
+    get transform() {
+      ++transformGetterCalls;
+      return (chunk, controller) => controller.enqueue(chunk);
+    }
+  });
+  const writer = ts.writable.getWriter();
+  writer.write('a');

It actually is looked up once per chunk.

But I'm starting to think that it shouldn't be. If we only looked it up once, in the constructor, then we could bypass Javascript completely in the case that it was undefined. However, this would be different from the way that sinks and sources work, and maybe too surprising?

-- 
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/689#discussion_r105073625

Received on Thursday, 9 March 2017 02:15:29 UTC