Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetIteratorFlattenable should check that iterator is an Object. #247

Closed
woess opened this issue Nov 3, 2022 · 4 comments · Fixed by #253
Closed

GetIteratorFlattenable should check that iterator is an Object. #247

woess opened this issue Nov 3, 2022 · 4 comments · Fixed by #253

Comments

@woess
Copy link

woess commented Nov 3, 2022

GetIteratorFlattenable apparently is missing a check that the iterator returned by Call(method, obj) (i.e. @@iterator() or @@asyncIterator()) is an Object, as required by Iterator Record:

1. If _obj_ is not an Object, throw a *TypeError* exception.
1. Let _alreadyAsync_ be *false*.
1. Let _method_ be *undefined*.
1. If _hint_ is ~async~, then
  1. Set _method_ to ? Get(_obj_, @@asyncIterator).
  1. Set _alreadyAsync_ to *true*.
1. If IsCallable(_method_) is *false*, then
  1. Set _method_ to ? Get(_obj_, @@iterator).
  1. Set _alreadyAsync_ to *false*.
1. If IsCallable(_method_) is *false*, then
  1. Let _iterator_ be _obj_.
  1. Set _alreadyAsync_ to *true*.
1. Else,
  1. Let _iterator_ be ? Call(_method_, _obj_).
1. Let _nextMethod_ be ? GetV(_iterator_, *"next"*).
1. If IsCallable(_nextMethod_) is *false*, throw a *TypeError* exception.
1. Let _iteratorRecord_ be the Iterator Record { [[Iterator]]: _iterator_, [[NextMethod]]: _nextMethod_, [[Done]]: *false* }.
1. If _hint_ is ~async~ and _alreadyAsync_ is *false*, then
  1. Return CreateAsyncFromSyncIterator(_iteratorRecord_).
1. Return _iteratorRecord_.
@ljharb
Copy link
Member

ljharb commented Nov 3, 2022

Wouldn’t GetV check that?

@woess
Copy link
Author

woess commented Nov 3, 2022

@ljharb no, GetV performs a ToObject conversion, so if the returned iterator is an object-coercible primitive value and there's a callable next method on its corresponding prototype, GetIteratorFlattenable will not throw.

FWIW, GetIterator has a check for this case: "4. If iterator is not an Object, throw a TypeError exception."

@ljharb
Copy link
Member

ljharb commented Nov 3, 2022

aha, thanks, good catch

@michaelficarra
Copy link
Member

@woess Thank you for the issue. I've opened #253 to resolve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants