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

domenic commented on this pull request.



> @@ -300,4 +300,36 @@ promise_test(() => {
   return readableStreamToArray(ts.readable);
 }, 'methods should not not have .apply() or .call() called');
 
+promise_test(t => {
+  const transformer = {
+    transform() {
+      transformer.transform = undefined;
+      throw new TypeError();
+    }
+  };
+  const ts = new TransformStream(transformer);
+  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')

It's a little unclear to me whether these throw because it's undefined or throw because you threw a TypeError. If you're testing that the code gets exercised, then maybe setting a boolean, or using the `error1` pattern, would be clearer.

> +  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');

Maybe write more than one chunk to ensure it doesn't look it up once for each chunk?

-- 
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#pullrequestreview-25857911

Received on Wednesday, 8 March 2017 19:16:10 UTC