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

Issue 29333522: Issue 3515 - Adapted polyfill for URL class for consistency (Closed)

Created:
Jan. 14, 2016, 5:22 p.m. by Sebastian Noack
Modified:
Jan. 19, 2016, 4:41 p.m.
Reviewers:
kzar
Visibility:
Public.

Description

Issue 3515 - Adapted polyfill for URL class for consistency

Patch Set 1 #

Total comments: 1

Patch Set 2 : Rebased, fixed IIFE #

Patch Set 3 : Use strict mode #

Total comments: 18

Patch Set 4 : Rebased and addressed comments #

Unified diffs Side-by-side diffs Delta from patch set Stats (+69 lines, -57 lines) Patch
A lib/polyfills/url.js View 1 2 3 1 chunk +65 lines, -0 lines 0 comments Download
M lib/url.js View 1 chunk +0 lines, -31 lines 0 comments Download
M metadata.common View 1 2 3 1 chunk +2 lines, -1 line 0 comments Download
M safari/ext/background.js View 2 chunks +2 lines, -25 lines 0 comments Download

Messages

Total messages: 7
Sebastian Noack
https://codereview.adblockplus.org/29333522/diff/29333523/safari/ext/background.js File safari/ext/background.js (left): https://codereview.adblockplus.org/29333522/diff/29333523/safari/ext/background.js#oldcode170 safari/ext/background.js:170: var Frame = function(url, parent) Note that all changes ...
Jan. 14, 2016, 5:27 p.m. (2016-01-14 17:27:21 UTC) #1
Sebastian Noack
Jan. 14, 2016, 5:59 p.m. (2016-01-14 17:59:02 UTC) #2
kzar
https://codereview.adblockplus.org/29333522/diff/29333626/lib/polyfill/url.js File lib/polyfill/url.js (right): https://codereview.adblockplus.org/29333522/diff/29333626/lib/polyfill/url.js#newcode18 lib/polyfill/url.js:18: "use strict"; Again shouldn't this be inside the IIFE? ...
Jan. 16, 2016, 4:05 p.m. (2016-01-16 16:05:29 UTC) #3
Sebastian Noack
https://codereview.adblockplus.org/29333522/diff/29333626/lib/polyfill/url.js File lib/polyfill/url.js (right): https://codereview.adblockplus.org/29333522/diff/29333626/lib/polyfill/url.js#newcode18 lib/polyfill/url.js:18: "use strict"; On 2016/01/16 16:05:28, kzar wrote: > Again ...
Jan. 19, 2016, 2:13 p.m. (2016-01-19 14:13:22 UTC) #4
kzar
https://codereview.adblockplus.org/29333522/diff/29333626/lib/polyfill/url.js File lib/polyfill/url.js (right): https://codereview.adblockplus.org/29333522/diff/29333626/lib/polyfill/url.js#newcode18 lib/polyfill/url.js:18: "use strict"; On 2016/01/19 14:13:21, Sebastian Noack wrote: > ...
Jan. 19, 2016, 3:24 p.m. (2016-01-19 15:24:03 UTC) #5
Sebastian Noack
https://codereview.adblockplus.org/29333522/diff/29333626/lib/polyfill/url.js File lib/polyfill/url.js (right): https://codereview.adblockplus.org/29333522/diff/29333626/lib/polyfill/url.js#newcode26 lib/polyfill/url.js:26: // Chrome <32 didn't implement any of those properties ...
Jan. 19, 2016, 4:03 p.m. (2016-01-19 16:03:40 UTC) #6
kzar
Jan. 19, 2016, 4:12 p.m. (2016-01-19 16:12:07 UTC) #7
LGTM

https://codereview.adblockplus.org/29333522/diff/29333626/lib/polyfill/url.js
File lib/polyfill/url.js (right):

https://codereview.adblockplus.org/29333522/diff/29333626/lib/polyfill/url.js...
lib/polyfill/url.js:26: // Chrome <32 didn't implement any of those properties
On 2016/01/19 16:03:39, Sebastian Noack wrote:
> On 2016/01/19 15:24:02, kzar wrote:
> > On 2016/01/19 14:13:21, Sebastian Noack wrote:
> > > On 2016/01/16 16:05:28, kzar wrote:
> > > > Couldn't we avoid checking these properties exist for versions 35
onwards?
> > > > Something like:
> > > > 
> > > > if ("URL" in global)
> > > >   return;
> > > > else if ("webkitURL" in global)
> > > > {
> > > >   global.URL = global.webkitURL;
> > > >   var URLProperties = ...
> > > 
> > > Note that Safari 6 and Chrome 32-34 uses the non-standard name webkitURL
> while
> > > it already provides these properties. And we need that list of properties
> > anyway
> > > below.
> > 
> > Yea I understand that, just suggesting changing the logic so we don't check
> the
> > properties if URL already exists. If URL already exists we know that we're
> > running on a new enough version of Chrome / Safari as to provide URL with
the
> > correct properties, right?
> > 
> > As far as I see it, the only time we're not sure if the correct properties
are
> > given is when webkitURL exists but not URL.
> 
> That seems to be true. But skipping that check if window.URL exist doesn't
make
> the code here any simpler. In fact it would be two additional lines, without
> much simplifying the remainder.
> 
> However, if the check is always executed, that code path is always tested,
even
> when running on the latest Chrome version.
> 
> And performance-wise, it's only executed once at startup and the check is
quite
> fast. So not worth any optimization.

Acknowledged.

https://codereview.adblockplus.org/29333522/diff/29333626/lib/polyfill/url.js...
lib/polyfill/url.js:41: global.URL = function(url, baseUrl)
On 2016/01/19 16:03:39, Sebastian Noack wrote:
> On 2016/01/19 15:24:02, kzar wrote:
> > On 2016/01/19 14:13:21, Sebastian Noack wrote:
> > > On 2016/01/16 16:05:28, kzar wrote:
> > > > A few things that I noticed behave differently with this:
> > > >
> > > >  - The hash part of the URL does not seem to be parsed.
> > > >  - The username and password parts of the URL also aren't parsed.
> > > 
> > > As for the other two polyfills, it's not the objective to be 100% complete
> > with
> > > the standard. But to only implement the properties we need. In particular
> with
> > > the approach here adding additional properties would increase the memory
> > > footprint.
> > > 
> > > >  - Calling with a relative URL but no base URL does not throw an
> exception.
> > > >  - Calling with no arguments at all does not throw an exception.
> > > 
> > > It's probably not worth adding complexity to handle that scenario. The
> reason
> > > this polyfill is as simple as it is is that we merely delegate to an <a>
> > > element. Also since we don't catch any exceptions thrown here, that
> > > inconsistency wouldn't make anything worse.
> > > 
> > > And after all, the behavior doesn't change with this patch.
> > 
> > I think with the missing properties, especially hash, we should include
them.
> Or
> > if not we should at least leave a comment here, I can imagine someone
writing
> > code that uses the hash of a URL, testing it on a modern browser and not
> > thinking to check that the polyfill also supports the properties used.
> > 
> > We could end up with undefined instead of the hash string, which depending
on
> > how it's used might not even throw an exception.
> 
> The way URL objects are currently used in Adblock Plus username, password and
> hash are explicitly ignored in stringifyURL anyway. That behavior is even
> documented there.
> 
> And if in the future, URL objects should be used in another way, a comment
> wouldn't help either, if one only tests in the latest version of any browser.
> 
> And still, this is unrelated of the change here, which is about unifying the
> polyfills, not about changing their behavior.

Acknowledged.

Powered by Google App Engine
This is Rietveld