Skip to content

XS: For-in prints deleted keys #82

Description

@bakkot

(Sorry if this is the wrong repo; I'm not sure where to file bugs in the JavaScript engine.)

Consider the following program:

if (typeof console === 'undefined') console = { log: print };

let a = {
  x: 0,
  y: 1,
};

for (let key in a) {
  console.log(key);
  delete a.y;
  if (key === 'y') {
    console.log('reached');
  }
}

This prints x, y, reached. It should only print x. It should not reach the step with y, since y has been deleted before it gets to that iteration of the loop. The spec is pretty loose here, but does not allow this behavior: in #sec-enumerate-object-properties, it says "A property that is deleted before it is processed by the iterator's next method is ignored." No other engine has this behavior, though see related spidermonkey bug - spidermonkey exhibits this behavior when iterating over proxy objects, even those which are totally transparent.

See also (and please comment on) this open spec bug about more precisely specifying the behavior of for-in, which prompted the investigation which lead me to discovering this: tc39/ecma262#1281

PS: @patrick-soquet, thanks for adding moddable support to eshost! It makes it much, much more likely I'll find and file bugs like this.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions