Auto merge of #20406 - kwonoj:feat-fetch-body-arraybuffer, r=jdm

feat(fetch): accept arraybuffer in consume_body

<!-- Please describe your changes on the following line: -->
Related to https://github.com/servo/servo/issues/20346.

I realized I am not sufficiently knowledgeable about codebases and have high confidence this PR is not ready to be accepted. Raising it as PR early to possibly ask some suggestions around codebases.

If this PR seems unrecoverable by code review, please feel freely close and unassign me from issue 🙏

This PR tries to implement #20346, updating `Body` idl and implements corresponding implementation in `body.rs` for `fetch`. Criteria for changes may includes

- does `run_array_buffer_data_algorithm` implementation is legit for allocating arraybuffer? (probably not)
- does `run_array_buffer_data_algorithm` implementation is acceptable for handling error, by naively returning `Error::JSFailed`?
- there are some number of wpt test started to PASS with this PR. Is this legit side effect, or something incorrect by current implementation?
- etcs, vice versa

---
<!-- 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 #20346 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
- wpt test has changed in PR, need to be reviewed.

<!-- 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/20406)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-03-24 13:46:20 -04:00 committed by GitHub
commit 23b2f42a36
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 39 additions and 269 deletions

View file

@ -611,6 +611,12 @@ impl RequestMethods for Request {
fn Json(&self) -> Rc<Promise> {
consume_body(self, BodyType::Json)
}
#[allow(unrooted_must_root)]
// https://fetch.spec.whatwg.org/#dom-body-arraybuffer
fn ArrayBuffer(&self) -> Rc<Promise> {
consume_body(self, BodyType::ArrayBuffer)
}
}
impl BodyOperations for Request {

View file

@ -354,6 +354,12 @@ impl ResponseMethods for Response {
fn Json(&self) -> Rc<Promise> {
consume_body(self, BodyType::Json)
}
#[allow(unrooted_must_root)]
// https://fetch.spec.whatwg.org/#dom-body-arraybuffer
fn ArrayBuffer(&self) -> Rc<Promise> {
consume_body(self, BodyType::ArrayBuffer)
}
}
fn serialize_without_fragment(url: &ServoUrl) -> &str {

View file

@ -10,7 +10,7 @@
interface Body {
readonly attribute boolean bodyUsed;
// [NewObject] Promise<ArrayBuffer> arrayBuffer();
[NewObject] Promise<ArrayBuffer> arrayBuffer();
[NewObject] Promise<Blob> blob();
[NewObject] Promise<FormData> formData();
[NewObject] Promise<any> json();