Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/polyfill/fetch.js

Issue 29333518: Issue 3515 - Added polyfill for the fetch() API (Closed)
Patch Set: Use strict mode Created Jan. 15, 2016, 3:22 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | metadata.common » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 "use strict";
kzar 2016/01/15 19:35:18 Like in the other review, shouldn't this be inside
Sebastian Noack 2016/01/19 13:09:31 Like in the other review, it shouldn't. ;) Puttin
kzar 2016/01/19 15:03:23 Acknowledged.
19
20 (function(global)
21 {
22 if ("fetch" in global)
23 return;
24
25 function Response(xhr)
26 {
27 this._xhr = xhr;
28 }
29 Response.prototype = {
kzar 2016/01/15 19:35:18 Seems like you've omitted quite a few of the Respo
Sebastian Noack 2016/01/19 13:09:31 As further explained in the other review, lets kee
kzar 2016/01/19 15:03:23 Acknowledged.
30 get ok()
31 {
32 return this._xhr.status >= 200 && this._xhr.status <= 299;
33 },
34 text: function()
35 {
36 return Promise.resolve(this._xhr.responseText);
37 }
38 };
39
40 global.fetch = function(url)
kzar 2016/01/15 19:35:18 Shouldn't this also take a second argument for the
Sebastian Noack 2016/01/19 13:09:31 See above.
41 {
42 return new Promise(function(resolve, reject)
43 {
44 var xhr = new XMLHttpRequest();
45
46 xhr.onload = function()
47 {
48 resolve(new Response(xhr));
49 };
50 xhr.onerror = function()
51 {
52 reject(new TypeError("Failed to fetch"));
53 };
54
55 xhr.open("GET", url);
56 xhr.send();
57 });
58 };
59 })(this);
OLDNEW
« no previous file with comments | « no previous file | metadata.common » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld