1 of 23

for-in

2 of 23

github.com/bakkot/for-in-exploration

3 of 23

Recap

  • Reflect.ownKeys is ordered
  • for (a in b) {...} is not

4 of 23

5 of 23

6 of 23

Historically there was wild divergence.

7 of 23

There still is for Proxies and

in edge cases.

8 of 23

But there's a broad space

with (necessary) agreement.

9 of 23

Problems with current spec

  • Interpretation for proxies
  • Failure to capture constraints

10 of 23

Goals

  • Nail down behavior for proxies
  • Maybe also common case
  • Clarify spec text in general

11 of 23

Non-goals

  • Anything which would require anyone to make changes for non-proxy cases.

12 of 23

So.

13 of 23

Proxies

14 of 23

Every engine does something different for proxies.

15 of 23

Uncaptured constraints

  • Horizontal order
  • Vertical order
  • New keys are not hit
  • Etc

16 of 23

The common case

(way too much text)

17 of 23

The common case

  • No proxies or host objects
  • Fixed proto chain
  • No new props up the chain
  • Fixed enumerable attributes
  • Nothing removed then added back
  • Non-enumerable props don't shadow
  • No shadowing props are deleted
  • No proto props are deleted

18 of 23

The common case

See associated repo.

19 of 23

Every engine agrees in

the common case.

20 of 23

21 of 23

Make the reference

implementation normative

for proxies.

Proposal 1:

22 of 23

Make the reference

implementation normative

for the common case.

Proposal 2:

23 of 23