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

Implement read methods on FileReaderSync #19511

Merged

Conversation

@DonatJR
Copy link
Contributor

DonatJR commented Dec 7, 2017

Implemented the read methods on the FileReaderSync struct according to https://w3c.github.io/FileAPI/#dfn-FileReaderSync


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #15114
  • There are tests for these changes

This change is Reviewable

@highfive
Copy link

highfive commented Dec 7, 2017

Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @wafflespeanut (or someone else) soon.

@highfive
Copy link

highfive commented Dec 7, 2017

Heads up! This PR modifies the following files:

  • @asajeffrey: components/script/dom/filereadersync.rs, components/script/dom/webidls/FileReaderSync.webidl, components/script/dom/bindings/error.rs, components/script/dom/webidls/DOMException.webidl, components/script/dom/domexception.rs
  • @fitzgen: components/script/dom/filereadersync.rs, components/script/dom/webidls/FileReaderSync.webidl, components/script/dom/bindings/error.rs, components/script/dom/webidls/DOMException.webidl, components/script/dom/domexception.rs
  • @KiChjang: components/script/dom/filereadersync.rs, components/script/dom/webidls/FileReaderSync.webidl, components/script/dom/bindings/error.rs, components/script/dom/webidls/DOMException.webidl, components/script/dom/domexception.rs
@highfive
Copy link

highfive commented Dec 7, 2017

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!
@DonatJR
Copy link
Contributor Author

DonatJR commented Dec 7, 2017

I tried to update the manifest with ./mach update-manifest but this changed almost every entry in the files. What is the correct way to only change the entry for the changed test (/tests/wpt/web-platform-tests/FileAPI/FileReaderSync.worker.js) ?

@jdm
Copy link
Member

jdm commented Dec 8, 2017

That's the correct way to update it; what were the changes it tried to make?

@DonatJR
Copy link
Contributor Author

DonatJR commented Dec 8, 2017

manifests.zip
For tests/wpt/metadata/MANIFEST.json there are a few timeout changes in the WebCryptoAPI tests and a lot of changed hashes for the tests themselves.
For tests/wpt/mozilla/meta/MANIFEST.json there are only changes to the test hashes.
I atteched all 4 files so you can have a look at them (they also have different line endings - probably because I'm on Windows).

@jdm jdm assigned jdm and unassigned wafflespeanut Jan 29, 2018
Copy link
Member

jdm left a comment

This is great! I think it should be possible to avoid duplicating some of the less straightforward parts of the implementation, though.


// step 2
let blob_contents = blob.get_bytes().unwrap_or(vec![]);
if blob_contents.is_empty() {

This comment has been minimized.

@jdm

jdm Jan 29, 2018

Member

What happens if we run a test like readerSync.readAsBinaryString(new Blob([""]));? Won't this incorrectly throw an exception?


// step 2
let blob_contents = blob.get_bytes().unwrap_or(vec![]);
if blob_contents.is_empty() {

This comment has been minimized.

@jdm

jdm Jan 29, 2018

Member

Same question as readAsBinaryString.

let blob_type = String::from(blob.Type());

//https://w3c.github.io/FileAPI/#encoding-determination
let mut encoding = blob_label.as_ref()

This comment has been minimized.

@jdm

jdm Jan 29, 2018

Member

Could we share this code with filereader.rs instead of duplicating it?


// step 2
let blob_contents = blob.get_bytes().unwrap_or(vec![]);
if blob_contents.is_empty() {

This comment has been minimized.

@jdm

jdm Jan 29, 2018

Member

Same question as other methods.

}

// step 3
let base64 = base64::encode(&blob_contents);

This comment has been minimized.

@jdm

jdm Jan 29, 2018

Member

Let's share this code with filereader.rs.


// step 2
let blob_contents = blob.get_bytes().unwrap_or(vec![]);
if blob_contents.is_empty() {

This comment has been minimized.

@jdm

jdm Jan 29, 2018

Member

Same question as other methods.

var data = readerSync.readAsBinaryString(blob);
assert_equals(data, "test");
}, "readAsBinaryString");

This comment has been minimized.

@jdm

jdm Jan 29, 2018

Member

Let's add tests with empty blobs in this file as well.

}

impl FileReaderSync {
pub fn new_inherited() -> FileReaderSync {
FileReaderSync {
eventtarget: EventTarget::new_inherited(),
ready_state: Cell::new(FileReaderReadyState::Empty),

This comment has been minimized.

@jdm

jdm Jan 29, 2018

Member

Since the spec doesn't actually tell us to modify the readyState for synchronous file readers, nor does it describe a way where the LOADING check could actually succeed, let's remove it from our implementation.

This comment has been minimized.

@jdm

jdm Jan 29, 2018

Member

I've filed w3c/FileAPI#96 against the spec.

@jdm
Copy link
Member

jdm commented Jan 29, 2018

Sorry about the unnecessary delay before this code was reviewed. I promise shorter review cycles if you want to keep working on this!

@DonatJR
Copy link
Contributor Author

DonatJR commented Jan 30, 2018

@jdm No worries about the delay, I'm rather short on time myself right now, so I probably wouldn't have been able to work on this any sooner anyway. That said, I do want to keep working on it! :)

@DonatJR
Copy link
Contributor Author

DonatJR commented May 23, 2018

Now I'm the one having to apologize for taking SO long to update this...
I adressed your comments but I'm not completely happy with my solution for sharing the code between FileReader and FileReaderSync - if you have any suggestions on how to improve it I'd be happy to make the necessary changes.

I am also still unable to properly update the manifest files for the updated tests (same issues as described in an earlier comment)

@servo-wpt-sync
Copy link
Collaborator

servo-wpt-sync commented May 23, 2018

Error syncing changes upstream. Logs saved in error-snapshot-1527098417542.

@servo-wpt-sync
Copy link
Collaborator

servo-wpt-sync commented May 23, 2018

Error syncing changes upstream. Logs saved in error-snapshot-1527103060139.

Copy link
Member

jdm left a comment

Great work! For sharing code, it's a toss-up as to whether it's worth creating static methods on a type like this PR does, or using free functions. I'm not bothered either way. Please squash all the commits together, too!

result: &DomRefCell<Option<FileReaderResult>>,
data: ReadMetaData,
blob_bytes: &[u8],
) {
let blob_label = &data.label;
let blob_type = &data.blobtype;

//https://w3c.github.io/FileAPI/#encoding-determination

This comment has been minimized.

@jdm

jdm May 29, 2018

Member

This comment should be moved into the text_decode function.

This comment has been minimized.

@DonatJR

DonatJR May 29, 2018

Author Contributor

Its in text_decode (link to line) as well, do you want me to remove it here anyway?

This comment has been minimized.

@jdm

jdm May 29, 2018

Member

Ah, my mistake. You can just remove it from this location, in that case.

@DonatJR
Copy link
Contributor Author

DonatJR commented Jun 3, 2018

This is the first time I'm attempting to squash commits together, so I just wanted to be sure if I'm doing it correctly. I searched the log for the commit hash that came right before my first change, ran git rebase -i <hash> and replaced pick with squash for all commits except the first. So far this seems to be easy enough, but because of the fact that I merged the master branch back into this one to resolve conflicts the rebase is now also processing these merged commits. Is this correct or should I have only picked my commits from this PR in the list at the beginning of the rebase?

Thanks for your patience and help :)

@KiChjang
Copy link
Member

KiChjang commented Jun 3, 2018

@DonatJR What happens if you do git rebase origin master first before you squash?

@DonatJR
Copy link
Contributor Author

DonatJR commented Jun 3, 2018

@KiChjang git rebase origin master says that master is already up to date:

Current branch master is up to date.

And it changes nothing about the number of commits when squashing.

@KiChjang
Copy link
Member

KiChjang commented Jun 3, 2018

@DonatJR Oh sorry, I meant git rebase origin/master.

@DonatJR
Copy link
Contributor Author

DonatJR commented Jun 3, 2018

With git rebase origin/master my commits from this PR are getting rebased:

First, rewinding head to replay your work on top of it...
Applying: implemented readAsText, readAsBinaryString and readAsDataUrl on FileReaderSync
...

But again, no changes to before when squashing.

@jdm
Copy link
Member

jdm commented Jun 4, 2018

It's probably easiest to make a new branch based off of master and cherry-pick all of the non-merge commits like:

git cherry-pick b290a5b
git cherry-pick a343a77
git cherry-pick 90db19a
git cherry-pick e2abae0
git cherry-pick 7b7b3d1
git cherry-pick 5550449
git cherry-pick d0a5e2b
git cherry-pick 00700fa
git cherry-pick a0748c3
git cherry-pick 8ffa7a4
git cherry-pick 371c770

Then you can do git push [fork] [newbranchname]:implement-read-methods-on-filereadersync -f to overwrite the changes in this PR, where [fork] is the remote pointing at your github fork, and [newbranchname] is the name of the new branch you created locally.

@DonatJR DonatJR force-pushed the DonatJR:implement-read-methods-on-filereadersync branch from 371c770 to 21bf9c3 Jun 4, 2018
@bors-servo
Copy link
Contributor

bors-servo commented Jun 4, 2018

Testing commit 21bf9c3 with merge 49b2367...

bors-servo added a commit that referenced this pull request Jun 4, 2018
…nc, r=jdm

Implement read methods on FileReaderSync

<!-- Please describe your changes on the following line: -->
Implemented the read methods on the FileReaderSync struct according to https://w3c.github.io/FileAPI/#dfn-FileReaderSync

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #15114

<!-- Either: -->
- [x] There are tests for these changes

<!-- 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. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19511)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jun 4, 2018

💔 Test failed - android

@jdm
Copy link
Member

jdm commented Jun 4, 2018

 0:24.76 INFO Diffing old and new manifests /Users/servo/buildbot/slave/mac-dev-unit/build/tests/wpt/mozilla/meta/MANIFEST.json
 0:25.38 INFO Diffing old and new manifests /Users/servo/buildbot/slave/mac-dev-unit/build/tests/wpt/metadata/MANIFEST.json
 0:29.87 WARNING Manifest /Users/servo/buildbot/slave/mac-dev-unit/build/tests/wpt/metadata/MANIFEST.json contains correct tests but file hashes changed.
 0:29.95 ERROR Manifest /Users/servo/buildbot/slave/mac-dev-unit/build/tests/wpt/metadata/MANIFEST.json is outdated, use |./mach update-manifest| to fix.
@DonatJR
Copy link
Contributor Author

DonatJR commented Jun 4, 2018

This is because of the issues I talked about earlier in the PR (here, here and here). I am not sure how to correctly generate the manifests, ./mach update-manifest changes a lot of hashes (among some other changes) for tests I never touched. :(

@jdm
Copy link
Member

jdm commented Jun 4, 2018

Oh, right. Yeah, that's super weird, and I don't have any good suggestions. I'll make the change locally and update the PR.

@jdm jdm force-pushed the DonatJR:implement-read-methods-on-filereadersync branch from 21bf9c3 to 0fdafb0 Jun 4, 2018
@jdm
Copy link
Member

jdm commented Jun 4, 2018

@bors-servo
Copy link
Contributor

bors-servo commented Jun 4, 2018

📌 Commit 0fdafb0 has been approved by jdm

@servo-wpt-sync
Copy link
Collaborator

servo-wpt-sync commented Jun 4, 2018

Transplanted upstreamable changes to existing PR.

Completed upstream sync of web-platform-test changes at jdm/web-platform-tests#65.

@bors-servo
Copy link
Contributor

bors-servo commented Jun 4, 2018

Testing commit 0fdafb0 with merge 652a177...

bors-servo added a commit that referenced this pull request Jun 4, 2018
…nc, r=jdm

Implement read methods on FileReaderSync

<!-- Please describe your changes on the following line: -->
Implemented the read methods on the FileReaderSync struct according to https://w3c.github.io/FileAPI/#dfn-FileReaderSync

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #15114

<!-- Either: -->
- [x] There are tests for these changes

<!-- 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. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19511)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jun 4, 2018

💔 Test failed - mac-rel-css2

@jdm
Copy link
Member

jdm commented Jun 4, 2018

@bors-servo
Copy link
Contributor

bors-servo commented Jun 4, 2018

@bors-servo
Copy link
Contributor

bors-servo commented Jun 4, 2018

@bors-servo bors-servo merged commit 0fdafb0 into servo:master Jun 4, 2018
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
jdm added a commit to web-platform-tests/wpt that referenced this pull request Jun 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

7 participants
You can’t perform that action at this time.