node icon indicating copy to clipboard operation
node copied to clipboard

stream: implement ReadableStream.from

Open debadree25 opened this issue 1 year ago • 10 comments

Implements ReadableStream.from

Updating the WPTs add a lot of new tests, and failures that weren't relevant to this PR, I have added them to expected failures.

Please do take a look at the node errors used, I have used ERR_INVALID_STATE.TypeError in all the places since all the webstreams code seems to be reliant on that.

Fixes: https://github.com/nodejs/node/issues/48389

debadree25 avatar Jun 08 '23 18:06 debadree25

cc @nodejs/whatwg-stream

debadree25 avatar Jun 08 '23 18:06 debadree25

Also, would this need node tests too? or WPTs are enough?

debadree25 avatar Jun 08 '23 18:06 debadree25

CI: https://ci.nodejs.org/job/node-test-pull-request/52169/

nodejs-github-bot avatar Jun 08 '23 18:06 nodejs-github-bot

We should short circuit if we get a Node stream and use toWeb machinary if the spec allows

where to check for this? should make a issue on the spec repo? maybe @MattiasBuelens can help?

debadree25 avatar Jun 09 '23 17:06 debadree25

have addressed all the comments and will wait for some time if we would like to add .toWeb functionality like @benjamingr suggested

debadree25 avatar Jun 09 '23 17:06 debadree25

CI: https://ci.nodejs.org/job/node-test-pull-request/52185/

nodejs-github-bot avatar Jun 09 '23 18:06 nodejs-github-bot

We should short circuit if we get a Node stream and use toWeb machinary if the spec allows

where to check for this? should make a issue on the spec repo? maybe @MattiasBuelens can help?

I would recommend something like:

// at the top-level
// ideally, this is exported by `lib/internal/streams/readable.js`
const originalReadableAsyncIterator = Readable.prototype[Symbol.asyncIterator];

// in readableStreamFromIterable
if (iterable instanceof Readable && iterable[Symbol.asyncIterator] === originalReadableAsyncIterator) {
 return Readable.toWeb(iterable);
}

This way, you can be certain that you're dealing with an unmodified Readable, and that there will be no behavioral differences compared to "going the long way" using Readable's async iterator.

I also suggest you write additional tests with polluted Readable instances, or with a polluted Readable.prototype. 😉

MattiasBuelens avatar Jun 12 '23 09:06 MattiasBuelens

Hey one thing is it ok to export things from lib/internal/streams/readable.js something like originalReadableAsyncIterator as suggested? i know there is little bit restrictions in what we can export import in around the readable node stream part since its used in readablestream @benjamingr @mcollina

debadree25 avatar Jun 13 '23 20:06 debadree25

Updated the docs, just question from https://github.com/nodejs/node/pull/48395#issuecomment-1589977209 remains

debadree25 avatar Jun 16 '23 19:06 debadree25

friendly ping regards to this question https://github.com/nodejs/node/pull/48395#issuecomment-1589977209 @benjamingr 😅😄

debadree25 avatar Jun 22 '23 13:06 debadree25

Hey @benjamingr added the short circuit with toWeb() as you suggested used symbols to communicate whether the iterator prototype is original or polluted, PTAL if it makes sense!

Thank You!

debadree25 avatar Jun 24 '23 07:06 debadree25

CI: https://ci.nodejs.org/job/node-test-pull-request/52418/

nodejs-github-bot avatar Jun 24 '23 07:06 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/52423/

nodejs-github-bot avatar Jun 24 '23 12:06 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/52427/

nodejs-github-bot avatar Jun 24 '23 15:06 nodejs-github-bot

Does anyone know what this failure means:

"readable-streams/read-task-handling.window.js": {
    "fail": {
      "unexpected": [
        "evaluation in WPTRunner.runJsTests()"
      ]
    }

seems to be failing in some systems so inclined to believe this is something flakey

debadree25 avatar Jun 24 '23 18:06 debadree25

CI: https://ci.nodejs.org/job/node-test-pull-request/52434/

nodejs-github-bot avatar Jun 24 '23 18:06 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/52437/

nodejs-github-bot avatar Jun 24 '23 20:06 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/52446/

nodejs-github-bot avatar Jun 25 '23 07:06 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/52448/

nodejs-github-bot avatar Jun 25 '23 07:06 nodejs-github-bot

added skips for some browser-specific tests, please PTAL and re-approve 😅

debadree25 avatar Jun 25 '23 07:06 debadree25

CI: https://ci.nodejs.org/job/node-test-pull-request/52451/

nodejs-github-bot avatar Jun 25 '23 08:06 nodejs-github-bot

Hey everyone pinging again just blocked on what should be dont for https://github.com/nodejs/node/pull/48395#pullrequestreview-1470701774 cc @mcollina @benjamingr maybe we could land this implementation and do the toWeb thing in a follow up?

debadree25 avatar Jul 12 '23 19:07 debadree25

As a casual observer, mixing node streams with web streams will only lead to harder to maintain code. IMO all of the node stream stuff should be removed.

KhafraDev avatar Jul 13 '23 04:07 KhafraDev

CI: https://ci.nodejs.org/job/node-test-pull-request/52751/

nodejs-github-bot avatar Jul 13 '23 18:07 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/52752/

nodejs-github-bot avatar Jul 13 '23 18:07 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/52753/

nodejs-github-bot avatar Jul 13 '23 18:07 nodejs-github-bot

Hello everyone! I have reverted the change of toWeb for now (I shall do it in a follow up, since i was getting confused 😅) PTAL it seems ready to land!

debadree25 avatar Jul 14 '23 06:07 debadree25

Landed in b361ad72ce65894a250fd0543b0e09d1a9a7edc5

nodejs-github-bot avatar Jul 18 '23 09:07 nodejs-github-bot