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 Blob response for XMLHttpRequest: #9623 #9629

Merged
merged 1 commit into from Feb 15, 2016

Conversation

@dlrobertson
Copy link
Contributor

dlrobertson commented Feb 14, 2016

My first attempt at implementing the Blob response for XMLHttpRequest. The expected result for the response tests/wpt/web-platform-test/HMLHttpRequest/response-blob-data.htm is also changed to PASS. Please let me know if you see any areas in which I can improve this PR!

Fixes #9623

Review on Reviewable

@@ -726,6 +729,32 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
return NullValue();
}
}
XMLHttpRequestResponseType::Blob => {
match self.response_blob.get() {

This comment has been minimized.

Copy link
@KiChjang

KiChjang Feb 14, 2016

Member

This should really go into a separate method down there, named blob_response, with an annotation containing the corresponding link to the WHATWG specification.

@dlrobertson
Copy link
Contributor Author

dlrobertson commented Feb 14, 2016

Review status: 0 of 2 files reviewed at latest revision, 3 unresolved discussions.


components/script/dom/xmlhttprequest.rs, line 126 [r1] (raw file):
From some review of other commits, I guessed that this was the correct type.


components/script/dom/xmlhttprequest.rs, line 757 [r1] (raw file):
It would be nice to implement this as a separate function, but I don't have a good grasp on codegen and how the XMLHttpRequest trait is generated yet.


Comments from the review on Reviewable.io

@@ -1,5 +1,5 @@
[response-data-blob.htm]
type: testharness
[XMLHttpRequest: The response attribute: Blob data]
expected: FAIL
expected: PASS

This comment has been minimized.

Copy link
@KiChjang

KiChjang Feb 14, 2016

Member

This is not how we change test expectations. If it is expected to PASS, you can just delete the line. In fact, since there's only one expected test failure in this .ini file, you can delete the entire file.

@dlrobertson
Copy link
Contributor Author

dlrobertson commented Feb 14, 2016

Review status: 0 of 2 files reviewed at latest revision, 4 unresolved discussions.


components/script/dom/xmlhttprequest.rs, line 733 [r1] (raw file):
Beat me to it 😄... I'll figure it out and make the update. Thanks!


Comments from the review on Reviewable.io

@KiChjang KiChjang self-assigned this Feb 14, 2016
@dlrobertson
Copy link
Contributor Author

dlrobertson commented Feb 14, 2016

Review status: 0 of 2 files reviewed at latest revision, 4 unresolved discussions.


tests/wpt/metadata/XMLHttpRequest/response-data-blob.htm.ini, line 4 [r1] (raw file):
Good to know! I'll add this in the update as well!


Comments from the review on Reviewable.io

@dlrobertson dlrobertson force-pushed the dlrobertson:i9623 branch from 78b2830 to 7175fac Feb 14, 2016
@@ -1038,6 +1052,25 @@ impl XMLHttpRequest {
encoding.decode(&self.response.borrow(), DecoderTrap::Replace).unwrap().to_owned()
}

fn blob_response(&self) -> Root<Blob> {

This comment has been minimized.

Copy link
@KiChjang

KiChjang Feb 14, 2016

Member

Spec link above this function, please. (https://xhr.spec.whatwg.org/#blob-response)

}
},
XMLHttpRequestResponseType::Blob => {
// Step 1

This comment has been minimized.

Copy link
@KiChjang

KiChjang Feb 14, 2016

Member

This step should also be moved to blob_response. All we should have here is a single call to blob_response.

@dlrobertson dlrobertson force-pushed the dlrobertson:i9623 branch from 7175fac to 1070e73 Feb 14, 2016
fn blob_response(&self) -> Root<Blob> {
// Step 1
match self.response_blob.get() {
Some(response) => response,

This comment has been minimized.

Copy link
@KiChjang

KiChjang Feb 14, 2016

Member

We could simplify this step as if let Some(blob) = self.response_blob.get() { return blob; }

Some(response) => response,
None => {
// Step 2
let mime: String = match self.response_headers.borrow().get() {

This comment has been minimized.

Copy link
@KiChjang

KiChjang Feb 14, 2016

Member

There is a final_mime_type() function defined, so this isn't necessary.


// Step 4
let blob = Blob::new(self.global().r(), body, &mime);
self.response_blob.set(Some(blob.r()));

This comment has been minimized.

Copy link
@KiChjang

KiChjang Feb 14, 2016

Member

This wouldn't compile.

This comment has been minimized.

Copy link
@KiChjang

KiChjang Feb 14, 2016

Member

Ignore what I said, MutNullableHeap::set requires an Option.


// Step 3
let bytes = self.response.borrow();
let body = if bytes.is_empty() {

This comment has been minimized.

Copy link
@KiChjang

KiChjang Feb 14, 2016

Member

This step here doesn't seem necessary. I think let blob = Blob::new(self.global().r(), self.response.borrow().to_vec(), &mime); down there would be sufficient.

@dlrobertson
Copy link
Contributor Author

dlrobertson commented Feb 14, 2016

Review status: 0 of 2 files reviewed at latest revision, 10 unresolved discussions.


components/script/dom/xmlhttprequest.rs, line 1054 [r3] (raw file):
Awesome, i'll look it up.


components/script/dom/xmlhttprequest.rs, line 1061 [r3] (raw file):
Okay! I was just being on the safe side. I'll test and use this if possible.


Comments from the review on Reviewable.io

@dlrobertson dlrobertson force-pushed the dlrobertson:i9623 branch from 1070e73 to 98a27f6 Feb 14, 2016
return response;
}
// Step 2
let mime = match self.final_mime_type() {

This comment has been minimized.

Copy link
@KiChjang

KiChjang Feb 14, 2016

Member

let mime = self.fial_mime_type().unwrap_or("").to_string();

@KiChjang
Copy link
Member

KiChjang commented Feb 14, 2016

Almost there! r=me with that final nit.

@dlrobertson dlrobertson force-pushed the dlrobertson:i9623 branch from 98a27f6 to 5dc108b Feb 14, 2016
return response;
}
// Step 2
let mime = self.final_mime_type().map(|x| x.to_string()).unwrap_or("".to_owned());

This comment has been minimized.

Copy link
@KiChjang

KiChjang Feb 14, 2016

Member

use std::string::ToString

and then .as_ref().map(ToString::to_string) should work.

@KiChjang
Copy link
Member

KiChjang commented Feb 14, 2016

Ah, brainfarted. Everything looks fine right now, thanks for working on this!

@bors-servo r+

@bors-servo
Copy link
Contributor

bors-servo commented Feb 14, 2016

📌 Commit 5dc108b has been approved by KiChjang

@bors-servo
Copy link
Contributor

bors-servo commented Feb 14, 2016

Testing commit 5dc108b with merge a38442d...

bors-servo added a commit that referenced this pull request Feb 14, 2016
Implement Blob response for XMLHttpRequest: #9623

My first attempt at implementing the Blob response for XMLHttpRequest. The expected result for the response `tests/wpt/web-platform-test/HMLHttpRequest/response-blob-data.htm` is also changed to `PASS`. Please let me know if you see any areas in which I can improve this PR!

Fixes #9623

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9629)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Feb 14, 2016

💔 Test failed - mac-dev-unit

@bors-servo
Copy link
Contributor

bors-servo commented Feb 14, 2016

Testing commit 0b0e147 with merge 6aa908a...

bors-servo added a commit that referenced this pull request Feb 14, 2016
Implement Blob response for XMLHttpRequest: #9623

My first attempt at implementing the Blob response for XMLHttpRequest. The expected result for the response `tests/wpt/web-platform-test/HMLHttpRequest/response-blob-data.htm` is also changed to `PASS`. Please let me know if you see any areas in which I can improve this PR!

Fixes #9623

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9629)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Feb 15, 2016

💔 Test failed - linux-rel

@KiChjang
Copy link
Member

KiChjang commented Feb 15, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Feb 15, 2016

Testing commit 0b0e147 with merge d8e1237...

bors-servo added a commit that referenced this pull request Feb 15, 2016
Implement Blob response for XMLHttpRequest: #9623

My first attempt at implementing the Blob response for XMLHttpRequest. The expected result for the response `tests/wpt/web-platform-test/HMLHttpRequest/response-blob-data.htm` is also changed to `PASS`. Please let me know if you see any areas in which I can improve this PR!

Fixes #9623

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9629)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Feb 15, 2016

💔 Test failed - linux-rel

@KiChjang
Copy link
Member

KiChjang commented Feb 15, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Feb 15, 2016

Testing commit 0b0e147 with merge e8ae7e4...

bors-servo added a commit that referenced this pull request Feb 15, 2016
Implement Blob response for XMLHttpRequest: #9623

My first attempt at implementing the Blob response for XMLHttpRequest. The expected result for the response `tests/wpt/web-platform-test/HMLHttpRequest/response-blob-data.htm` is also changed to `PASS`. Please let me know if you see any areas in which I can improve this PR!

Fixes #9623

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9629)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Feb 15, 2016

💔 Test failed - mac-rel-css

@KiChjang
Copy link
Member

KiChjang commented Feb 15, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Feb 15, 2016

Previous build results for android, gonk, linux-dev, mac-dev-unit are reusable. Rebuilding only linux-rel, mac-rel-css, mac-rel-wpt...

@bors-servo
Copy link
Contributor

bors-servo commented Feb 15, 2016

@bors-servo bors-servo merged commit 0b0e147 into servo:master Feb 15, 2016
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@dlrobertson dlrobertson deleted the dlrobertson:i9623 branch Feb 15, 2016
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.

None yet

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