 Issue 29333522:
  Issue 3515 - Adapted polyfill for URL class for consistency  (Closed)
    
  
    Issue 29333522:
  Issue 3515 - Adapted polyfill for URL class for consistency  (Closed) 
  | Index: lib/polyfill/url.js | 
| =================================================================== | 
| new file mode 100644 | 
| --- /dev/null | 
| +++ b/lib/polyfill/url.js | 
| @@ -0,0 +1,55 @@ | 
| +/* | 
| + * This file is part of Adblock Plus <https://adblockplus.org/>, | 
| + * Copyright (C) 2006-2015 Eyeo GmbH | 
| + * | 
| + * Adblock Plus is free software: you can redistribute it and/or modify | 
| + * it under the terms of the GNU General Public License version 3 as | 
| + * published by the Free Software Foundation. | 
| + * | 
| + * Adblock Plus is distributed in the hope that it will be useful, | 
| + * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
| + * GNU General Public License for more details. | 
| + * | 
| + * You should have received a copy of the GNU General Public License | 
| + * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 
| + */ | 
| + | 
| +"use strict"; | 
| 
kzar
2016/01/16 16:05:28
Again shouldn't this be inside the IIFE?
 
Sebastian Noack
2016/01/19 14:13:21
Again, it shouldn't. ;)
Putting "use strict" on t
 
kzar
2016/01/19 15:24:02
Acknowledged.
 | 
| + | 
| +(function(global) | 
| +{ | 
| + // Chrome <35 and Safari 6 used the non-standard name webkitURL | 
| + if (!("URL" in global) && "webkitURL" in global) | 
| + global.URL = global.webkitURL; | 
| + | 
| + // Chrome <32 didn't implement any of those properties | 
| 
kzar
2016/01/16 16:05:28
Couldn't we avoid checking these properties exist
 
Sebastian Noack
2016/01/19 14:13:21
Note that Safari 6 and Chrome 32-34 uses the non-s
 
kzar
2016/01/19 15:24:02
Yea I understand that, just suggesting changing th
 
Sebastian Noack
2016/01/19 16:03:39
That seems to be true. But skipping that check if
 
kzar
2016/01/19 16:12:07
Acknowledged.
 | 
| + var URLProperties = ["href", "protocol", "host", "hostname", "pathname", "search"]; | 
| 
kzar
2016/01/16 16:05:28
Nit: this line is too long
 
Sebastian Noack
2016/01/19 14:13:21
Done.
 | 
| + if ("URL" in global) | 
| + { | 
| + var dummy = new URL("about:blank"); | 
| + if (URLProperties.every(function(prop) { return prop in dummy; })) | 
| + return; | 
| + } | 
| + | 
| + var doc = document.implementation.createHTMLDocument(); | 
| + var base = doc.createElement("base"); | 
| + doc.head.appendChild(base); | 
| + var anchor = doc.createElement("a"); | 
| + doc.body.appendChild(anchor); | 
| + | 
| + global.URL = function(url, baseUrl) | 
| 
kzar
2016/01/16 16:05:28
A few things that I noticed behave differently wit
 
Sebastian Noack
2016/01/19 14:13:21
As for the other two polyfills, it's not the objec
 
kzar
2016/01/19 15:24:02
I think with the missing properties, especially ha
 
Sebastian Noack
2016/01/19 16:03:39
The way URL objects are currently used in Adblock
 
kzar
2016/01/19 16:12:07
Acknowledged.
 | 
| + { | 
| + if (baseUrl instanceof URL) | 
| 
kzar
2016/01/16 16:05:28
should be `... instanceof global.URL)`?
 
Sebastian Noack
2016/01/19 14:13:21
As in the other review, that isn't necessary, but
 
kzar
2016/01/19 15:24:02
Acknowledged.
 | 
| + base.href = baseUrl.href; | 
| + else | 
| + base.href = baseUrl || ""; | 
| + anchor.href = url; | 
| + | 
| + for (var i = 0; i < URLProperties.length; i++) | 
| + { | 
| + var prop = URLProperties[i]; | 
| + this[prop] = anchor[prop]; | 
| + } | 
| + }; | 
| +})(this); |