paulmillr / es6-shim

ECMAScript 6 compatibility shims for legacy JS engines
http://paulmillr.com
MIT License
3.11k stars 387 forks source link

Allowed iterator on empty object #468

Closed gnh1201 closed 3 years ago

gnh1201 commented 3 years ago

For example:

var Apps = {
    ProcessName: {}   // empty object
};

for (var uniqueId in Apps.ProcessName) {
  console.log("test: " + typeof(uniqueId));
  console.log("test: " + uniqueId);
  console.log("test: " + typeof(Apps.ProcessName[uniqueId]));
  console.log("test: " + Apps.ProcessName[uniqueId]);
}

Output:

* test: string
* test: _es6-shim iterator_
* test: function
* test: function iterator() { return this; }

I'm not sure if this is wrong or right.

ljharb commented 3 years ago

This is "correct" in the sense that it's an enumerable string property on the prototype.

We could certainly make it non-enumerable in implementations that support it, and probably should. I'm not sure if WSH does or not, though.

ljharb commented 3 years ago

It looks like we're already creating it as non-enumerable when supported, so this seems like something that's unavoidable in WSH (the implication is that it does not support Object.defineProperty for non-enumerables).

Happy to reopen if that's not the case.