Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(411)

Side by Side Diff: Source/modules/serviceworkers/polyfills/fetchPolyfill.js

Issue 311343003: ServiceWorker polyfill Fetch implementation. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fix memory error Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/modules/serviceworkers/polyfills/cachePolyfill.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // A simple, incomplete implementation of Fetch, intended to facilitate end
6 // to end serviceworker testing.
7
8 // See http://fetch.spec.whatwg.org/#fetch-method
9
10 (function (global) {
11 var _castToRequest = function (item) {
12 if (typeof item === 'string') {
13 item = new Request({
14 url: item
15 });
16 }
17 return item;
18 };
19
20 // FIXME: Support init argument to fetch.
21 var fetch = function(request) {
22 request = _castToRequest(request);
23
24 return new Promise(function(resolve, reject) {
25 // FIXME: Use extra headers from |request|.
26 var xhr = new XMLHttpRequest();
27 xhr.open(request.method, request.url, true /* async */);
28 xhr.send(null);
29 xhr.onreadystatechange = function() {
30 if (xhr.readyState !== 4) return;
31
32 var response = new Response({
33 status: xhr.status,
34 statusText: xhr.statusText,
35 // FIXME: Set response.headers.
36 // FIXME: Set response.method when available.
37 // FIXME: Set response.url when available.
38 // FIXME: Set response.body when available.
39 });
40
41 if (xhr.status === 200) {
42 resolve(response);
43 } else {
44 reject(response);
45 }
46 };
47 });
48 };
49
50 global.fetch = global.fetch || fetch;
51 }(self)); // window or worker global scope
OLDNEW
« no previous file with comments | « Source/modules/serviceworkers/polyfills/cachePolyfill.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698