Skip to content

re-use (done: false) IteratorResult objects yielded by underlying iterator #17

@michaelficarra

Description

@michaelficarra

Taken from the tests PR: https://github.com/tc39/test262/pull/4326/files#diff-667834d670268d2d741d9c1331df51d617cb4281fd9a46f785af4f43cc1ff256R49.

let oldIterResult = {
  done: false,
  value: 123,
};

let testIterator = {
  next() {
    return oldIterResult;
  }
};

let iterable = {
  [Symbol.iterator]() {
    return testIterator;
  }
};

let iterator = Iterator.concat(iterable);

let iterResult = iterator.next();

assert.sameValue(iterResult.done, false);
assert.sameValue(iterResult.value, 123);

assert.notSameValue(iterResult, oldIterResult);

This seems really wasteful. Would there be any harm in re-using these IteratorResult objects from the underlying iterator instead of constructing them anew?

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