ljharb / es-abstract

ECMAScript spec abstract operations.
MIT License
114 stars 30 forks source link

Feature request: ES2018 `GetIterator` and `CreateAsyncFromSyncIterator` #66

Open ExE-Boss opened 5 years ago

ExE-Boss commented 5 years ago

I’m currently writing a polyfill for the Iterator Helpers proposal, and I need these two methods.

ljharb commented 5 years ago

GetIterator has been available since v1.11.0, afaik.

CreateAsyncFromSyncIterator is tricky; i don't currently have the intrinsic for AsyncFromSyncIteratorPrototype, so I'd need to add that as well; I'm also not sure that it's *possible to implement that in JS.

ExE-Boss commented 5 years ago

ES2018 added the optional hint parameter to the GetIterator abstract operation, in a backwards incompatible manner.

ljharb commented 5 years ago

ah yes. I’d have to throw on an async hint, though, until the other method you request was available.

ExE-Boss commented 5 years ago

Actually, GetIterator(obj, 'async') can be allowed return an async iterator if obj has a Symbol.asyncIterator property, and only throw when CreateAsyncFromSyncIterator is needed.

Also, there’s no way to access %AsyncFromSyncIteratorPrototype% from JS, and even if there were, you still couldn’t set its [[SyncIteratorRecord]] internal slot.

ljharb commented 5 years ago

right, so when would it be needed?

ExE-Boss commented 5 years ago

CreateAsyncFromSyncIterator is needed when obj doesn’t have a [Symbol.asyncIterator]() method.