.entries() vs. the web

# Oliver Hunt (11 years ago)

It turns out there are a number of sites (such as mobile.twitter.com) that are property detecting .entries on objects, and that means that they're breaking when Array.prototype.entries is provided.

We're removing it from JSC now, until we can find a way to expose it without causing site breakage, although this does seem like fixing it would require bringing back the awful "pretend that you're undefined" horror.

# Tab Atkins Jr. (11 years ago)

What are they using the detection for?

# Erik Arvidsson (11 years ago)

That is why you need to implement @unscopables too.

# Oliver Hunt (11 years ago)

@@unscopeable doesn't work as they are not using |with|

The logic is something along the lines of

if (foo.entries) ...

It looks like there are paths that objects or arrays may path through, with entries being a perfectly reasonable property name in the object case, but now the array case hits the entries property on Array.prototype

# Claude Pache (11 years ago)

Apparently, this problem was already known more than 4 months ago:

bugzilla.mozilla.org/show_bug.cgi?id=924386#c19

I guess it specifically affect the mobile web? for it didn't prevent Firefox to ship Array.prototype.entries in v28, released on March 18.

—Claude

# Andrea Giammarchi (11 years ago)

This is a gently reminder I don't represent my company anyhow in this mailing list but actually I've been working on mobile web here at twitter for 1.5 years how ... thanks for the report, I'll do what I can (already patched, waiting reviews) + I don't think mobile web should block anyhow new standards no matter where I work.

Best

# Brendan Eich (11 years ago)

Would .items fare better, I wonder.

# Rick Waldron (11 years ago)

On Mon, Jun 16, 2014 at 11:11 PM, Brendan Eich <brendan at mozilla.org> wrote:

Would .items fare better, I wonder.

Or outreach to sites the break?

# Alex Russell (11 years ago)

Right. Would love to know the size/traffic of the "number of sites" affected.

# Andrea Giammarchi (11 years ago)

FWIW I think this is a non issue and "how many" should not be relevant.

If developers understand the issue, the fix is straight forward.

instead of doing this

if (obj.entries) {
  // do stuff with entries
} else if(Array.isArray(obj)) {
  // do stuff with obj
}

or this

var entries = obj.entries || obj;

we should just advocate this:

if (Array.isArray(obj)) {
  // do stuff with obj
} else if(obj.entries) {
  // do stuff with entry property
}

or using instanceof when the realm is not a problem (if performance is a concern and Array.isArray is the bottleneck which is rarely the case)

This also seems to be an API only related problem where both Array and Object could be passed as parameter but yeah, objects with properties named as list, items, or entries are quite common but I personally prefer a future proof approach/small refactoring than a stopper for new specs.

my 2 cents

# Alex Russell (11 years ago)

On Tue, Jun 17, 2014 at 11:46 AM, Andrea Giammarchi andrea.giammarchi at gmail.com> wrote:

FWIW I think this is a non issue and "how many" should not be relevant.

If developers understand the issue, the fix is straight forward.

I wish to live in your world of unicorns and magic for in that world I AM A WIZARD.

# Andrea Giammarchi (11 years ago)