{"action":"created","comment":{"url":"https://api.github.com/repos/servo/servo/pulls/comments/79835230","id":79835230,"diff_hunk":"@@ -0,0 +1,165 @@\n+/* This Source Code Form is subject to the terms of the Mozilla Public\n+ * License, v. 2.0. If a copy of the MPL was not distributed with this\n+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */\n+\n+use dom::bindings::codegen::Bindings::RequestBinding::RequestInit;\n+use dom::bindings::codegen::Bindings::ResponseBinding::ResponseBinding::ResponseMethods;\n+use dom::bindings::codegen::UnionTypes::RequestOrUSVString;\n+use dom::bindings::error::{Error, Fallible};\n+use dom::bindings::global::GlobalRef;\n+use dom::bindings::refcounted::{Trusted, TrustedPromise};\n+use dom::bindings::reflector::Reflectable;\n+use dom::promise::Promise;\n+use dom::request::Request;\n+use dom::response::Response;\n+use ipc_channel::ipc;\n+use ipc_channel::router::ROUTER;\n+use js::jsapi::JSAutoCompartment;\n+use net_traits::{FetchResponseListener, Metadata, NetworkError};\n+use net_traits::CoreResourceMsg::Fetch as NetTraitsFetch;\n+use net_traits::request::{Request as NetTraitsRequest, RequestInit as NetTraitsRequestInit};\n+use network_listener::{NetworkListener, PreInvoke};\n+use std::rc::Rc;\n+use std::sync::{Arc, Mutex};\n+use url::Url;\n+\n+#[allow(unrooted_must_root)]\n+struct FetchContext {\n+    fetch_promise: Option<TrustedPromise>,\n+    response_object: Trusted<Response>,\n+}\n+\n+fn from_referer_to_referer_url(request: &NetTraitsRequest) -> Option<Url> {\n+    let referer = request.referrer.borrow();\n+    match referer.to_url() {\n+        Some(url) => Some(url.clone()),\n+        None => None,\n+    }\n+}\n+\n+fn request_init_from_request(request: NetTraitsRequest) -> NetTraitsRequestInit {\n+    NetTraitsRequestInit {\n+        method: request.method.borrow().clone(),\n+        url: request.url(),\n+        headers: request.headers.borrow().clone(),\n+        unsafe_request: request.unsafe_request,\n+        same_origin_data: request.same_origin_data.get(),\n+        body: request.body.borrow().clone(),\n+        destination: request.destination,\n+        synchronous: request.synchronous,\n+        mode: request.mode,\n+        use_cors_preflight: request.use_cors_preflight,\n+        credentials_mode: request.credentials_mode,\n+        use_url_credentials: request.use_url_credentials,\n+        // TODO: NetTraitsRequestInit and NetTraitsRequest have different \"origin\"\n+        // ... NetTraitsRequestInit.origin: Url\n+        // ... NetTraitsRequest.origin: RefCell<Origin>\n+        origin: request.url(),\n+        referrer_url: from_referer_to_referer_url(&request),\n+        referrer_policy: request.referrer_policy.get(),\n+        pipeline_id: request.pipeline_id.get(),\n+    }\n+}\n+\n+// https://fetch.spec.whatwg.org/#fetch-method\n+#[allow(unrooted_must_root)]\n+pub fn Fetch(global: GlobalRef, input: RequestOrUSVString, init: &RequestInit) -> Fallible<Rc<Promise>> {\n+    let core_resource_thread = global.core_resource_thread();\n+\n+    // Step 1\n+    let promise = Promise::new(global);\n+    let response = Response::new(global);\n+\n+    // Step 3\n+    response.Headers().set_guard_immutable();\n+\n+    // Step 2\n+    let request = match Request::Constructor(global, input, init) {\n+        Err(e) => {\n+            promise.maybe_reject_error(promise.global().r().get_cx(),\n+                                       e);\n+            return Ok(promise);\n+        }\n+        Ok(r) => r.get_request(),\n+    };\n+\n+    let request_init = request_init_from_request(request);\n+\n+    // Step 4\n+    let (action_sender, action_receiver) = ipc::channel().unwrap();\n+    let fetch_context = Arc::new(Mutex::new(FetchContext {\n+        fetch_promise: Some(TrustedPromise::new(promise.clone())),\n+        response_object: Trusted::new(response.r()),","path":"components/script/fetch.rs","position":92,"original_position":92,"commit_id":"c1355499ce91edc63c02e20b498dffdba0e79072","original_commit_id":"d45dbae01fb7ec9d155f10ec0347d18f7cbd1467","user":{"login":"jdm","id":27658,"avatar_url":"https://avatars.githubusercontent.com/u/27658?v=3","gravatar_id":"","url":"https://api.github.com/users/jdm","html_url":"https://github.com/jdm","followers_url":"https://api.github.com/users/jdm/followers","following_url":"https://api.github.com/users/jdm/following{/other_user}","gists_url":"https://api.github.com/users/jdm/gists{/gist_id}","starred_url":"https://api.github.com/users/jdm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdm/subscriptions","organizations_url":"https://api.github.com/users/jdm/orgs","repos_url":"https://api.github.com/users/jdm/repos","events_url":"https://api.github.com/users/jdm/events{/privacy}","received_events_url":"https://api.github.com/users/jdm/received_events","type":"User","site_admin":false},"body":"We can use `&*` instead of `.r()` here.","created_at":"2016-09-21T13:41:54Z","updated_at":"2016-09-21T13:48:04Z","html_url":"https://github.com/servo/servo/pull/13323#discussion_r79835230","pull_request_url":"https://api.github.com/repos/servo/servo/pulls/13323","_links":{"self":{"href":"https://api.github.com/repos/servo/servo/pulls/comments/79835230"},"html":{"href":"https://github.com/servo/servo/pull/13323#discussion_r79835230"},"pull_request":{"href":"https://api.github.com/repos/servo/servo/pulls/13323"}}},"pull_request":{"url":"https://api.github.com/repos/servo/servo/pulls/13323","id":85836844,"html_url":"https://github.com/servo/servo/pull/13323","diff_url":"https://github.com/servo/servo/pull/13323.diff","patch_url":"https://github.com/servo/servo/pull/13323.patch","issue_url":"https://api.github.com/repos/servo/servo/issues/13323","number":13323,"state":"open","locked":false,"title":"Implement the Fetch method","user":{"login":"jeenalee","id":8248574,"avatar_url":"https://avatars.githubusercontent.com/u/8248574?v=3","gravatar_id":"","url":"https://api.github.com/users/jeenalee","html_url":"https://github.com/jeenalee","followers_url":"https://api.github.com/users/jeenalee/followers","following_url":"https://api.github.com/users/jeenalee/following{/other_user}","gists_url":"https://api.github.com/users/jeenalee/gists{/gist_id}","starred_url":"https://api.github.com/users/jeenalee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeenalee/subscriptions","organizations_url":"https://api.github.com/users/jeenalee/orgs","repos_url":"https://api.github.com/users/jeenalee/repos","events_url":"https://api.github.com/users/jeenalee/events{/privacy}","received_events_url":"https://api.github.com/users/jeenalee/received_events","type":"User","site_admin":false},"body":"<!-- Please describe your changes on the following line: -->\r\n\r\nThis 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.\r\n\r\nA few comments about the current fetch implementation:\r\n- The fetch method manually calls `JSAutoCompartment` in order to prevent SpiderMonkey from crashing. This may have to change in the future.\r\n- Not all `FetchResponseListener` methods are implemented.\r\n- `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.\r\n\r\n---\r\n<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->\r\n- [X] `./mach build -d` does not report any errors\r\n- [X] `./mach test-tidy` does not report any errors\r\n- [X] These changes fix #11898 (github issue number if applicable).\r\n\r\n<!-- Either: -->\r\n- [X] There are tests for these changes OR\r\n- [ ] These changes do not require tests because _____\r\n\r\n<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->\n\n<!-- Reviewable:start -->\n---\nThis change is [<img src=\"https://reviewable.io/review_button.svg\" height=\"34\" align=\"absmiddle\" alt=\"Reviewable\"/>](https://reviewable.io/reviews/servo/servo/13323)\n<!-- Reviewable:end -->\n","created_at":"2016-09-19T17:37:37Z","updated_at":"2016-09-21T13:48:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"75e38af339fd9e96d4ee1342180f7261ebf716b0","assignee":{"login":"jdm","id":27658,"avatar_url":"https://avatars.githubusercontent.com/u/27658?v=3","gravatar_id":"","url":"https://api.github.com/users/jdm","html_url":"https://github.com/jdm","followers_url":"https://api.github.com/users/jdm/followers","following_url":"https://api.github.com/users/jdm/following{/other_user}","gists_url":"https://api.github.com/users/jdm/gists{/gist_id}","starred_url":"https://api.github.com/users/jdm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdm/subscriptions","organizations_url":"https://api.github.com/users/jdm/orgs","repos_url":"https://api.github.com/users/jdm/repos","events_url":"https://api.github.com/users/jdm/events{/privacy}","received_events_url":"https://api.github.com/users/jdm/received_events","type":"User","site_admin":false},"assignees":[{"login":"jdm","id":27658,"avatar_url":"https://avatars.githubusercontent.com/u/27658?v=3","gravatar_id":"","url":"https://api.github.com/users/jdm","html_url":"https://github.com/jdm","followers_url":"https://api.github.com/users/jdm/followers","following_url":"https://api.github.com/users/jdm/following{/other_user}","gists_url":"https://api.github.com/users/jdm/gists{/gist_id}","starred_url":"https://api.github.com/users/jdm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdm/subscriptions","organizations_url":"https://api.github.com/users/jdm/orgs","repos_url":"https://api.github.com/users/jdm/repos","events_url":"https://api.github.com/users/jdm/events{/privacy}","received_events_url":"https://api.github.com/users/jdm/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/servo/servo/pulls/13323/commits","review_comments_url":"https://api.github.com/repos/servo/servo/pulls/13323/comments","review_comment_url":"https://api.github.com/repos/servo/servo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/servo/servo/issues/13323/comments","statuses_url":"https://api.github.com/repos/servo/servo/statuses/c1355499ce91edc63c02e20b498dffdba0e79072","head":{"label":"jeenalee:fetch","ref":"fetch","sha":"c1355499ce91edc63c02e20b498dffdba0e79072","user":{"login":"jeenalee","id":8248574,"avatar_url":"https://avatars.githubusercontent.com/u/8248574?v=3","gravatar_id":"","url":"https://api.github.com/users/jeenalee","html_url":"https://github.com/jeenalee","followers_url":"https://api.github.com/users/jeenalee/followers","following_url":"https://api.github.com/users/jeenalee/following{/other_user}","gists_url":"https://api.github.com/users/jeenalee/gists{/gist_id}","starred_url":"https://api.github.com/users/jeenalee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeenalee/subscriptions","organizations_url":"https://api.github.com/users/jeenalee/orgs","repos_url":"https://api.github.com/users/jeenalee/repos","events_url":"https://api.github.com/users/jeenalee/events{/privacy}","received_events_url":"https://api.github.com/users/jeenalee/received_events","type":"User","site_admin":false},"repo":{"id":62420576,"name":"servo","full_name":"jeenalee/servo","owner":{"login":"jeenalee","id":8248574,"avatar_url":"https://avatars.githubusercontent.com/u/8248574?v=3","gravatar_id":"","url":"https://api.github.com/users/jeenalee","html_url":"https://github.com/jeenalee","followers_url":"https://api.github.com/users/jeenalee/followers","following_url":"https://api.github.com/users/jeenalee/following{/other_user}","gists_url":"https://api.github.com/users/jeenalee/gists{/gist_id}","starred_url":"https://api.github.com/users/jeenalee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeenalee/subscriptions","organizations_url":"https://api.github.com/users/jeenalee/orgs","repos_url":"https://api.github.com/users/jeenalee/repos","events_url":"https://api.github.com/users/jeenalee/events{/privacy}","received_events_url":"https://api.github.com/users/jeenalee/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jeenalee/servo","description":"The Servo Browser Engine","fork":true,"url":"https://api.github.com/repos/jeenalee/servo","forks_url":"https://api.github.com/repos/jeenalee/servo/forks","keys_url":"https://api.github.com/repos/jeenalee/servo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jeenalee/servo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jeenalee/servo/teams","hooks_url":"https://api.github.com/repos/jeenalee/servo/hooks","issue_events_url":"https://api.github.com/repos/jeenalee/servo/issues/events{/number}","events_url":"https://api.github.com/repos/jeenalee/servo/events","assignees_url":"https://api.github.com/repos/jeenalee/servo/assignees{/user}","branches_url":"https://api.github.com/repos/jeenalee/servo/branches{/branch}","tags_url":"https://api.github.com/repos/jeenalee/servo/tags","blobs_url":"https://api.github.com/repos/jeenalee/servo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jeenalee/servo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jeenalee/servo/git/refs{/sha}","trees_url":"https://api.github.com/repos/jeenalee/servo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jeenalee/servo/statuses/{sha}","languages_url":"https://api.github.com/repos/jeenalee/servo/languages","stargazers_url":"https://api.github.com/repos/jeenalee/servo/stargazers","contributors_url":"https://api.github.com/repos/jeenalee/servo/contributors","subscribers_url":"https://api.github.com/repos/jeenalee/servo/subscribers","subscription_url":"https://api.github.com/repos/jeenalee/servo/subscription","commits_url":"https://api.github.com/repos/jeenalee/servo/commits{/sha}","git_commits_url":"https://api.github.com/repos/jeenalee/servo/git/commits{/sha}","comments_url":"https://api.github.com/repos/jeenalee/servo/comments{/number}","issue_comment_url":"https://api.github.com/repos/jeenalee/servo/issues/comments{/number}","contents_url":"https://api.github.com/repos/jeenalee/servo/contents/{+path}","compare_url":"https://api.github.com/repos/jeenalee/servo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jeenalee/servo/merges","archive_url":"https://api.github.com/repos/jeenalee/servo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jeenalee/servo/downloads","issues_url":"https://api.github.com/repos/jeenalee/servo/issues{/number}","pulls_url":"https://api.github.com/repos/jeenalee/servo/pulls{/number}","milestones_url":"https://api.github.com/repos/jeenalee/servo/milestones{/number}","notifications_url":"https://api.github.com/repos/jeenalee/servo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jeenalee/servo/labels{/name}","releases_url":"https://api.github.com/repos/jeenalee/servo/releases{/id}","deployments_url":"https://api.github.com/repos/jeenalee/servo/deployments","created_at":"2016-07-01T21:26:32Z","updated_at":"2016-07-01T21:17:01Z","pushed_at":"2016-09-19T23:01:49Z","git_url":"git://github.com/jeenalee/servo.git","ssh_url":"git@github.com:jeenalee/servo.git","clone_url":"https://github.com/jeenalee/servo.git","svn_url":"https://github.com/jeenalee/servo","homepage":"https://servo.org/","size":208644,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"servo:master","ref":"master","sha":"7d3c7beb215c18f10c03fb394eff9d152313dc59","user":{"login":"servo","id":2566135,"avatar_url":"https://avatars.githubusercontent.com/u/2566135?v=3","gravatar_id":"","url":"https://api.github.com/users/servo","html_url":"https://github.com/servo","followers_url":"https://api.github.com/users/servo/followers","following_url":"https://api.github.com/users/servo/following{/other_user}","gists_url":"https://api.github.com/users/servo/gists{/gist_id}","starred_url":"https://api.github.com/users/servo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/servo/subscriptions","organizations_url":"https://api.github.com/users/servo/orgs","repos_url":"https://api.github.com/users/servo/repos","events_url":"https://api.github.com/users/servo/events{/privacy}","received_events_url":"https://api.github.com/users/servo/received_events","type":"Organization","site_admin":false},"repo":{"id":3390243,"name":"servo","full_name":"servo/servo","owner":{"login":"servo","id":2566135,"avatar_url":"https://avatars.githubusercontent.com/u/2566135?v=3","gravatar_id":"","url":"https://api.github.com/users/servo","html_url":"https://github.com/servo","followers_url":"https://api.github.com/users/servo/followers","following_url":"https://api.github.com/users/servo/following{/other_user}","gists_url":"https://api.github.com/users/servo/gists{/gist_id}","starred_url":"https://api.github.com/users/servo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/servo/subscriptions","organizations_url":"https://api.github.com/users/servo/orgs","repos_url":"https://api.github.com/users/servo/repos","events_url":"https://api.github.com/users/servo/events{/privacy}","received_events_url":"https://api.github.com/users/servo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/servo/servo","description":"The Servo Browser Engine","fork":false,"url":"https://api.github.com/repos/servo/servo","forks_url":"https://api.github.com/repos/servo/servo/forks","keys_url":"https://api.github.com/repos/servo/servo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/servo/servo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/servo/servo/teams","hooks_url":"https://api.github.com/repos/servo/servo/hooks","issue_events_url":"https://api.github.com/repos/servo/servo/issues/events{/number}","events_url":"https://api.github.com/repos/servo/servo/events","assignees_url":"https://api.github.com/repos/servo/servo/assignees{/user}","branches_url":"https://api.github.com/repos/servo/servo/branches{/branch}","tags_url":"https://api.github.com/repos/servo/servo/tags","blobs_url":"https://api.github.com/repos/servo/servo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/servo/servo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/servo/servo/git/refs{/sha}","trees_url":"https://api.github.com/repos/servo/servo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/servo/servo/statuses/{sha}","languages_url":"https://api.github.com/repos/servo/servo/languages","stargazers_url":"https://api.github.com/repos/servo/servo/stargazers","contributors_url":"https://api.github.com/repos/servo/servo/contributors","subscribers_url":"https://api.github.com/repos/servo/servo/subscribers","subscription_url":"https://api.github.com/repos/servo/servo/subscription","commits_url":"https://api.github.com/repos/servo/servo/commits{/sha}","git_commits_url":"https://api.github.com/repos/servo/servo/git/commits{/sha}","comments_url":"https://api.github.com/repos/servo/servo/comments{/number}","issue_comment_url":"https://api.github.com/repos/servo/servo/issues/comments{/number}","contents_url":"https://api.github.com/repos/servo/servo/contents/{+path}","compare_url":"https://api.github.com/repos/servo/servo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/servo/servo/merges","archive_url":"https://api.github.com/repos/servo/servo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/servo/servo/downloads","issues_url":"https://api.github.com/repos/servo/servo/issues{/number}","pulls_url":"https://api.github.com/repos/servo/servo/pulls{/number}","milestones_url":"https://api.github.com/repos/servo/servo/milestones{/number}","notifications_url":"https://api.github.com/repos/servo/servo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/servo/servo/labels{/name}","releases_url":"https://api.github.com/repos/servo/servo/releases{/id}","deployments_url":"https://api.github.com/repos/servo/servo/deployments","created_at":"2012-02-08T19:07:25Z","updated_at":"2016-09-21T08:46:45Z","pushed_at":"2016-09-21T13:41:27Z","git_url":"git://github.com/servo/servo.git","ssh_url":"git@github.com:servo/servo.git","clone_url":"https://github.com/servo/servo.git","svn_url":"https://github.com/servo/servo","homepage":"https://servo.org/","size":295878,"stargazers_count":7932,"watchers_count":7932,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1269,"mirror_url":null,"open_issues_count":1731,"forks":1269,"open_issues":1731,"watchers":7932,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/servo/servo/pulls/13323"},"html":{"href":"https://github.com/servo/servo/pull/13323"},"issue":{"href":"https://api.github.com/repos/servo/servo/issues/13323"},"comments":{"href":"https://api.github.com/repos/servo/servo/issues/13323/comments"},"review_comments":{"href":"https://api.github.com/repos/servo/servo/pulls/13323/comments"},"review_comment":{"href":"https://api.github.com/repos/servo/servo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/servo/servo/pulls/13323/commits"},"statuses":{"href":"https://api.github.com/repos/servo/servo/statuses/c1355499ce91edc63c02e20b498dffdba0e79072"}}}}
{"actor":{"display_login":"jdm"}}