Skip to content
This repository has been archived by the owner on Jun 27, 2018. It is now read-only.

Iterating over array entries using "for .. in" breaks if Array polyfills are used #57

Open
RichardBradley opened this issue Dec 15, 2015 · 1 comment · May be fixed by #58
Open

Iterating over array entries using "for .. in" breaks if Array polyfills are used #57

RichardBradley opened this issue Dec 15, 2015 · 1 comment · May be fixed by #58

Comments

@RichardBradley
Copy link
Contributor

Hi,

I'm trying to use ng-admin with an older browser (PhantomJS 1.9, backed by Safari 5).
It doesn't have Array.find, so I'm using this polyfill.

However, this breaks ng-admin in another way, because this code attempts to iterate over array entries using "for .. in":

getMappedValue(value, entry) {
    for (let i in this._maps) {
        value = this._maps[i](value, entry);
    }

    return value;
}

It's not safe to iterate over arrays in this way, see e.g. this stackoverflow answer, as any functions which have been added to Array.prototype will get returned along with all the array entries.

I believe that this and all other array loops in ng-admin and admin-config need converting to use a "for (var i = 0; i < array.length; i++) { style loop instead.

A quick grep suggests that there are a great many such loops in ng-admin and admin-config :-(

@KonstantinYegupov
Copy link

Since ng-admin, as far as I can tell, is written in ES 2015, I believe the proper construct to use is:
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/for...of

RichardBradley added a commit to RichardBradley/admin-config that referenced this issue Dec 16, 2015
RichardBradley added a commit to RichardBradley/admin-config that referenced this issue Dec 16, 2015
The former causes "ReferenceError: Symbol is not defined" in ng-admin.
RichardBradley added a commit to RichardBradley/admin-config that referenced this issue May 24, 2016
RichardBradley added a commit to RichardBradley/admin-config that referenced this issue May 24, 2016
The former causes "ReferenceError: Symbol is not defined" in ng-admin.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants