Skip to content

__values causes an infinite loop on Sets when Symbol.iterator isn't defined #59

Closed

Description

Environment: https://github.com/convoyinc/apollo-cache-hermes/tree/8088c19

Specifics:

Helpful reproduction repo built by @alexanderson1993 over in convoyinc/apollo-cache-hermes#382

When run on react-native android (and presumably older versions of Chrome), the following code infinite loops on tslib.__values (it emits undefined forever)

TypeScript source:

export class QueryInfo {
  // …
  public readonly variables: Set<string>;
  // …
  private _assertAllVariablesDeclared(messages: string[], declaredVariables: Set<string>) {
    for (const name of this.variables) {
      if (!declaredVariables.has(name)) {
        messages.push(`Variable $${name} is used, but not declared`);
      }
    }
  }
  // …
}

Emitted source:

// …
QueryInfo.prototype._assertAllVariablesDeclared = function (messages, declaredVariables) {
    try {
        for (var _a = tslib_1.__values(this.variables), _b = _a.next(); !_b.done; _b = _a.next()) {
            var name_1 = _b.value;
            if (!declaredVariables.has(name_1)) {
                messages.push("Variable $" + name_1 + " is used, but not declared");
            }
        }
    }
    catch (e_1_1) { e_1 = { error: e_1_1 }; }
    finally {
        try {
            if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
        }
        finally { if (e_1) throw e_1.error; }
    }
    var e_1, _c;
};

// …

Observed: for (const name of this.variables) { loops forever, assigning undefined to name on each iteration

Activity

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

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions