Closed Bug 925989 Opened 6 years ago Closed 4 years ago

Replace E4X for-each with ES6 for-of in Add-on SDK and chrome JS


(Core :: JavaScript Engine, defect)

Not set





(Reporter: evilpie, Unassigned)




(1 file)

No description provided.
Assignee: nobody → evilpies
Attachment #816253 - Flags: review?(Ms2ger)
I have a few more patches, but they are really huge. Somebody wants to volunteer? They touch a lot of files in different components.
I can review some.  Are all the transformations just turning this:

  for each (let X in Y)

into this

  for (let X of Y)

or are there other forms?
I think in practice this should work, but there might be some differences.
17:52 <evilpie> jorendorff: what are the differences beween for each and for of?
17:52 <evilpie> seems like only a custom iterator property?
17:52 <jorendorff> evilpie: for-each iterates over *properties*
17:54 <jorendorff> evilpie: for-of iterates over whatever obj.iterator() returns, so types like Map and Set, and generators, which don't treat their contents as properties, can still be iterable
17:54 <jorendorff> sorry
17:54 <jorendorff> obj[std_iterator]()
17:55 <jorendorff> (it should've been called .iterator() but TC39 <3 symbols)
17:56 <evilpie> oh because for each (x in {a: 1}) {} works
17:56 <sankha93> what is difference between the @@iterator and the symbol?
17:56 <evilpie> so we need to be careful to use Iterator() or something in that case
If for-each is used on an array then it can usually be changed to for-of easily. If for each is used on any other type of object, then the transformation looks like, from:

> for each (let value in obj) {


> for (let key in obj) {
>   let value = obj[key];
I've put the existing bugs that are "remove for each from ..." as blockers for this. Feel free to do this all as part of one big patch or however you want to do it, just wanted to make sure they get closed if they're fixed when this is fixed.
Depends on: 866733, 825800, 825801
Verifying every single use and making sure that it is actually possible to convert to for .. of in a straightforward way almost seems like an impossible task.
Assignee: evilpies → nobody
Attachment #816253 - Flags: review?(Ms2ger)
Duplicate of this bug: 791348
Depends on: 1083467
OS: Linux → All
Hardware: x86_64 → All
Summary: Replace for each with for of in Mozilla code → Replace E4X for-each with ES6 for-of in Add-on SDK and chrome JS
All blocking bugs are fixed and other use are also removed in other bugs that blocks bug 1083470.
Closed: 4 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.