Closed
Bug 1217093
Opened 9 years ago
Closed 9 years ago
Remove use of for-each from dom/.
Categories
(Firefox :: General, defect)
Firefox
General
Tracking
()
RESOLVED
FIXED
Firefox 44
Tracking | Status | |
---|---|---|
firefox44 | --- | fixed |
People
(Reporter: arai, Assigned: arai)
References
Details
Attachments
(2 files)
(deleted),
patch
|
smaug
:
review+
|
Details | Diff | Splinter Review |
(deleted),
text/plain
|
Details |
Need to replace non-standard for-each with one of:
* for-of
* for-in
* array.map/array.filter for array-comprehension
as a part of bug 1083470.
converting rules are following:
* for-each
* for each (let x in array) { ... }
-> for (let x of array) { ... }
* for each (let x in object) { ... }
-> for (let key in object) { let x = object[key]; ... }
* for each (let [key, value] in Iterator(object)) { ... }
-> for (let key in object) { let value = object[key]; ... }
* for each (let x in array) { ... }
where array can be null or undefined
-> if (array) { for (let x of array) { ... } }
* legacy array comprehension with for-each
* [EXPR for each (x in array)]
-> array.map(x => EXPR)
* [EXPR for each (x in array) if (COND)]
-> array.filter(x => COND).map(x => EXPR)
* [x for each (x in array) if (COND)]
-> array.filter(x => COND)
* [EXPR for each ([i, x] in Iterator(array)) if (g(x, i)]
-> array.filter((x, i) => g(x, i)).map((x => EXPR)
* [EXPR for each (x in arraylike)]
-> Array.from(arraylike).map(x => EXPR)
* [EXPR for each (x in string)]
-> Array.prototype.slice.call(string).map(x => EXPR)
// Array.from behaves differently for surrogate-pair
I'll post a patch shortly.
Assignee | ||
Comment 1•9 years ago
|
||
try runs here
linux: https://treeherder.mozilla.org/#/jobs?repo=try&revision=f521b1264cb4
mac (after linux with some fix): https://treeherder.mozilla.org/#/jobs?repo=try&revision=d5ecb19c84f6
win (after mac with some fix): https://treeherder.mozilla.org/#/jobs?repo=try&revision=adf800f88efd
finally xpcshell passed on linux (after win with some fix): https://treeherder.mozilla.org/#/jobs?repo=try&revision=526c234c897d
Attachment #8676992 -
Flags: review?(bugs)
Assignee | ||
Comment 2•9 years ago
|
||
here's the result of investigation for some complicated case.
Assignee | ||
Comment 3•9 years ago
|
||
update from other bugs.
Newer Array comprehension ([for (x of y) x]) is now also non-standard and we shouldn't use it as a replacement for legacy array comprehension. I used map/filter instead in the patch :)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Array_comprehensions
Comment 4•9 years ago
|
||
Comment on attachment 8676992 [details] [diff] [review]
Remove for-each from dom/.
I don't know what the type of participantIds is in
dom/mobilemessage/tests/marionette/test_mmdb_upgradeSchema_22.js
Please make sure it is handled correctly.
Attachment #8676992 -
Flags: review?(bugs) → review+
Assignee | ||
Comment 5•9 years ago
|
||
Thank you for pointing that out :)
It's a non-null Array.
https://dxr.mozilla.org/mozilla-central/rev/473aefe5bd85842eeb142e0cde8e2cd21edbf40b/dom/mobilemessage/tests/marionette/test_mmdb_upgradeSchema_22.js#153
> this.findThreadRecordByPlmnAddresses(aThreadStore, aParticipantStore,
> aAddresses, true,
> function(threadRecord, participantIds) {
> if (!participantIds) {
> aTransaction.abort();
> return;
> }
https://dxr.mozilla.org/mozilla-central/rev/473aefe5bd85842eeb142e0cde8e2cd21edbf40b/dom/mobilemessage/gonk/MobileMessageDB.jsm#2499
> findThreadRecordByPlmnAddresses: function(aThreadStore, aParticipantStore,
> aAddresses, aCreateParticipants,
> aCallback) {
> ...
> this.findParticipantIdsByPlmnAddresses(aParticipantStore, aAddresses,
> aCreateParticipants, false,
> function(participantIds) {
> ...
> aCallback(null, null);
> ...
> aCallback(threadRecord, participantIds);
https://dxr.mozilla.org/mozilla-central/rev/473aefe5bd85842eeb142e0cde8e2cd21edbf40b/dom/mobilemessage/gonk/MobileMessageDB.jsm#2379
> findParticipantIdsByPlmnAddresses: function(aParticipantStore, aAddresses,
> aCreate, aSkipNonexistent, aCallback) {
> ...
> aCallback(null);
> ...
> (function findParticipantId(index, result) {
> ...
> aCallback(result);
> ...
> aCallback(null);
> ...
> findParticipantId(index, result);
> ...
> }) (0, []);
Assignee | ||
Comment 6•9 years ago
|
||
https://hg.mozilla.org/integration/mozilla-inbound/rev/fc6901b48e21ad9cb3331a77c5851f88814d2615
Bug 1217093 - Remove for-each from dom/. r=smaug
Status: NEW → RESOLVED
Closed: 9 years ago
status-firefox44:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → Firefox 44
You need to log in
before you can comment on or make changes to this bug.
Description
•