Left: | ||
Right: |
OLD | NEW |
---|---|
(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); | |
OLD | NEW |