[heycam/webidl] Creating a sequence from an iterable: IteratorClose not called (#895)

In [Creating a sequence from an iterable](https://heycam.github.io/webidl/#create-sequence-from-iterable), step 3.4. is `Initialize Si to the result of converting nextItem to an IDL value of type T.` This step can throw. That isn’t addressed with either `?` (`ReturnIfAbrupt` shorthand) or express handling. I’m not sure if that omission an error itself or if Web IDL allows for implicit abrupt-completion-bubbling.

If conversion throws, I’d expect [IteratorClose](https://tc39.es/ecma262/#sec-iteratorclose) to get called. The absence of iterator closing in the conversion algorithm can be observed when, for example, `finally` blocks don’t get evaluated:

```js
document.createElement('canvas').getContext('2d').setLineDash(function * () {
  try {
    yield Symbol(); // will fail to coerce to unrestricted double, throwing a TypeError
  } finally {
    console.log('iterator closed'); // return() isn’t called; this statement isn’t evaluated
  }
}());
```

When evaluated in Chrome or Firefox, the iterator is not closed. Safari however does perform iterator closing if conversion fails — the finally block does get evaluated. Although that’s a departure from the Web IDL spec currently, I think that should be the specified behavior.

The [Array.from](https://tc39.es/ecma262/#sec-array.from) builtin may be instructive because in the `usingIterator` path, if you ignore the bits that are specific to assembling an ES array, it’s pretty much the same premise as create-a-sequence-from-an-iterable (where `mapFn` is the Web IDL “convert” step which might throw).


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/heycam/webidl/issues/895

Received on Wednesday, 17 June 2020 05:42:35 UTC