Andy Wingo (2013-04-30T11:30:45.000Z)
Hi Kevin,

On Tue 30 Apr 2013 11:05, Kevin Gadd <kevin.gadd at gmail.com> writes:

> I would definitely expect a given finally block to run if i use for-of
> or similar on the generator. This is the intent, I hope?

Certainly they run in this situation:

  function *g1() { try { yield 1; } finally { qux(); } }
  for (x of g1())
    print (x)

Or in this one:

  function *g2() { try { yield 1; return; } finally { qux(); } }
  for (x of g2())
    print (x)

But the question is what happens here:

  function *g3() { try { yield 1; } finally { qux(); } }
  for (x of g3())
    break;

Or here:

  function *g4() { try { yield 1; } finally { qux(); } }
  for (x of g4())
    throw "foo";

Or here:

  function *g5() { try { yield 1; } finally { qux(); } }
  for (x of g5())
    call_function_that_throws_an_exception();

For me, it is acceptable in the last three cases to never invoke those
finally blocks.  Otherwise, for-of would need to be implicitly
surrounded by a try/finally to manually "close" the generator.  It
seems to me that it would have pretty negative perf implications; for
example Crankshaft doesn't currently run on functions with try/finally.

Regards,

Andy
github at esdiscuss.org (2013-07-12T02:26:56.470Z)
Hi Kevin,

On Tue 30 Apr 2013 11:05, Kevin Gadd <kevin.gadd at gmail.com> writes:

> I would definitely expect a given finally block to run if i use for-of
> or similar on the generator. This is the intent, I hope?

Certainly they run in this situation:

```js
function *g1() { try { yield 1; } finally { qux(); } }
for (x of g1())
  print (x)
```

Or in this one:

```js
function *g2() { try { yield 1; return; } finally { qux(); } }
for (x of g2())
  print (x)
```

But the question is what happens here:

```js
function *g3() { try { yield 1; } finally { qux(); } }
for (x of g3())
  break;
```

Or here:

```js
function *g4() { try { yield 1; } finally { qux(); } }
for (x of g4())
  throw "foo";
```

Or here:

```
function *g5() { try { yield 1; } finally { qux(); } }
for (x of g5())
  call_function_that_throws_an_exception();
```

For me, it is acceptable in the last three cases to never invoke those
`finally` blocks.  Otherwise, `for`-`of` would need to be implicitly
surrounded by a `try`/`finally` to manually "close" the generator.  It
seems to me that it would have pretty negative perf implications; for
example Crankshaft doesn't currently run on functions with `try`/`finally`.