tc39 / proposal-array-from-async

Draft specification for a proposed Array.fromAsync method in JavaScript.
http://tc39.es/proposal-array-from-async/
BSD 3-Clause "New" or "Revised" License
177 stars 13 forks source link

Wrap bare return values with Completion Records in abstract closure #32

Closed js-choi closed 2 years ago

js-choi commented 2 years ago

Resolves #31, at least temporarily. (Also affects #14.)

Eventually we might want to make a change to match whatever approach proposal-iterator-helpers does; see tc39/proposal-iterator-helpers#218. But that should be able to be a mere editorial change.

ljharb commented 2 years ago

I'm confused why this is necessary - what else would a "return" statement do in an abstract closure?

bakkot commented 2 years ago

It returns a value to the caller. The caller, in this case, is step 3.b.ii of AsyncBlockStart. You can look at the following steps to see that a.) the caller expects the result to be a Completion Record, not a bare value and b.) if the caller got a normal completion, it would not do the right thing.

"Return" in an abstract closure is mostly unrelated to returning from an ES function, which is handled by a different mechanism.