Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite FileReader definitions. #118

Merged
merged 6 commits into from
Mar 15, 2019
Merged

Conversation

mkruisselbrink
Copy link
Collaborator

@mkruisselbrink mkruisselbrink commented Mar 12, 2019

Make algorithms more imperative to make it clearer what is going on.
No intended behavioral changes, but making it clearer that the behavior
from #79 is the expected behavior.


Preview | Diff

Make algorithms more imperative to make it clearer what is going on.
No intended behavioral changes, but making it clearer that the behavior
from #79 is the expected behavior.
@mkruisselbrink
Copy link
Collaborator Author

This isn't supposed to change behavior, but I should still write tests to actually verify the behavior, as there are things in this area (like #79) that aren't currently tested, and where browsers do diverge.

Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'm a little worried about all the promise usage in parallel, but I guess since we don't have a low-level stream model that's hard to get away from. Fetch also has this problem... Maybe @domenic has thoughts.

index.bs Outdated Show resolved Hide resolved
1. Let |bytes| by an empty [=byte sequence=].
1. Let |chunk| be the result of [=read a chunk|reading a chunk=] from |stream| with |reader|.
1. Let |isFirstChunk| be true.
1. [=In parallel=], while true:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't really in parallel since you operate on promises from the main thread. Maybe it's okay for now though, but doesn't seem like the correct setup long term.

cc @domenic

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is exactly what fetch does in for example the "transmit body" algorithm. But yeah, not sure what the best spec language is these days to "wait" for promises to resolve without blocking the main thread of execution. Open to suggestions.

index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
@mkruisselbrink
Copy link
Collaborator Author

Thanks for the review. Yeah, I tried to mostly just mimic what fetch (and sometimes XHR) are doing.

Corresponding tests are in web-platform-tests/wpt#7494 (and unfortunately not a single browser currently passes those tests... Firefox is close (it is synchronously firing the loadstart event rather than posting a task, and it set result too soon for readAsBinaryString). Chromium/Edge have various other issues, but we already have a bug for at least some of those, and I don't see any problems with fixing those. Safari seems to mostly currently match Chromium in behavior.

Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks great. I mostly have a ton of nits.

index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
Copy link
Contributor

@domenic domenic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally LGTM, with some suggestions which are mostly scope-creep.

index.bs Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
1. Let |stream| be the result of calling [=get stream=] on |blob|.
1. Let |reader| be the result of [=get a reader|getting a reader=] from |stream|.
1. Let |promise| be the result of [=read all bytes|reading all bytes=] from |stream| with |reader|.
1. Wait for |promise| to be fulfilled or rejected.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not the most sound thing to do with real promises, but let's pretend these are spec promises, like they really should be if streams had a better infrastructure :).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, this of course only sort of works because we control the stream, and we know no script has to execute for this particular stream to be drained and the promise to resolve... That's not very nice (but then neither are sync APIs in general :) )

@mkruisselbrink mkruisselbrink merged commit 795750f into master Mar 15, 2019
@annevk annevk deleted the rewrite-read-operations branch March 16, 2019 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants