Negatives make for unsatsifying answers, but unfortunately, I don't believe there's any direct replacement. Although the ownKeys trap will be triggered by a for-in loop (because its initialization uses the abstract EnumerateObjectProperties operation, which has to get the keys for an object via [[OwnPropertyKeys]]), ownKeys will also be triggered other times the keys of an object are required, not just when being used in a for-in loop.
Negatives make for unsatsifying answers, but unfortunately, I don't believe there's any direct replacement. Although the
ownKeys
trap will be triggered by afor-in
loop (because its initialization uses the abstractEnumerateObjectProperties
operation, which has to get the keys for an object via[[OwnPropertyKeys]]
),ownKeys
will also be triggered other times the keys of an object are required, not just when being used in afor-in
loop.