Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upImplement ReadableStream support #21482
Comments
|
https://searchfox.org/mozilla-central/source/dom/fetch/Fetch.cpp is a good place to use to see examples of C++ code using ReadableStream APIs that the JS engine provides. |
This should be fixed when servo#21482 is done.
This should be fixed when servo#21482 is done.
This should be fixed when servo#21482 is done.
This should be fixed when servo#21482 is done.
This should be fixed when servo#21482 is done.
This should be fixed when servo#21482 is done.
|
#24876 relates to this and is probably a prerequisite for it |
|
Some WPT tests want to see the ReadableStream constructor itself, in addition to the various ones that expect a body.getReader(). |
|
@jdm could you please provide more details on what you mean with:
I've taken a look at On another note, I was wondering if a WebIDL/codegen is necessary, because SM gives use those low-level APIs at https://github.com/servo/mozjs/blob/e21c05b415dfc246175ff8d5fc48b0e8c5b4e9e9/mozjs/js/public/Stream.h and those API all operate on things like On the other hand, I do think we will need to implement various |
|
WebIDL and codegen are only necessary for any WebIDL that includes If WebIDL changes are desired, then the initial codegen can expose the stream objects as |
|
Ok I'm confused by this one. So normally, we use a So I get that(I think). However this time, the actual code is already implemented by SM. Yet will still need:
So, for 1, how can we use the code from SM found over at https://github.com/servo/mozjs/blob/e21c05b415dfc246175ff8d5fc48b0e8c5b4e9e9/mozjs/js/src/builtin/Stream.h (note this is the For 2, I think we can just have a C++ class binding to a Rust struct(like is done with https://github.com/servo/rust-mozjs/blob/9b0d063ba062f4cc60c3bab9250218d6935d647b/src/jsglue.cpp#L42), which would implement the |
|
For example, if I do Why does it require a webild, if SM is already implementing it? |
|
Ah actually we do have a |
|
Ok this is what I will try to do:
Then I guess the Rust struct could just have another method to create a stream backed by a Rust underlying source, this time using So basically, we don't use the code in the |
|
That sounds like a reasonable plan! |
|
@jdm Do you have an idea how to work with The SM API expects a I tried using Would there be a way to get a See https://github.com/servo/servo/pull/25827/files#diff-4a2b21dadec30a5cccff658e252da1a5R46 By the way I am also wondering if its a good idea to get those raw |
|
Ok I think I will accept an object as argument to the constructor, and then:
Or perhaps go from the So the question would be using At this point it's trial and error for me... |
|
Hang on I think I am starting to get it, see a1ac06b Next I'll try to remove the use of |
|
Ok I think this is going actually pretty well(although I haven't run anything so it might all crash), see the WIP at #25827 One thing I noticed is that there are a bunch of other objects, for example For example there is a comment that reads:
and also those reader functions that SM exposes don't seem to give you everything required to implement everything that would be required if we had our own rust struct and exposed it as an interface to script. Also, it's probably better not to call back and forth from rust to JS if it's not necessary. So does it sound ok to just return the JS object to script, and not do everything with an webidl? |
|
Ok so what I have so far crashes in many different ways when trying to run the test-suite, and I'm starting to think there must a better way. In gecko they seem to only have this: https://dxr.mozilla.org/mozilla-central/source/dom/bindings/ReadableStream.h, which is used in the codegen like https://dxr.mozilla.org/mozilla-central/source/dom/bindings/Codegen.py#1393, and seems to rely on https://dxr.mozilla.org/mozilla-central/source/dom/bindings/SpiderMonkeyInterface.h Using Here's the gecko patch to The full gecko issue: https://bugzilla.mozilla.org/show_bug.cgi?id=1128959 |
|
I agree - the WebIDL shouldn't be necessary, because the JS object already exposes the correct prototype hierarchy that matches what the web platform requires. Translating the ReadableStream type in codegen into a JSObject should be a reasonable start. |
|
Ok I've looked more into codegen, and I now see a bit how I could add some code integrating readable stream(it would seem important to add some code handling And there's one thing still baffling me: the constructor. How is it that currently |
|
That's from a RealmOptions setting: https://doc.servo.org/mozjs/jsapi/struct.RealmCreationOptions.html#structfield.streams_ |
|
Awesome! |
|
Another question: What is the best way to implement this Can I just have a struct with the same method names, and cast it to a It's similar to what was done with the However this time I don't think I need static "traps", but rather an actual "instance" of a struct. |
|
My guess here is that to make the virtual methods work you'd need to make a C++ class that derives from ReadableStreamUnderlyingSource and wrap the Rust methods in its C++ methods. Looking at JobQueue, you could probably implement it using the same traps pattern as that. |
|
Little update on what I'm doing over at #25873 So basically just trying to integrate the stream workflow with other parts of the engine, mostly fetch. I'm starting to realize there are parts where we probably want to skip the JS api, since there seems no point of shuffling data from native to JS and then back to native, but for now mostly trying to use the JS apis everywhere. We could later have some "fast native path" to these operations. Also, currently we sometimes have a Also, this is actually a pretty fundamental changes to how we do some of the file operations, and fetch. Currently, the "request body" is always a With regards to file operations, this can also turn things on its head. So currently we're just sending a message containing an IPC sender to the file manager, and then the manager just reads a file as fast as possible and "push" it all over the IPC sender. So with a stream, we could do something were it's the stream that sends an IPC message to signal it wants another chunk, and only then would the filemanager "read a chunk" and send it over IPC. So as a first step I think we can just integrate streams with the current setup, but its sort of "useless" since we'd just be pushing data down into the stream and then resolving a promise, which doesn't really require a stream at all. So the stream basically would just add some JS overhead to the operation. But the power of streams is that the reader is pulling chunks from it, and you get this internal backpressure, which only makes sense if script is also "pulling" chunks via the filemanager. So anyway, the current work is mostly to get the basic integration to work, and sometimes this is actually just going to add overhead to the existing operation. But it opens the door to "doing things properly" where it would suddenly make sense... |
|
Ok so I think I will limit the initial PR to two things(in addition to the basic setup):
Because if I only do 1, then the stream is basically just wrapping a So that leaves integrating into Response bodies, and probably a ton of other stuff.... |
…try> Implement readablestream support <!-- Please describe your changes on the following line: --> FIX #21482 FIX #24876 FIX #26392 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #___ (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
…try> Implement readablestream support <!-- Please describe your changes on the following line: --> FIX #21482 FIX #24876 FIX #26392 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #___ (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
…try> Implement readablestream support <!-- Please describe your changes on the following line: --> FIX #21482 FIX #24876 FIX #26392 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #___ (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
…try> Implement readablestream support <!-- Please describe your changes on the following line: --> FIX #21482 FIX #24876 FIX #26392 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #___ (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
…try> Implement readablestream support <!-- Please describe your changes on the following line: --> FIX #21482 FIX #24876 FIX #26392 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #___ (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
…try> Implement readablestream support <!-- Please describe your changes on the following line: --> FIX #21482 FIX #24876 FIX #26392 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #___ (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
…try> Implement readablestream support <!-- Please describe your changes on the following line: --> FIX #21482 FIX #24876 FIX #26392 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #___ (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
…try> Implement readablestream support <!-- Please describe your changes on the following line: --> FIX #21482 FIX #24876 FIX #26392 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #___ (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
…try> Implement readablestream support <!-- Please describe your changes on the following line: --> FIX #21482 FIX #24876 FIX #26392 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #___ (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
…try> Implement readablestream support <!-- Please describe your changes on the following line: --> FIX #21482 FIX #24876 FIX #26392 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #___ (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
…try> Implement readablestream support <!-- Please describe your changes on the following line: --> FIX #21482 FIX #24876 FIX #26392 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #___ (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
…try> Implement readablestream support <!-- Please describe your changes on the following line: --> FIX #21482 FIX #24876 FIX #26392 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #___ (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This requires updating the WebIDL parser at minimum, and treating it as a
*mut JSObjectfor the code generation.