Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XS fails to cache next for array-destructuring #1223

Closed
gibson042 opened this issue Oct 2, 2023 · 3 comments
Closed

XS fails to cache next for array-destructuring #1223

gibson042 opened this issue Oct 2, 2023 · 3 comments
Labels
confirmed issue reported has been reproduced

Comments

@gibson042
Copy link

Environment: XS 14.2.0 32 4

Description
Array-destructuring does not cache an iterator's next method as required by the ECMAScript specification.

Steps to Reproduce

Object.defineProperty(Array.prototype, Symbol.iterator, {
  get() {
    print("get Symbol.iterator", this);
    return function makeIterator() {
      print("@@iterator", this, ...arguments);
      let i = 0;
      const src = this;
      return {
        [Symbol.iterator]: () => iterator,
        get next() {
          print("get", "next");
          return () => {
            if (i >= src.length) return { done: true, value: undefined };
            const value = src[i];
            print("yield", i, value);
            i += 1;
            return { done: false, value };
          };
        },
      };
    };
  },
});
const [x, y] = ["a", "b", "c"];

Actual behavior

get Symbol.iterator a,b,c
@@iterator a,b,c
get next
yield 0 a
get next
yield 1 b

Expected behavior

get Symbol.iterator a,b,c
@@iterator a,b,c
get next
yield 0 a
yield 1 b

DestructuringAssignmentEvaluation on an |ArrayAssignmentPattern| with argument value (the iterable responsible for providing values) is specified to always start with GetIterator(value, SYNC), which gets the Symbol.iterator method of value and uses GetIteratorFromMethod to invoke it and return a corresponding Iterator Record capturing the resulting iterator and its next method for use by IteratorDestructuringAssignmentEvaluation. But XS incorrectly gets the next method before each step (and fails to get it at all for const [] = …).

@bakkot
Copy link

bakkot commented Oct 3, 2023

Note that the current behavior (at least for this test) was correct prior to tc39/ecma262#1021.

@phoddie
Copy link
Collaborator

phoddie commented Oct 3, 2023

Thanks for the test case. It is a little odd that this isn't covered by test262, but that's a different discussion.

We have a fix for this that will be part of Modable SDK 4.2.1, likely later this week.

@phoddie
Copy link
Collaborator

phoddie commented Oct 10, 2023

Closing, as the fix for this is live.

@phoddie phoddie closed this as completed Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed issue reported has been reproduced
Projects
None yet
Development

No branches or pull requests

3 participants