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 the Fetch method #13323

Merged
merged 1 commit into from Sep 29, 2016
Merged

Implement the Fetch method #13323

merged 1 commit into from Sep 29, 2016

Conversation

@jeenalee
Copy link
Contributor

jeenalee commented Sep 19, 2016

This PR implements the fetch method, which is described in the Fetch Spec. The expected wpt results are updated as well.

A few comments about the current fetch implementation:

  • The fetch method manually calls JSAutoCompartment in order to prevent SpiderMonkey from crashing. This may have to change in the future.
  • Not all FetchResponseListener methods are implemented.
  • net_traits::CoreResourceMsg::Fetch message takes a net_traits::request::RequestInit. However, when the fetch method is called, a RequestBinding::RequestInit is given. The fetch method constructs a dom::request::Request with the given RequestInit, then creates net_traits::request::RequestInit from the dom Request object for the fetch message.

  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #11898 (github issue number if applicable).
  • There are tests for these changes OR
  • These changes do not require tests because _____

This change is Reviewable

@highfive
Copy link

highfive commented Sep 19, 2016

Heads up! This PR modifies the following files:

  • @fitzgen: components/devtools/Cargo.toml, components/devtools/lib.rs, components/devtools/actors/network_event.rs, components/devtools_traits/lib.rs, components/devtools_traits/lib.rs
  • @KiChjang: components/script/dom/request.rs, components/net_traits/response.rs, components/net_traits/response.rs, components/script/timers.rs, components/net/http_loader.rs, components/script/dom/workerglobalscope.rs, components/script/dom/bindings/error.rs, components/script/fetch.rs, components/script/Cargo.toml, components/net/blob_loader.rs, components/script/script_thread.rs, components/script/dom/promise.rs, components/script/dom/webidls/Fetch.webidl, components/script/dom/mod.rs, components/script/dom/htmllinkelement.rs, components/script/dom/bindings/refcounted.rs, components/script/dom/testbinding.rs, components/script/dom/xmlhttprequest.rs, components/script/dom/htmlmediaelement.rs, components/script/dom/webidls/PromiseNativeHandler.webidl, components/script/dom/response.rs, components/script/dom/bindings/codegen/Bindings.conf, components/script/dom/bindings/trace.rs, components/script/dom/window.rs, components/net_traits/lib.rs, components/net_traits/lib.rs, components/script/dom/bindings/codegen/CodegenRust.py, components/script/dom/webidls/TestBinding.webidl, components/net/fetch/methods.rs, components/script/dom/webidls/Promise.webidl, components/script/dom/bindings/global.rs, components/script/dom/webidls/Response.webidl, components/script/dom/htmlscriptelement.rs, components/script/lib.rs, components/script/dom/bindings/codegen/Configuration.py, components/net/about_loader.rs, components/script/dom/promisenativehandler.rs, components/script/dom/headers.rs, components/script/dom/bindings/js.rs, components/script/script_runtime.rs, components/script/dom/webidls/WindowOrWorkerGlobalScope.webidl
@highfive
Copy link

highfive commented Sep 19, 2016

warning Warning warning

  • These commits include an empty title element (<title></title>). Consider adding appropriate metadata.
  • These commits modify unsafe code. Please review it carefully!
@jeenalee
Copy link
Contributor Author

jeenalee commented Sep 19, 2016

r? @jdm

@highfive highfive assigned jdm and unassigned Ms2ger Sep 19, 2016
@jeenalee jeenalee force-pushed the jeenalee:fetch branch 4 times, most recently from c291b8e to c135549 Sep 19, 2016
@emilio
Copy link
Member

emilio commented Sep 21, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Sep 21, 2016

Trying commit c135549 with merge 864ba39...

bors-servo added a commit that referenced this pull request Sep 21, 2016
Implement the Fetch method

<!-- Please describe your changes on the following line: -->

This PR implements the fetch method, which is described in [the Fetch Spec](https://fetch.spec.whatwg.org/#fetch-method). The expected wpt results are updated as well.

A few comments about the current fetch implementation:
- The fetch method manually calls `JSAutoCompartment` in order to prevent SpiderMonkey from crashing. This may have to change in the future.
- Not all `FetchResponseListener` methods are implemented.
- `net_traits::CoreResourceMsg::Fetch` message takes a `net_traits::request::RequestInit`. However, when the fetch method is called, a `RequestBinding::RequestInit` is given. The fetch method constructs a `dom::request::Request` with the given `RequestInit`, then creates `net_traits::request::RequestInit` from the dom Request object for the fetch message.

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

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- 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/13323)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Sep 21, 2016

💔 Test failed - linux-rel

Copy link
Member

jdm left a comment

Nice work!

@@ -217,6 +217,10 @@ impl Headers {
self.guard.set(new_guard)
}

pub fn set_guard_immutable(&self) {

This comment has been minimized.

Copy link
@jdm

jdm Sep 21, 2016

Member

We can use set_guard instead.


impl Response {
pub fn set_headers(&self, option_hyper_headers: Option<Serde<HyperHeaders>>) {
self.Headers().set_headers( match option_hyper_headers {

This comment has been minimized.

Copy link
@jdm

jdm Sep 21, 2016

Member

nit: extra space after (

use std::sync::{Arc, Mutex};
use url::Url;

#[allow(unrooted_must_root)]

This comment has been minimized.

Copy link
@jdm

jdm Sep 21, 2016

Member

Do you remember why this was required?

This comment has been minimized.

Copy link
@jeenalee

jeenalee Sep 21, 2016

Author Contributor

The compiler was saying that that Fallible<Rc<Promise>> should be rooted, and that was the reason it was added. But looking at the code again, I don't think it's required. I'll try removing it.

This comment has been minimized.

Copy link
@jeenalee

jeenalee Sep 21, 2016

Author Contributor

It was indeed not required. Thank you for pointing it out!

}

fn from_referer_to_referer_url(request: &NetTraitsRequest) -> Option<Url> {
let referer = request.referrer.borrow();

This comment has been minimized.

Copy link
@jdm

jdm Sep 21, 2016

Member

referrer

response_object: Trusted<Response>,
}

fn from_referer_to_referer_url(request: &NetTraitsRequest) -> Option<Url> {

This comment has been minimized.

Copy link
@jdm

jdm Sep 21, 2016

Member

from_referrer_to_referrer_url

[Exposed=(Window,Worker)]

partial interface WindowOrWorkerGlobalScope {
[NewObject, Throws] Promise<Response> fetch(RequestInfo input, optional RequestInit init);

This comment has been minimized.

Copy link
@jdm

jdm Sep 21, 2016

Member

No need for Throws anymore.

let (action_sender, action_receiver) = ipc::channel().unwrap();
let fetch_context = Arc::new(Mutex::new(FetchContext {
fetch_promise: Some(TrustedPromise::new(promise.clone())),
response_object: Trusted::new(response.r()),

This comment has been minimized.

Copy link
@jdm

jdm Sep 21, 2016

Member

We can use &* instead of .r() here.

}));
let listener = NetworkListener {
context: fetch_context.clone(),
// TODO: double check how to get script_chan

This comment has been minimized.

Copy link
@jdm

jdm Sep 21, 2016

Member

This comment is meaningless here; let's remove it.

response_object: Trusted::new(response.r()),
}));
let listener = NetworkListener {
context: fetch_context.clone(),

This comment has been minimized.

Copy link
@jdm

jdm Sep 21, 2016

Member

I don't think this clone is necessary.


#[allow(unrooted_must_root)]
fn process_response(&mut self, metadata: Result<Metadata, NetworkError>) {
let promise = match self.fetch_promise.take() {

This comment has been minimized.

Copy link
@jdm

jdm Sep 21, 2016

Member

Let's use let promise = self.fetch_promise.take().expect("fetch promise is missing").root();

@jeenalee
Copy link
Contributor Author

jeenalee commented Sep 21, 2016

@jdm Review comments addressed!

@jdm jdm removed the S-awaiting-review label Sep 21, 2016
@jdm
jdm approved these changes Sep 21, 2016
@jdm
Copy link
Member

jdm commented Sep 21, 2016

Great! You can squash your commits together, and then we'll merge this once #12830 is merged.

@jdm jdm added the S-needs-squash label Sep 21, 2016
@jeenalee jeenalee force-pushed the jeenalee:fetch branch from d538c95 to ff043f0 Sep 21, 2016
@bors-servo
Copy link
Contributor

bors-servo commented Sep 29, 2016

The latest upstream changes (presumably #13345) made this pull request unmergeable. Please resolve the merge conflicts.

@jeenalee jeenalee force-pushed the jeenalee:fetch branch from 0c25840 to 3216009 Sep 29, 2016
@jeenalee
Copy link
Contributor Author

jeenalee commented Sep 29, 2016

Rebased as #13345 was merged (hooray!)!

@jdm
Copy link
Member

jdm commented Sep 29, 2016

@jeenalee: Does this include new test results for all the tests? Working body methods will have changed the results from previous runs significantly.

@jeenalee
Copy link
Contributor Author

jeenalee commented Sep 29, 2016

@jdm I built and ran fetch/api/ tests, and updated the test results. Will that suffice?

@jdm
Copy link
Member

jdm commented Sep 29, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Sep 29, 2016

📌 Commit 3216009 has been approved by jdm

@bors-servo
Copy link
Contributor

bors-servo commented Sep 29, 2016

Testing commit 3216009 with merge f6d5cac...

bors-servo added a commit that referenced this pull request Sep 29, 2016
Implement the Fetch method

<!-- Please describe your changes on the following line: -->

This PR implements the fetch method, which is described in [the Fetch Spec](https://fetch.spec.whatwg.org/#fetch-method). The expected wpt results are updated as well.

A few comments about the current fetch implementation:
- The fetch method manually calls `JSAutoCompartment` in order to prevent SpiderMonkey from crashing. This may have to change in the future.
- Not all `FetchResponseListener` methods are implemented.
- `net_traits::CoreResourceMsg::Fetch` message takes a `net_traits::request::RequestInit`. However, when the fetch method is called, a `RequestBinding::RequestInit` is given. The fetch method constructs a `dom::request::Request` with the given `RequestInit`, then creates `net_traits::request::RequestInit` from the dom Request object for the fetch message.

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

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- 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/13323)
<!-- Reviewable:end -->
@bors-servo bors-servo mentioned this pull request Sep 29, 2016
3 of 5 tasks complete
@bors-servo
Copy link
Contributor

bors-servo commented Sep 29, 2016

💔 Test failed - linux-rel

@jdm
Copy link
Member

jdm commented Sep 29, 2016

bors-servo added a commit that referenced this pull request Sep 29, 2016
Implement the Fetch method

<!-- Please describe your changes on the following line: -->

This PR implements the fetch method, which is described in [the Fetch Spec](https://fetch.spec.whatwg.org/#fetch-method). The expected wpt results are updated as well.

A few comments about the current fetch implementation:
- The fetch method manually calls `JSAutoCompartment` in order to prevent SpiderMonkey from crashing. This may have to change in the future.
- Not all `FetchResponseListener` methods are implemented.
- `net_traits::CoreResourceMsg::Fetch` message takes a `net_traits::request::RequestInit`. However, when the fetch method is called, a `RequestBinding::RequestInit` is given. The fetch method constructs a `dom::request::Request` with the given `RequestInit`, then creates `net_traits::request::RequestInit` from the dom Request object for the fetch message.

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

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- 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/13323)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Sep 29, 2016

Testing commit 3216009 with merge 5996e00...

@bors-servo
Copy link
Contributor

bors-servo commented Sep 29, 2016

@bors-servo bors-servo merged commit 3216009 into servo:master Sep 29, 2016
1 of 3 checks passed
1 of 3 checks passed
continuous-integration/appveyor/pr AppVeyor build failed
Details
continuous-integration/travis-ci/pr The Travis CI build failed
Details
homu Test successful
Details
@bors-servo bors-servo mentioned this pull request Sep 29, 2016
3 of 5 tasks complete
@jdm jdm mentioned this pull request Sep 30, 2016
4 of 5 tasks complete
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.