Opened 10 years ago
Last modified 5 years ago
#597 reopened defect
Don't iterate Array with for...in
| Reported by: | dstillman | Owned by: | dstillman |
|---|---|---|---|
| Priority: | major | Milestone: | |
| Component: | connectors | Version: | |
| Keywords: | helpwanted | Cc: | simon, ajlyon |
Description
For better compatibility with extensions that extend Array.prototype, don't use for...in to iterate arrays. Can't do anything about extensions that extend Object.prototype, though.
Change History (15)
comment:1 Changed 10 years ago by dstillman
comment:2 Changed 10 years ago by dstillman
- Keywords helpwanted added
comment:3 Changed 10 years ago by dstillman
comment:4 Changed 10 years ago by dstillman
comment:5 Changed 9 years ago by dstillman
comment:6 Changed 9 years ago by dstillman
- Cc simon added
So I've just done some more testing here, and it looks like we should at least be careful about this in window code. The XPCOM object is insulated from this problem, but our own window scope code is not, and so an extension that bundled Prototype or otherwise extended Array.prototype could cause nasty problems in subtle ways.
So, we could probably continue to use for...in in xpcom code with impunity, but in all other code we should take care to use a standard for (var i=0; i<max; i++) loop and fix any remaining for...in loops over arrays.
comment:7 Changed 9 years ago by dstillman
- Milestone 1.0 RC 4 deleted
- Version 1.0 deleted
comment:8 Changed 7 years ago by dstillman
- Resolution set to fixed
- Status changed from new to closed
We should still try not to use "for ... in" in window code, but this hasn't been an issue in a long time, so we've either fixed all of these or other extensions have stopped extending Array.prototype.
comment:9 Changed 5 years ago by simon
- Component changed from data layer to connectors
- Resolution fixed deleted
- Status changed from closed to reopened
We need to avoid for...in in all connector-related code, since pages can extend Array.prototype.
comment:10 Changed 5 years ago by simon
In [10403]:
comment:11 Changed 5 years ago by ajlyon
Is this something that affects translators as well, or just core code?
comment:12 Changed 5 years ago by ajlyon
- Cc ajlyon added
comment:13 Changed 5 years ago by simon
This affects some translators as well. The translator framework and translators that scrape pages that extend Array.prototype will eventually need to be modified not to iterate over arrays with for...in. However, most sites don't do this, so most translators should be fine.
comment:14 Changed 5 years ago by ajlyon
So the sandbox protects translators from extensions that extend Array.prototype, correct?
If it's entirely a case of just watching out for sites that extend Array.prototype, then I'll just try to keep this in mind as a potential gotcha in future development and troubleshooting and do nothing at the moment.
comment:15 Changed 5 years ago by simon
In [10405]:
(In [1347]) Addresses #597, Don't iterate Array with for...in