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

Issue 29445648: Issue 5264 - Return page objects instead of page IDs (Closed)

Created:
May 22, 2017, 3:50 p.m. by Manish Jethani
Modified:
May 23, 2017, 6:49 p.m.
Reviewers:
Sebastian Noack, kzar
CC:
Wladimir Palant
Base URL:
https://hg.adblockplus.org/adblockpluschrome/
Visibility:
Public.

Description

After the changeset 2cebd252b232 (#5161) in adblockpluschrome, there's an issue on the options page: when you add a filter subscription, it throws an exception. There are two problems: (1) keys() returns an iterable, not an array; (2) the keys themselves are page IDs, not page objects as the caller expects. This patch modifies ext.PageMap.prototype.keys so that it returns an array of page objects instead of an iterable of page IDs.

Patch Set 1 #

Patch Set 2 : Return page objects instead of page IDs #

Total comments: 5
Unified diffs Side-by-side diffs Delta from patch set Stats (+1 line, -1 line) Patch
M ext/background.js View 1 1 chunk +1 line, -1 line 5 comments Download

Messages

Total messages: 12
Manish Jethani
May 22, 2017, 3:50 p.m. (2017-05-22 15:50:08 UTC) #1
Manish Jethani
Patch Set 1 See issue description.
May 22, 2017, 3:55 p.m. (2017-05-22 15:55:10 UTC) #2
kzar
On 2017/05/22 15:55:10, Manish Jethani wrote: > Patch Set 1 > > See issue description. ...
May 22, 2017, 3:57 p.m. (2017-05-22 15:57:30 UTC) #3
Manish Jethani
On 2017/05/22 15:57:30, kzar wrote: > On 2017/05/22 15:55:10, Manish Jethani wrote: > > Patch ...
May 22, 2017, 4:19 p.m. (2017-05-22 16:19:32 UTC) #4
kzar
On 2017/05/22 16:19:32, Manish Jethani wrote: > On 2017/05/22 15:57:30, kzar wrote: > > On ...
May 22, 2017, 4:43 p.m. (2017-05-22 16:43:52 UTC) #5
Manish Jethani
On 2017/05/22 15:57:30, kzar wrote: > On 2017/05/22 15:55:10, Manish Jethani wrote: > > Patch ...
May 22, 2017, 5:04 p.m. (2017-05-22 17:04:14 UTC) #6
Manish Jethani
Patch Set 2: Return page objects instead of page IDs A much more straightforward fix.
May 22, 2017, 5:09 p.m. (2017-05-22 17:09:48 UTC) #7
kzar
https://codereview.adblockplus.org/29445648/diff/29445659/ext/background.js File ext/background.js (right): https://codereview.adblockplus.org/29445648/diff/29445659/ext/background.js#newcode38 ext/background.js:38: return Array.from(this._map.keys()).map(ext.getPage); I wonder if you could do `return ...
May 23, 2017, 11:47 a.m. (2017-05-23 11:47:59 UTC) #8
Sebastian Noack
LGTM https://codereview.adblockplus.org/29445648/diff/29445659/ext/background.js File ext/background.js (right): https://codereview.adblockplus.org/29445648/diff/29445659/ext/background.js#newcode38 ext/background.js:38: return Array.from(this._map.keys()).map(ext.getPage); On 2017/05/23 11:47:59, kzar wrote: > ...
May 23, 2017, 12:16 p.m. (2017-05-23 12:16:54 UTC) #9
Manish Jethani
https://codereview.adblockplus.org/29445648/diff/29445659/ext/background.js File ext/background.js (right): https://codereview.adblockplus.org/29445648/diff/29445659/ext/background.js#newcode38 ext/background.js:38: return Array.from(this._map.keys()).map(ext.getPage); On 2017/05/23 12:16:54, Sebastian Noack wrote: > ...
May 23, 2017, 12:32 p.m. (2017-05-23 12:32:27 UTC) #10
Sebastian Noack
https://codereview.adblockplus.org/29445648/diff/29445659/ext/background.js File ext/background.js (right): https://codereview.adblockplus.org/29445648/diff/29445659/ext/background.js#newcode38 ext/background.js:38: return Array.from(this._map.keys()).map(ext.getPage); On 2017/05/23 12:32:27, Manish Jethani wrote: > ...
May 23, 2017, 3:09 p.m. (2017-05-23 15:09:18 UTC) #11
kzar
May 23, 2017, 4:15 p.m. (2017-05-23 16:15:04 UTC) #12
LGTM

https://codereview.adblockplus.org/29445648/diff/29445659/ext/background.js
File ext/background.js (right):

https://codereview.adblockplus.org/29445648/diff/29445659/ext/background.js#n...
ext/background.js:38: return Array.from(this._map.keys()).map(ext.getPage);
On 2017/05/23 15:09:18, Sebastian Noack wrote:
> On 2017/05/23 12:32:27, Manish Jethani wrote:
> > On 2017/05/23 12:16:54, Sebastian Noack wrote:
> > > On 2017/05/23 11:47:59, kzar wrote:
> > > > I wonder if you could do `return
> Array.prototype.map.call(this._map.keys(),
> > > > ext.getPage)`?
> > > 
> > > Please don't. Array generics are non-standard and deprecated:
> > >
> >
>
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Obje...
> > 
> > I think Dave meant Array.prototype.map rather than Array.map. The former
isn't
> > going anywhere, though for better or worse it won't work with a
non-array-like
> > object.
> > 
> > To map an iterable regardless of its type you have to use a function like
> this: 
> > 
> > https://codereview.adblockplus.org/29417597/patch/29417598/29417600
> > 
> > If you have generators support, then this: 
> > 
> > function* mapIterable(iterable, callback)
> > {
> >   for (let entry of iterable)
> >     yield callback(entry);
> > }
> > 
> > Here we don't have too many keys though, it's OK to create an intermediate
> > array.
> 
> Sorry, you are right, I mixed things up, calling array method's through the
> prototype isn't generally an issue, but as you pointed out it only works with
> array-like objects.
> 
> I wouldn't be opposed to make keys() a generator function. All browsers this
> code is running on support generators, and it doesn't seem to make the code
any
> more complicated. However, this would imply that there is no usage of keys()
> which access the result like an array, I didn't check this.
> 
> Alternatively, we could create an array like below:
> 
>   let pages = [];
>   for (let key of this._map.keys())
>     pages.push(ext.getPage(key));
>   return pages;
> 
> In the end it doesn't matter much, so as far as I'm concerned, just pick the
> approach that seems best to you.

Acknowledged.

Powered by Google App Engine
This is Rietveld