-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Normative: Remove [[Enumerate]] and associated reflective capabilities
Summary of changes: * 6.1.7.2 Removed [[Enumerate]] from the table and list of invariants * 9.5 Proxy Object Internal Methods and Interal Slots, [[Enumerate]] table entry removed. * 9.4.6.1.1 Module Namespace Object [[Enumerate]] moved to 26.3.2 module namespace object [ @@iterator ] * 9.5.11 Proxy [[Enumerate]] deleted * Moved ordinary [[Enumerate]] section to end of 13.7.5 for-in, renamed to EnumerateObjectProperties. * Add an assert to step 1 to signal callers we expect they'll only pass objects * Updated informative definition of EnumerateObjectProperties * 13.7.5.12 for-in head evaluation calls EnumerateObjectProperties(_obj_) instead of _obj_.[[Enumerate]] * EnumerableOwnNames: the _names_ are always ordered the same as EnumerateObjectProperties (since we don't have to worry about this not being enforceable with proxies anymore) * 26.1.5 Reflect.enumerate deleted Fixes #367.
- Loading branch information
Showing
1 changed file
with
39 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d96e60a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bterlson
Is there a way to get something similar to Reflect.enumerate?
Specifically a way to key own and inherited enumerable keys of an object.
Lodash uses the Reflect.enumerate shim as a _.keysIn compat route for folks wanting less buggy for-in style iteration in older enviros.
d96e60a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not the best solution, and it requires Symbol.iterator or Array.prototype.keys:
d96e60a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@leobalter
That's what I'm going for. I'm looking for something like:
I was able to get their by way of
Reflect.enumerate
.d96e60a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the enumerate example on ES2015 seems the most precise approach.
looks like an opportunity to bring in
Object.enumerate
(or even thekeysIn
) to esdiscuss (as Reflect wouldn't be appropriated without [[Enumerate]]).Seems like it's already introduced there and it's a good idea: https://esdiscuss.org/topic/property-ordering-of-enumerate-getownpropertynames
d96e60a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jdalton I asked this in the meeting, and was told
function* enumerate(obj) { for (const key in obj) { yield [key, obj[key]]; } }
would be sufficient.d96e60a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not shimmable (right?). So they took something away without a proper replacement. 😧
d96e60a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, it's not shimmable without materializing an array, and then returning an iterator off that array. Something like
function enumerate(obj) { var entries = []; for (var key in obj) { entries.push([key, obj[key]]); } return entries.values(); }
would work tho.d96e60a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ljharb
Work how? What built-in is that anchored to? Which
es-shim
would it fall under?I'm aware of how to create a for-in loop y'all. I want the compat path back that you nixed. That's what I want. I want to be able to point to an API that can be shimmed for folks that want better object iteration in older environments so that I can use it to power things like
_.keysIn
.